Running both Chrome and IE 11 Protractor tests - selenium-webdriver

Running Protractor E2E tests against both Chrome and IE is difficult.
I can run them separately, however I need to start/stop the respective Chrome/IE webdriver server before running each tests.
In my conf.js file, I export the config options like this :
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: [
'spec/my-spec.js',
],
directConnect: false, // false when targeting IE, and selen addr is used
multiCapabilities: [
{
browserName: 'chrome'
}
,
{
browserName: 'internet explorer',
'version': '11'
}
]
}
For the standard Chrome tests, I can kick off the Webdriver server:
> webdriver-manager start
But for IE, I discovered a way to run Webdriver IE as follows (yeah, pretty ugly):
java -Dwebdriver.ie.driver=C:\Projects\GSDashboard-E2ETests\node_modules\protractor\node_modules\webdriver-manager\selenium\IEDriverServer_x64_2.53.1.exe -jar C:\Projects\GSDashboard-E2ETests\node_modules\protractor\node_modules\webdriver-manager\selenium\selenium-server-standalone-2.53.1.jar
Then I just launch the Protractor tests:
protractor protractor.conf.js
I'm searching around for a cleaner and smoother way of running both IE/Chrome e2e tests in one shot.
Is there a solution to this ?
Any advice/guidance is appreciated....
****** UPDATE ******
As per answer below, trying to use seleniumArgs as follows (where I can specify the jar file OR the IEDriverServer_x64_2.53.1.exe file :
exports.config = {
//seleniumAddress: 'http://localhost:4444/wd/hub', // comment out
seleniumArgs: ['-Dwebdriver.ie.driver=C:\Projects\Dashb-E2ETests\node_modules\protractor\node_modules\webdriver-manager\selenium\IEDriverServer_x64_2.53.1.exe'],
allScriptsTimeout: 50000,
specs: [
'spec/MY-spec.js',
],
directConnect: false, // false when targeting IE, and selen addr is used
multiCapabilities: [
//{
// browserName: 'chrome',
,
{
browserName: 'internet explorer',
'version': '11'
}
]
}
BUT running the test throws this error in a windows cmd prompt:
E/launcher - The path to the driver executable must be set by the web driver.ie.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorer‌​Driver.
So, I still haven't figured out how to run both IE and Chrome tests (sequentially).
regards,
Bob

I had a similar problem and the solution was running this:
webdriver-manager update --ie
After that, both IE11 and Chrome instances run simultaneously with:
multiCapabilities: [
{
browserName: 'chrome'
}
,
{
browserName: 'internet explorer',
'version': '11'
}
]

include seleniumArgs: ['-Dwebdriver.ie.driver=pathtoIEdriver/IEDriverServer.exe'] property in the conf.js and remove seleniumAddress: 'http://localhost:4444/wd/hub'.If no seleniumAddress is mentioned ,then protractor will automatically start selenium server. So following will be your conf.js for running your protractor test against chrome and ie.
exports.config = {
seleniumArgs: ['-Dwebdriver.ie.driver=node_modules/protractor/selenium/IEDriverServer.exe'],
specs: [
'spec/my-spec.js',
],
directConnect: false, // false when targeting IE, and selen addr is used
multiCapabilities: [
{
browserName: 'chrome'
}
,
{
browserName: 'internet explorer',
'version': '11'
}
]
}

Related

Using headless chrome displays empty part of the page

When using chromedriver in a protractor script, to test an angular page, I obtain different results using "Headless" or "Normal" browser.
Actually, if I use a "repeater" locator, to display the items in the "empty" list, it returns that there are 5 items, but the "headless" chrome driver fails to render them. Look at the screenshots.
I'm using ChromeDriver 2.45, which supports Chrome Version 70 to 72, I have version 71.
My OS is Windows 10.
Protractor version 5.1.1
Angularjs version 1.5
Here's the configuration file:
exports.config = {
directConnect: true,
rootElement: 'html',
chromeDriver: 'C:\\srv\\build\\applications\\chromedriver\\chromedriver_win32\\chromedriver.exe',
getPageTimeout: 60000,
allScriptsTimeout: 60000,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome',
chromeOptions:{
args:["--headless"]
}
},
specs: [ 'features/*.feature' ],
baseUrl: '',
cucumberOpts: {
tags: '',
require: [ 'steps/*.spec.js' ],
monochrome: true,
strict: true,
plugin: "json"
},
};
Seems to problem is in the window size. By default, headless mode is not a fullscreen, so some elements are automatically moved and hidden (as when you try manually to resize the window)
Just add to your conf:
driver.manage().window().maximize();
Can you update args to
capabilities: {
...,
chromeOptions: {
args: ["--headless", "--disable-gpu", "--window-size=800x600"]
}
}
For the exact configuration mentioned i am able to automate headless with no issues.
Reference https://github.com/angular/protractor/blob/master/docs/browser-setup.md#using-headless-chrome

How to loop in Protractor config file?

I am new to JS and Protractor for testing functionalities. I need to include some conditions or loops inside 'Configuration' file of protractor.
Such as, if I need to check my specs running on 'Windows / Mac' platform and a variable provides these details.
I am expecting something like :
exports.config = {
seleniumAddress : 'http://localhost:4444/wd/hub',
getPageTimeout : 30000,
allScriptsTimeout : 30000,
specs : [ ],
framework : 'jasmine2',
***don't know the syntax, am expecting below line and condition need to work for protractor***
***var platform = 'Windows',
if(platform ==='Windows'){***
multiCapabilities: [{
'browserName': 'chrome',
'specs': ['spec1.js']
},
***else {***
'browserName': 'chrome',
'specs': ['spec2.js']
}],
};
Is it possible to validate in Configuration file?
You need to use the getMultiCapabilities function:
getMultiCapabilities: function() {
// TODO: check platform and return list of capability objects
},

Phantomjs fails when Protractor is run with selenium hub

I have a protractor config file as follows and i use phantomjs to run the tests. It works when i use seleniumServerJar but fails when i use seleniumAddress (pointing to a hub) with a 'The driver executable does not exist' message! Is there any specific config to run phantomjs with selenium-hub?
exports.config = {
//Fails when i use this
//seleniumAddress:"http://selenium-hub.com:4659/wd/hub",
//Works when i use this selenium-standalone jar
seleniumServerJar: '../../../node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar',
framework: 'cucumber',
specs: [
'features/*.feature'
],
capabilities: {
"browserName": "phantomjs",
"phantomjs.binary.path": require("phantomjs").path,
"phantomjs.ghostdriver.cli.args": ["--loglevel=DEBUG"]
},
baseUrl: '',
rootElement: 'body',
resultJsonOutputFile: 'src/test/report.json',
cucumberOpts: {
require: 'features/steps/*_steps.js',
}
};

Why is Protractor complaining about target browser config when I'm not targeting a browser?

I'm writing an app using Ionic/Angular and testing it with Protractor. I'd like to test it using Sauselabs Appium so I can test the app running natively on the various target platforms. I'm launching Protractor with:
SAUCE_USERNAME=$(SAUCE_USERNAME) SAUCE_ACCESS_KEY=$(SAUCE_ACCESS_KEY) ./node_modules/.bin/protractor protractorConfig.js
But I get this error message:
[launcher] Running 1 instances of WebDriver
[launcher] Error: TypeError: Target browser must be a string, but is <object>; did you forget to call forBrowser()?
My protractorConfig.js looks like:
/* global exports */
/* global process */
exports.config = {
sauceUser: process.env.SAUCE_USERNAME,
sauceKey: process.env.SAUCE_ACCESS_KEY,
capabilities: {
appiumVersion: "1.0",
app: "sauce-storage:app.zip",
platformName: "iOS",
platformVersion: "7.1",
deviceName: "iPhone Simulator"
},
allScriptsTimeout: 30000,
specs: [
"spec/feature/*.js"
]
};
I should have read the docs more carefully. Appium's documentation for Desired Capabilities says that 'browserName' should be an empty string if you're not targeting a browser.
Updating my protractorConfig accordingly fixes the issue.
/* global exports */
/* global process */
exports.config = {
sauceUser: process.env.SAUCE_USERNAME,
sauceKey: process.env.SAUCE_ACCESS_KEY,
capabilities: {
appiumVersion: "1.0",
app: "sauce-storage:app.zip",
platformName: "iOS",
platformVersion: "7.1",
deviceName: "iPhone Simulator",
browserName: ""
},
allScriptsTimeout: 30000,
specs: [
"spec/feature/*.js"
]
};
Try adding of 'browserName': 'chrome' into your capabilities.

Selenium stand-alone-serer and PhantomJS

For the moment, I have a basic angular app, generated by "generator-gulp-angular". In this project, I have 2 tests: 1 karma-test and 1 e2e-test (using protractor). The karma-test wil run without a problem, but with the other, I encounter some issues.
I'm trying to run selenium driver with phantomJS to execute the test, and in Chrome it works, in Firefox not (because of the upgrade), but trying to run the test on phantomJS wil fail. I have already downgraded my selenium stand-alone-server but now, selenium will give the error "driver info: driver.session: unknown". I'm using selenium 2.38 and phantom 1.9.x.
Can somebody tell me what to do? Should I adapt something in the conf-files of phantomJS node-module? Should I downgrade my phantomJS? ...
This is my protractor.conf.js:
exports.config = {
//directConnect: true,
seleniumAddress: 'http://localhost:4444/wd/hub',
baseUrl: 'http://localhost:9292',
rootElement: 'body',
// Capabilities to be passed to the webdriver instance.
capabilities: {
browserName: 'phantomjs',
'phantomjs.binary.path': 'C:/Users/--------/Documents/3de_Academiejaar/Stage/GitHub_Repos/proj_Jesper2/node_modules/phantomjs/bin/phantomjs',
},
specs: [paths.e2e + '/**/*.js'],
framework: 'jasmine',
jasmineNodeOpts: {
onComplete: function () {
},
isVerbose: true,
showColors: true,
includeStackTrace: true,
defaultTimeoutInterval: 30000
}
};

Resources