Running multiCapabilities on browserstack using browserstack-local - protractor

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

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.

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

ScriptTimeoutError: Timed out - From: Task: Protractor.waitForAngular()

I am trying to run basic end to end tests written using protractor. I always get this error.
ScriptTimeoutError: Timed out
I checked this link https://github.com/angular/protractor/blob/master/docs/timeouts.md and increased the default timeout, but still I get the same error. I am not able to figure out from where this error pops out. The browser loads the base Url, later it will not perform any action as mentioned in the test. The test is very simple , open the browser and click on the menu and verify if the URL is matched.
Node Version: v7.5.0
Protractor Version: 5.1.2
Angular Version: 2.4.10
Browser(s): firefox
Operating System and Version ubuntu
typescript: 2.2.2
Config file
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['test/e2e/menu.js'],
capabilities: {
'browserName': 'firefox',
},
baseUrl: 'http://localhost:8100/#/',
//allScriptsTimeout: 360000,
jasmineNodeOpts: {
showColors: true,
// defaultTimeoutInterval: 360000
},
//useAllAngular2AppRoots:true,
//menu.js
describe('menu check', function () {
beforeEach(function () {
browser.get('http://localhost:8100/#/');
browser.waitForAngular();
// browser.driver.manage().timeouts().setScriptTimeout(60000);
});
it('Should route to the operationalView page from menu', function () {
element(by.css('[href="#/operationalView"]')).click();
expect(browser.getCurrentUrl()).toMatch('http://localhost:8100/#/operationalView');
});
it('Should route to the worldlview page from menu', function () {
element(by.css('[href="#/worldView"]')).click();
expect(browser.getCurrentUrl()).toMatch('http://localhost:8100/#/worldView');
});
});
I have had this issue once, which I resolved using
browser.ignoreSynchronization=true
before the beforeEach() method in your Protractor spec files. This makes Protractor not wait for Angular promises, such as those from $http or $timeout to resolve. You can try this in your script.
Edit : As of today, 08/16/19, this solution has been deprecated. Use waitForAngularEnabled to be false instead.

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

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));
},
}, <-----
};