Set Internet Explorer options for protractor (--headless) - protractor

I would like to set headless option in my protractor configuration for internet explorer, but I cannot find anyting related to this. They only say how to do it in Chrome and Firefox: Adding chrome and Firefox specific options.
This is what I have so far:
multiCapabilities: [
{
'browserName': 'chrome',
chromeOptiaons: {
args: ["--headless"]
},
},
{
'browserName': 'firefox',
'moz:firefoxOptions': {
args: ["--headless"]
}
},
{
'browserName': 'internet explorer',
internetExplorerOptions: { <---------------------------
args: ["--headless"] <---------------------------
}
}
],
internetExplorerOptions is not working
So how do I add the 'Options / args' option to IE?

IE does not have support for a headless mode. But you can try to use triflejs.
I did not try this solution by myself but seems like it's the only option since IE is basically obsolete browser and it does not receive any updates.

First of all, you need IEDriverServer.
I will try to make this as simple as possible. The proper way to get and install this is, by using protractor’s built-in functionality.
Install Webdriver-manager and gulp, globally.
npm installwebdriver-manager gulp -g
Browse to node_modules/protractor/bin and run
npm webdriver-manager --standalone update
npm webdriver-manager --ie update
Then, you will need to manually start the webdriver server
For this, you will need to run
npm webdriver-manager --ie start
As simple as that.
After that, the 2nd step is to get the config file right.
The spicy and “different” stuff is: Capabilities, direct connect, and
LocalSeleniumStandaloneOpts
Necessary and Important examples for config file, in order to run the spec test suite:
capabilities: {
'browserName': 'internet explorer',
'ignoreProtectedModeSettings': true,
'platform': 'ANY',
'version': '11',
args: ['--silent', '--no-sandbox', '--test-type=browser', '--lang=US', '--start-maximized'], //,'--headless', '--disable-gpu'
prefs: {
'download': {
'prompt_for_download': false,
'directory_upgrade': true,
'extensions_to_open': '',
'default_directory': process.cwd() + '/downloads/'
},
}
},
localSeleniumStandaloneOpts: {
jvmArgs: [
'-Dwebdriver.ie.driver=node_modules/protractor/node_modules/webdriver-manager/selenium/IEDriverServer3.14.0.exe'
]
},
directConnect: false,
framework: 'jasmine',
seleniumArgs: ['-
Dwebdriver.ie.driver=node_modules/protractor/node_modules/webdriver-
manager/selenium/IEDriverServer3.14.0.exe'],
seleniumAddress: 'http://localhost:4444/wd/hub'

Related

Running e2e test cases using proactor and getting session not created

I wrote e2e test cases using a protractor. It was working fine a few days before. But now while running the test cases.
I am getting:
session not created: This version of ChromeDriver only
supports Chrome version 81 (Driver info: chromedriver=81.0.4044.69
I have already installed Google Chrome version 81. Then also I am getting the same error. I tried re-installing the node_modules but not worked.
This the configuration of my protractor.conf.json file:
const { SpecReporter } = require('jasmine-spec-reporter');
const config = require('./protractor.conf').config;
const puppeteer = require('puppeteer');
/**
* #type { import("protractor").Config }
*/
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: [ "--headless", "--no-sandbox" ],
binary: puppeteer.executablePath()
},
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.json')
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
Because you specify binary: puppeteer.executablePath(), this means protractor will use the browser provided by npm package puppeteer, not the browser installed by yourself.
So the issue is the version of chrome browser provided by 'puppeteer' is not 81. To make it to version 81 or change the chromedriver version to compatible with the current 'puppeteer' chrome browser. Or remove this line binary: puppeteer.executablePath() to rely on the browser which have to pre-installed on test machine manualy.

Running multiCapabilities on browserstack using browserstack-local

I'm working on an angular project where we have end to end tests using protractor. We use gulp-protractor to run these tests. Every thing works fine on local. Now we want to increase the number of browsers and devices under tests, so I started to change protractor.conf.js to work with browserstack.
The web application under tests is running locally, so I use browserstack-local as well.
I have a configuration working well for one browser, which test website running on local (inspired from https://github.com/browserstack/protractor-browserstack/blob/master/conf/local.conf.js).
Now, I'm trying to adapt it to run on multi-browsers (following https://github.com/browserstack/protractor-browserstack/blob/master/conf/parallel.conf.js). I end up with that configuration:
exports.config = {
framework: 'jasmine2',
onPrepare: common.onPrepare,
// The address of a running selenium server.
seleniumAddress: 'http://hub-cloud.browserstack.com/wd/hub',
commonCapabilities: {
'browserstack.user': 'OUR_USER',
'browserstack.key': 'OUR_KEY',
name: 'Taylor Wimpey e2e tests',
'browserstack.debug': 'true',
'browserName': 'chrome',
'browserstack.local': true
},
multiCapabilities: [{
browserName: 'Chrome'
},{
browserName: 'Safari'
},{
browserName: 'Firefox'
},{
browserName: 'IE'
}],
baseUrl: 'http://localhost:3000',
// Spec patterns are relative to the current working directory when
// protractor is called.
specs: [paths.e2e + '/**/*.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
},
// Code to start browserstack local before start of test
beforeLaunch: function(){
console.log("Connecting local");
return new Promise(function(resolve, reject){
exports.bs_local_args = {
key: exports.config.commonCapabilities['browserstack.key'],
force: true
};
exports.bs_local = new browserstack.Local();
exports.bs_local.start(exports.bs_local_args, function(error) {
if (error) return reject(error);
console.log('Connected. Now testing...');
resolve();
});
});
},
// Code to stop browserstack local after end of test
onComplete: function(){
console.log('Stop browserstack local');
return new Promise(function(resolve){
exports.bs_local.stop(resolve);
});
}
};
// Code to support common capabilities
exports.config.multiCapabilities.forEach(function(caps){
for(var i in exports.config.commonCapabilities) {
caps[i] = caps[i] || exports.config.commonCapabilities[i];
}
});
Tests are launched and worked (my reports are generated for each browsers), but it never stop. Here the end of console logs:
...
[BS] Serving files from: .tmp/serve
[BS] Serving files from: src
Connecting local
Connected. Now testing...
[09:05:39] I/launcher - Running 4 instances of WebDriver
......F......FFF^C
so I have to kill them manually, which is not an option as at the end, tests will be running in a continuous integration server.
Does anyone knows how to get e2e tests working on multi-browsers using browserstack with the web application under test running on local?
UPDATE: browserstack support has added an example for multi-capabilities running on local on their github repo: https://github.com/browserstack/protractor-browserstack/blob/master/conf/parallel_local.conf.js
The only difference is to use afterLaunch instead of onComplete
Thanks

how can Parametrize protractor-config file for different browsers and test suites

I am running my Protractor Test from command npm run e2e
I want a way so that if I pass npm run e2e firefox then my test will get executed on Firefox browser.
Or if I run npm run e2e chrome then it should run on chrome
if I pass both npm run e2e firefox chrome then my test should run on both the browser in parallel.
Is it possible to parametrize protractor config file?
Similarly if I can pass test suite name via command and it should execute only tests under that particular test suite.
Here is my config file and this is what I want to achieve:
`//var HtmlReporter = require('protractor-html-screenshot-reporter');
exports.config = {
allScriptsTimeout: 30000,
//Add parameters for browser names
params:{
pass: {
browserName : 'chrome',
testSuitName : 'e2e/TestSuites/_BVT/*.js',
}
},
suites: {
//Define here List of Sanity Test Scenarios:
BVT : testSuitName,
},
// configure multiple browsers to run tests
multiCapabilities: [
shardTestFiles: true,
maxInstances: 2
{'browserName': browserName}
],
baseUrl: 'http://mytestUrl/',
framework: 'jasmine2',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
},
onPrepare: function() {
var jasmineReporters = require('jasmine-reporters');
browser.driver.manage().window().maximize();
return browser.getProcessedConfig().then(function(config) {
var browserName = config.capabilities.browserName;
var junitReporter = new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'tests/test-results',
filePrefix: browserName + '-xmloutput',
modifySuiteName: function(generatedSuiteName, suite) {
return browserName + '.' + generatedSuiteName;
}
});
jasmine.getEnv().addReporter(junitReporter);
});
},
resultJsonOutputFile: 'tests/test-results/output.json'
};`
Would appreciate any help on this.
Thanks in advance.
I know this post is a bit old now, but this solution may help people having a similar problem.
Use multiple config files, one for each browser type, setup a base config file, and require that into each of the other config files, and then create an npm script for each config file. No need for parameters and everything stacks nicely.
so the base config (called something like "protractor_base.js")would look something like:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
rootElement: '[ng-app]',
allScriptsTimeout: 60000,
framework: 'jasmine',
specs: ['example-spec.js']
};
And then your other configs (ie "protractor_chrome.conf.js") would look something like:
protractor = require('./protractor_base.js');
var config = protractor.config;
config.capabilities: {
'browserName': 'chrome'
};
exports.config = config;
You can then specify a multi browser config, just a chrome one, etc.
--capabilities.chromeOptions.args=headless --capabilities.chromeOptions.args=disable-gpu --capabilities.chromeOptions.args=window-size=1200,600
The above code should work for you.
I was looking for passing parameters from command line to protractor config file and found a way to do this:
npm run e2e -- --baseUrl=http://testurl:8080 --suite=suite_name_defined_in_config --capabilities.browserName=browser_Name
where my npm package.json :
"e2e": "protractor tests/protractor-conf.js",
and config file contains :
suites: {
BVT: 'e2e/TestSuites/_BVT/*.js',
Full: 'e2e/TestSuites/Full/**/*.js',
},
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:8080/',

Protractor - run multiple tests in parallel on different System

Is there any way to run multiple test suites in parallel on different machines.
I am able to do parallel execution in same machine with different browser.
Tried using seleniumAdress: ''/wd/hub
But its not working.
Finally Got the answer :-)
Step 1: Start selenium standalone using following command
java -jar selenium-server-standalone-2.42.2.jar -port 5041
here 5041 is a port number.
Step 2: add following line of code in your configuration file
multiCapabilities: [
{
browserName: 'safari',
shardTestFiles: true,
seleniumAddress: 'http://IP1:5041/wd/hub',
specs: '../xyz.js',
maxInstances: 1
},
{
browserName: 'safari',
shardTestFiles: true,
seleniumAddress: 'http://IP2:5041/wd/hub',
specs: '../pqr.js',
maxInstances: 1
}
],
Note: You need start selenium-standalone in both the system.
There may be a better way to do this but currently I am just executing these as concurrent Grunt tasks.
1) Add the grunt concurrent plugin
npm install grunt-concurrent --save-dev
2) Add a task for each browser under grunt.initConfig. We can add the browser as an arg to re-use our configuration file.
protractor: {
options: {
keepAlive: true,
singleRun: false,
configFile: "test/protractor.conf.js"
},
run_chrome: {
options: {
args: {
browser: "chrome"
}
}
},
run_firefox: {
options: {
args: {
browser: "firefox"
}
}
}
},
3) Register these as tasks;
grunt.registerTask('protractor-chrome', ['protractor:run_chrome']);
grunt.registerTask('protractor-firefox', ['protractor:run_firefox']);
4) Create your concurrent task under grunt.initConfig
concurrent: {
protractor_test: ['protractor-chrome', 'protractor-firefox']
},
5) Add the grunt task for concurrent
grunt.registerTask('protractor-e2e', ['concurrent:protractor_test']);
And executing that should give you concurrent protractor tests.
Hope this helps. :)

Running protractor tests on multiple browsers with browser stack

I am trying to run E2E tests on multiple browsers on browser stack, I took the reference from
E2E testing on multiple/parallel browsers in Protractor?
and
Internet Explorer Selenium protractor e2e tests
but the error I get every time I try to run the tests -
ERROR - Unable to start a WebDriver session.
C:\MrWhiteMVP\whitemvp-integrationtests_develop\node_modules\gulp-protractor\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:113
var template = new Error(this.message);
^
UnknownError: Authorization required
at new bot.Error (C:\MrWhiteMVP\whitemvp-integrationtests_develop\node_modules\gulp-protractor\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:113:18)
at Object.bot.response.checkResponse (C:\MrWhiteMVP\whitemvp-integrationtests_develop\node_modules\gulp-protractor\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\response.js:103:11)
But if I run the tests on 1 browser, then it works perfectly fine. this is how my conf file looks like
'use strict';
exports.config = {
seleniumAddress: 'http://hub.browserstack.com/wd/hub',
multicapabilities: [{
'browserstack.user': 'testuser',
'browserstack.key': 'testkey',
// Needed for testing localhost
// 'browserstack.local': 'true',
// Settings for the browser you want to test
'browserName': 'chrome',
'version': '36.0',
'os': 'OS X',
'os_version': 'Mavericks',
'resolution': '1024x768'
},
{
'browserstack.user': 'testuser',
'browserstack.key': 'testkey',
// Needed for testing localhost - 'browserstack.local': 'true',
// Settings for the browser
'browserName': 'firefox',
'os': 'windows'
}],
baseUrl: 'http://origin-develop.mvp.livebranches.com',
// The require statement must be down here, since jasmine-reporters
// needs jasmine to be in the global and protractor does not guarantee
// this until inside the onPrepare function.
onPrepare: function()
{
require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('xmloutput', true, true));
},
},
};
could anyone please tell me what am I doing wrong here, also we use gulp ti run specs but my problem is it is saying not even going beyond authentication.
I think that first of all, you have an extra comma on your config.
onPrepare: function()
{
require('jasmine-reporters');
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('xmloutput', true, true));
},
}, <-----
};