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
Related
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'
}
]
}
I have a scenario where I need to click on a link which will trigger .CSV file download to a default location(/tmp)and it is working fine on both chrome and firefox browsers but based on multiCapabilities configuration in conf.js, at times it work only on single browser(means one set of configuration helps in chrome working fine but not the firefox and the other set results in firefox to work but not the chrome).And I used the following stackoverflow post as the reference : Protractor e2e test case for downloading pdf file. And my attempt worked fine someway but then script hits only on chrome or firefox based on multiCapabilities configuration I used.
Please note that chrome will work with following config and in this I haven't added the firefox profile setup . So file download part in firefox wont work with the following configuration.
multiCapabilities: [
{
'browserName': 'chrome',
'platform': 'ANY',
'chromeOptions': {
args: ['--no-sandbox', '--test-type=browser'],
prefs: {
download: {
'prompt_for_download': false,
'directory_upgrade': true,
'default_directory': '/tmp'
}
}
}
},
{
'browserName': 'firefox',
}
],
Based on the above mentioned url(Protractor e2e test case for downloading pdf file) I added the function getFirefoxProfile() in my util file : common.js
var getFirefoxProfile = function() {
var deferred = q.defer();
var firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.download.folderList", 2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
firefoxProfile.setPreference("browser.download.dir", '/tmp');
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/comma-separated-values, text/csv, application/csv, application/excel, application/vnd.ms-excel, application/vnd.msexcel, text/anytext");
firefoxProfile.encoded(function(encodedProfile) {
var multiCapabilities = [{
browserName: 'firefox',
firefox_profile : encodedProfile
}];
deferred.resolve(multiCapabilities);
});
return deferred.promise;
}
exports.getFirefoxProfile = getFirefoxProfile;
And then I updated the conf.js as follows:
getMultiCapabilities: com.getFirefoxProfile,
multiCapabilities: [
{
'browserName': 'chrome',
'platform': 'ANY',
'chromeOptions': {
args: ['--no-sandbox', '--test-type=browser'],
prefs: {
download: {
'prompt_for_download': false,
'directory_upgrade': true,
'default_directory': '/tmp'
}
}
}
},
{
'browserName': 'firefox',
}
],
And getMultiCapabilities: com.getFirefoxProfile when used in conf.js will override both capabilities and multiCapabilities mentioned in the conf.js and when I run my script, it executes the script only on firefox and not in chrome.
Any idea on how to fix this? And my requirement is to login to chrome, perform the csv download, logout from chrome, then login to firefox and do the same.
Any help would be greatly appreciated..
For adding capabilities to multiple browser(chrome and firefox), we need to use multiCapabilities, and add capabilities of each browser(firefox and chrome) as follows.
Note : Here I configured multi capabilities with promises.
var q = require("q");
var FirefoxProfile = require("firefox-profile");
exports.config = {
directConnect: true,
onPrepare: function () {
browser.driver.getCapabilities().then(function(caps){
browser.browserName = caps.get('browserName');
});
},
maxSessions: 1,
getPageTimeout: 150000,
allScriptsTimeout: 150000,
params: require('../testdata/data.json'),
framework: 'jasmine2',
specs: ['../unit_test/*_spec.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 150000
},
//seleniumAddress: "http://127.0.0.1:4444/wd/hub",
getMultiCapabilities: function() {
var deferred = q.defer();
var multiCapabilities = [
{
'browserName': 'chrome',
'platform': 'ANY',
'chromeOptions': {
args: ['--no-sandbox', '--test-type=browser'],
prefs: {
download: {
'prompt_for_download': false,
'directory_upgrade': true,
'default_directory': '/tmp'
}
}
}
},
];
// Wait for a server to be ready or get capabilities asynchronously.
setTimeout(function() {
var firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("javascript.enabled", false);
firefoxProfile.setPreference("browser.download.folderList", 2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
firefoxProfile.setPreference("browser.download.dir", '/tmp');
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/comma-separated-values, text/csv, application/csv, application/excel, application/vnd.ms-excel, application/vnd.msexcel, text/anytext");
firefoxProfile.encoded(function (encodedProfile) {
var capabilities = {
"browserName": "firefox",
"firefox_profile": encodedProfile
};
multiCapabilities.push(capabilities);
deferred.resolve(multiCapabilities);
});
}, 1000);
return deferred.promise;
}
};
The default download location is set as /tmp for both browsers and for firefox to set capabilities, we need create a firefox profile and set preference.
Note :
"browser.download.folderList", 2 ==> set the download location as user defined. passing value 0 set download to desktop and 1 will download to default download location.
Also "browser.helperApps.neverAsk.saveToDisk", "text/comma-separated-values, text/csv, application/csv, application/excel, application/vnd.ms-excel, application/vnd.msexcel, text/anytext" ==> mime type used is csv mime type.
If your download file is pdf or some other, replace the csv mime type with your files mime type.
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
},
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
}
};
I'm writing end to end tests with Protractor for an angular website.
We have to support certain languages so I would like to init chrome using the --lang flag and start it with some other language. I searched the web and couldn't find any example to how it can be done.
My only lead was some article I saw and understood that I need to add to Protractor config file the "capabilities" section and there I can define the "args" property.
Then tried to tinker with it but no luck.
Any help will be most welcome.
Thanks,
Alon
How to set Browser language and/or Accept-Language header
exports.config = {
capabilities: {
browserName: 'chrome',
chromeOptions: {
// How to set browser language (menus & so on)
args: [ 'lang=fr-FR' ],
// How to set Accept-Language header
prefs: {
intl: { accept_languages: "fr-FR" },
},
},
},
};
More examples:
intl: { accept_languages: "es-AR" }
intl: { accept_languages: "de-DE,de" }
As it turns out - the answer was in the docs all along.
This is how you do it for chrome and i guess it similar for other browsers:
inside the protractor.conf.js (for Spanish):
capabilities: {
browserName: 'chrome',
version: '',
platform: 'ANY',
'chromeOptions': {
'args': ['lang=es-ES']}
}