Multiple browsers are opened, but only one browser running spec. other browsers are idle - protractor

I am trying to achieve parallel test execution in protractor. With the below mentioned code, I can open multiple browser. But only one browser running the spec, rest are just opened.Below is the snippet in config file
capabilities: {
'browserName': 'chrome',
'shardTestFiles': true,
'maxInstances': 3
},
specs: ['Spec1.js',
'Spec2.js',
'Spec3.js'
],
Any help can be appreciated.

Try adding count to the browser capabilities and maxSessions to the config file

Related

Why is SSO enabled when opening incognito mode from protractor?

I am trying to run my e2e tests using protractor and chrome. I use chrome in incognito mode, as I have to test different logins and I do not want SSO to be enabled. It works when I open an incognito window and I manually navigate to the URL, I am getting asked for a username and password. However, when I run the same scenario from protractor (so still using incognito and the same URL), I am getting logged in automatically.
Anybody has any suggestions? Does it have something to do with the chrome profile that is getting loaded?
I am new to this, so any suggestion is welcomed. Thank you!
My capabilities section of the config:
config.capabilities = {
browserName: 'chrome',
chromeOptions: {
args: ['disable-infobars',"--incognito","--log-level=3","--disable-gpu", "--window-size=1600,1200"]
},
//shardTestFiles: true,
//maxInstances: 3,
deviceProperties:{
browser: {
name: 'chrome',
version: 'latest'
},
platform: {
name: 'Windows',
version: '10'
}
}
}
Try the below one
browser.get('#/Login');
browser.executeScript('window.localStorage.clear();');
browser.executeScript('window.sessionStorage.clear();');
browser.driver.manage().deleteAllCookies();
Hoep it helps you

BrowserStack + Protractor + TravisCi and secure localhost server - configuration

Trying to have an e2e test to test my server and it's UI on TraviCI. I'm however not able to come up with the necessary configuration in order to run all the components and access seleniumServer on BrowserStack.
I am able to get my session started, but when launching a browser to https://localhost:3000/login I see that the browser shows a page not found. If I manually run the ./BrowserStackLocal tool and use browserstack to access my localhost, I can do so no problem.
Here are my files:
./travis.yaml
....
addons:
browserstack:
username: "<my username>"
access_key:
secure: "<secure key goes here>"
config.js
var browserstack = require('browserstack-local');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'specs/*.js'
],
'seleniumAddress': 'http://hub.browserstack.com/wd/hub',
'capabilities': {
'browserstack.user': '<my username>', //<<--- I also had a version without these properties for browserstack, and that didn't work either
'browserstack.key': '<my key>',
'browserName': 'chrome',
'acceptSslCerts': true,
'browserstack.debug': true,
'chromeOptions': {
'excludeSwitches': ["disable-popup-blocking"]
}
},
baseUrl: 'https://localhost:3000/',
rootElement: 'div[ng-app]',
framework: 'jasmine',
jasmineNodeOpts: {
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 = new browserstack.Local();
exports.bs_local.start({'key': exports.config.capabilities['browserstack.key'] }, function(error) {
if (error) return reject(error);
console.log('Connected. Now testing...');
resolve();
});
});
},
// Code to stop browserstack local after end of test
afterLaunch: function(){
return new Promise(function(resolve, reject){
exports.bs_local.stop(resolve);
});
}
};
Since you are testing your local/private environment on BrowserStack Automate you have to follow these steps:
1) Create the Local Testing connection via the BrowserStackLocal Binary.
2) Add the capability 'browserstack.local' : true in your config file.
I do not see the capability in the config.js file. Add the capability and things should work.
Your script looks similar to the one here.
I ran into this same problem myself recently. First, Ashwin is right that you need to add 'browserstack.local' : true to your protractor config file. Next you need to add "browserstack-local": "^1.3.0" to package.json under devDependencies. This is required for the Browserstack Local binary to be installed on your build server.
package.json:
...
"devDependencies": {
"browserstack-local": "^1.3.0"
}
Beyond that, it is not a problem with the config/setup. Rather, it is how you kick off the tests that affects the port your app is served on.
The reason it works when you run with the local binary is because your app is started on http://localhost:3000.
But when you build and run the app via Travis (by running ng e2e or similar), it actually starts your app on a different port (refer to this post for more on the angular ports). You can confirm this by looking at the console log, it should start with something like this:
> ng e2e
** NG Live Development Server is listening on localhost:49152, open your browser on http://localhost:49152 **
In the example above, it started on port 49152. So now if you have localhost:3000 hardcoded somewhere in your test spec, it won't find anything there. To fix this, in your test spec file, instead of browser.get('http://localhost:3000/login'), try browser.get(browser.baseUrl + '/login').
I realize this answer is probably too late for you, but hopefully it will be helpful to others.

Protractor - Change Browser Capabilities at RunTime

Is there a way to change the browser capabilities within beforeEach of the protractor suite. I need to set the Capabilities.name attribute before each spec execution.
To create separate instances of the desired capabilities, such as capabilities.name, you will want to try the multiCapabilities option available via Protractor. An example would look similar to what is below and reside in the conf.js file. This allows you to submit a unique name for each test session.
onPrepare: function(){
var caps = browser.getCapabilities()
},
multiCapabilities: [{
browserName: 'firefox',
version: '32',
platform: 'OS X 10.10',
name: "firefox-tests",
shardTestFiles: true,
maxInstances: 25
}, {
browserName: 'chrome',
version: '41',
platform: 'Windows 7',
name: "chrome-tests",
shardTestFiles: true,
maxInstances: 25
}],
A complete example of this can be seen here:
https://github.com/saucelabs-sample-test-frameworks/JS-CucumberJS-Protractor3.0/blob/master/conf.js
Here are the sauceLabs capabilities:
https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options
When you don't specify a Capabilities.name it looks like sauceLabs reports each test formatted as browserName:specFilename by default.
You can't change the capabilities in beforeEach() (Jasmine hook) or onPrepare() (Protractor conf.js) because the browser instance has already been created and webdriver session has been started with the capabilities already sent to the Selenium server.
Desired capabilities are set in the conf.js under Capabilities or Multicapabilities. You could set them at runtime by getting a variable before exporting in conf.js.
One common way to do this is to set the capability using an environment variable, for example:
Capabilities: {
browserName: process.env.SELENIUM_BROWSER
}
You can set variables to be used in capabilities in beforeLaunch() but this executes one time only, before any specs are read.
There is an excellent summary of the Protractor / Jasmine hooks here:
http://timothymartin.azurewebsites.net/protractor-before-and-afters/
I have not yet identified a way (without modifying Protractor source) to change capabilities dynamically on a per-spec or per-suite basis.

Protractor test's within Webstorm has no Browser Connection

While trying to start the default protractor tests, WebStorm or protractor can not launch the default pages inside the Browser.
The Error Message is a simple Exception:
FA Jasmine spec timed out. Resetting the WebDriver Control Flow.
The setup for protractor is as follows:
The protractor.conf.js is as follows
exports.config = {
allScriptsTimeout: 11000,
specs: [
'*.js'
],
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:8000/app/',
framework: 'jasmine2',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
and the tests are the default webstorm tests.
Configuration looks OK.
Please make sure you have started the local webserver on port 8000 (npm start) prior to running protractor - webserver needs to be serving up the application, so that Protractor can interact with it.
Also, make sure that web driver is installed (npm run update-webdriver)

Unable to run parallel tests in protractor

Unable to shard tests between browsers. Even though the config is set to shard them.
maxSessions: 2 ,
capabilities: {
browserName: 'chrome',
shardTestFiles: true,
maxInstances: 2,
},
It launches only one browser.
That won't launch two browsers. You have to use multicapabilities like shown in the section Testing again multiple browsers of this link
use:
multiCapabilities: [
{
browserName: 'chrome',
shardTestFiles: true,
maxInstances: 2,
}
If you want to run test in multiple browsers(chrome, IE, firefox) then implement multi capabilities.
If you want to run test in single browser, but multiple instances then you used right config, just make sure you are passing more than 1 script or you can create different suites. For example:
suites:
{
regressionTest: ['Scripts/*.js'],
sampleTest :['Scripts/xxxx.js']
}