Protractor - Change Browser Capabilities at RunTime - protractor

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.

Related

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

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

How to implement protractor grid system using JavaScript?

I created web-application using angular-5 for chatting and audio-call. need to implement automation using protractor.
Example test cases:
1.send message from machine-1 and receive message from machine-2.
2.make call from machine-1 and end call from the machine-2.
How to write protractor test-cases for these kind of scenarios.
As of now my current implementation is like.
multiCapabilities: [
{
seleniumAddress: 'http://machine1/wd/hub',
browserName: 'chrome',
directConnect: true,
sequential: true,
specs: [
'e2e/sender/login.js',
'e2e/sender/sendmsg.js',
'e2e/sender/makecall.js']
},
{
seleniumAddress: 'http://machine2/wd/hub',
browserName: 'chrome',
directConnect: true,
specs: [
'e2e/receiver/login.js',
'e2e/receiver/receivemessage.js',
'e2e/receiver/endcall.js']
}
]
Note: when i run the protractor, both machines will execute the test cases parallel.
How to implement proper test cases using protractor to test these kind of scenarios Please suggest.
Thanks in Advance..
You need to use driver.forkNewDriverInstance() https://www.protractortest.org/#/api?view=ProtractorBrowser.prototype.forkNewDriverInstance to create new browser instance for the same test.

Can't run protractor on internet explorer

I try to run protractor on IE11 and i keep get this failuer:
E/launcher - Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones.
I did set in explorer for all zones but still get this error.
my conf.js file is:
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
browserName: 'internet explorer'
},
// Spec patterns are relative to the configuration file location passed
// to protractor (in this example conf.js).
// They may include glob patterns.
specs: ['todo-spec.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
}
};
Help please.
Shaked
Go to Tools -> Internet Options -> Security Tab and set all zones to the same protected mode (can be enabled or disabled).
Try including these capabilities:
capabilities: {
...
"ignoreProtectedModeSettings": true
}

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']
}