Running e2e test cases using proactor and getting session not created - protractor

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.

Related

Set Internet Explorer options for protractor (--headless)

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'

Error while trying to execute protractor test script in Micro soft edge browser

Can any one help me the set up required to run the Protractor test script in Microsoft edge browser .
I have tried below steps
In the Protractor configuration file
{
'browserName' : 'MicrosoftEdge',
'SharedTestFiles' : false
}
seleniumArgs : ['-Dwebdriver.edge.driver=C:/Windows/SystemApps/Microsoft.MicrosoftEdge_8wekyb3d8bbwe/MicrosoftEdge.exe'],
run the selenium webdriver server with the below command
webdriver-manager start
It is displaying below error message
SessionNotCreatedError: Unable to create new service: EdgeDriverService
I tried below and worked fine for me:-
config.js
exports.config = {
seleniumAddress: 'http://localhost:4444',
capabilities: {
browserName: 'MicrosoftEdge',
elementScrollBehavior: 1,
nativeEvents: false
},
framework: 'jasmine',
baseUrl: 'http://angularjs.org',
specs: [
'spec.js'
],
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
}
Test Case/Spec file:-
describe('IE Test cases suite', function() {
it('first IE test case', function() {
browser.get(browser.baseUrl);
browser.getCurrentUrl().then(function(url){
console.log(url);
});
});
});
Also you can find some pre-requisites for webdriver manager refer
https://github.com/angular/protractor/issues/2377#issuecomment-290836086

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

Unable to produce HTML reports in protractor 3.3.0 with protractor-html-screenshot-reporter

i am new to protractor testing.
i was using protractor with protractor-html-screenshot-reporter and i used to generate html reports.
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: '/protractor-result', // a location to store screen shots.
docTitle: 'Protractor Demo Reporter',
docName: 'protractor-demo-tests-report.html'
but when i upgraded my protractor version to 3.3.0, i am unable to produce these reports anymore by using protractor-html-screenshot-reporter module.
i may be missing some or the other configurations or is it not compatible with the protractor 3.3.0 version
any response would be highly appreciated.
protractor-html-screenshot-reporter is not compatible with jasmine 2. Latest versions of protractor come with Jasmine2 by default.You can use -
protractor-jasmine2-html-reporter
for Json report you need to add resultJsonOutputFile in your config file.
resultJsonOutputFile: 'Path to your Report.json'
Code Snippet of conf.js
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
exports.config = {
directConnect: true, //seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://juliemr.github.io/protractor-demo/',
framework: 'jasmine2',
specs: ['*spec.js '],
allScriptsTimeout: 180000,
getPageTimeout: 180000,
jasmineNodeOpts: {
defaultTimeoutInterval: 180000
},
resultJsonOutputFile: './Report.json', // here you need to put the json option
onPrepare: function () {
var width = 1300;
var height = 1200;
browser.driver.manage().window().setSize(width, height);
browser.ignoreSynchronization = true;
jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
savePath: './test/reports/'
}));
}
};
NOTE: First install protractor-jasmine2-html-reporter package by running '_npm install protractor-jasmine2-html-reporter' from command prompt. Otherwise it will give error 'protractor-jasmine2-html-reporter' Not found

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/',