How to implement protractor grid system using JavaScript? - protractor

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.

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

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

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