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

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

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

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.

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.

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