Unable to run parallel tests in protractor - 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']
}

Related

How to allow chrome browser notification in protractor e2e test for my Angular 9 web application

enter image description hereI need to allow the notification for the chrome browser to get incoming message notifications on my PC.
I have tried this code in the protractor.config file. It was still displaying the pop
capabilities: {
browserName: 'chrome',
'chromeOptions':{
'prefs' : {'profile.default_content_setting_values.geolocation': }
},
I have also tried using the following code in spec, it is not working
browser.switchTo().alert().accept()
for this code, I am getting an error as No such alert was found and the scripts fail.
Is there any provision to allow notification pop in the protractor for the chrome browser?
geolocation has nothing to do with it. You need to try these options https://chromium.googlesource.com/chromium/src/+/7e762c1f17514a29834506860961ba2f24e7e6e5/components/content_settings/core/common/pref_names.cc#36 Most likely these 3
"profile.default_content_setting_values.media_stream";
"profile.default_content_setting_values.media_stream_mic";
"profile.default_content_setting_values.media_stream_camera";
try these capabilities
{
browserName: 'chrome',
chromeOptions: {
prefs: {
'profile.default_content_setting_values.media_stream': 2,
"profile.default_content_setting_values.media_stream_mic": 2,
"profile.default_content_setting_values.media_stream_camera": 2
},
},
}

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

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.

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.