How to get rid of IE security dialog with Selenium / Nightwatch.js / Browserstack - selenium

When running tests against IE in browserstack it seems that IE is coming up with a security exception message:
This is coming up because the backend api that is being called is using a self signed cert which is untrusted (it needs to be like this for CI as the api has a different url each time CI creates the backend)
What needs to happen for this automated test to run is that the dialog needs to be accepted (or not come up at all) - but I dont see any way of doing this through the nightwatch framework.
I have tried things like, clicking the left arrow using browser.setValue('button', [browser.Keys.LEFT_ARROW]);
and also tried clicking the button with the 'Yes' value but nothing seems to work.
I have also set acceptSslCerts in my ie profile setup:
"ci_ie": {
"launch_url" : "http://hub.browserstack.com",
"selenium_port" : 80,
"selenium_host" : "hub.browserstack.com",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "ie",
"javascriptEnabled": true,
"acceptSslCerts": true,
"ignoreProtectedModeSettings": true,
"browser_version": "10",
"os_version": "7",
"os": "windows"
}
}
Any ideas on how to resolve this would be greatly appreciated.

Correct, you cannot control this popup via selenium webdriver, it is out of the scope/reach of it.
Instead, you need to prevent it from being shown in the first place:
How to deal with certificates using Selenium?
In case of IE, you should set the acceptSslCerts desired capability to "true":
"desiredCapabilities" : {
"browserName" : "internet explorer",
"javascriptEnabled" : true,
"acceptSslCerts" : true,
}
You might also need to set the ignoreProtectedModeSettings to "true":
"desiredCapabilities" : {
"browserName" : "internet explorer",
"javascriptEnabled" : true,
"acceptSslCerts" : true,
"ignoreProtectedModeSettings": true
}
There is also this workaround (you might need to set acceptSslCerts to "false" for that to work).

I fixed this by adding:
"unexpectedAlertBehaviour": "accept"
to the desiredCapabilities section in my nightwatch config.
I think it maybe due to acceptSslCerts getting ignored for XHR requests.

Related

WebdriverIO How to DISABLE "Save Password" popup in Chrome 84?

I'm desperate to find this solution because it seems nothing on the web is working atm.
My WDIO dependencies
"#wdio/browserstack-service": "^6.1.15",
"#wdio/cli": "^6.3.4",
"#wdio/cucumber-framework": "^6.3.0",
"#wdio/devtools-service": "^5.13.0",
"#wdio/local-runner": "^6.3.4",
"#wdio/spec-reporter": "^6.3.0",
"#wdio/sync": "^6.3.3",
Basically I need to disable this popup:
https://imgur.com/a/51GZLtY
I've disabled a param in my chrome:
chrome://settings/passwords - Offer to save passwords
observed file
AppData\Local\Google\Chrome\User Data\Default\Preferences
1 pref were added
"credentials_enable_service": false,
worth to mention that I've tried other values:
"credentials_enable_service": "false"
"credentials_enable_service": 0
"credentials_enable_service": "0"
"credentials_enable_service": 1
"credentials_enable_service": "1"
"credentials_enable_service": 2
"credentials_enable_service": "2"
in my capabilities I have added the following:
"goog:chromeOptions": {
"prefs": {
"credentials_enable_service": false
},
"args": [some arguments]
}
But popup is still present
and in a chrome created by WDIO I can see that param
chrome://settings/passwords - Offer to save passwords - is ENABLED
So my question is whether WebdriverIO passes "goog:chromeOptions": { "prefs": {} } to Chrome browser?
It seems that prefs are not passed. Atleast in a form i try because args array work perfectly
Any suggestions?
Simply add '--enable-automation' to the args.
Cheers.
Updating Capabilities like this works fine in the Chrome browser
capabilities: [{
'goog:chromeOptions': {
args: ["--disable-gpu", "--enable-automation","--headless"]
}
}],

How to setup custom browser versions for selenium grid?

Setup
We have a selenium grid where all nodes are completely identical except one. All the identical nodes run windows 10, have basic chrome, IE, edge browsers, and run on MST. The exception runs IE, chrome, and edge, but they are set to look like it is in the UK, and runs GMT+0 most of the year (except DST of course then it runs BST). This changes date formats and such and is used to test that dates are formatted properly and that documents on our system reflect accurate times in their own timezone. The browsers on the UK node all have custom browser versions declared in their node_XXXX.json file for selenium grid.
Issue
We lost our hub server a while back, and after rebuilding we can no longer get the IE, EDGE, and Firefox browsers to work on the UK server. We used to use custom browser versions for the Uk browsers eg: instead of "version":11 it is "version":"11.eu" to denote that we wanted to run on the special server. Chrome works fine with this model. However, IE is giving an error:
OpenQA.Selenium.WebDriverException : Error forwarding the new session cannot find : Capabilities {browserName: internet explorer, browserVersion: 11.eu, platformName: windows, se:ieOptions: {enablePersistentHover: true, ie.ensureCleanSession: true, nativeEvents: true}}
Attempted Solutions
We have already tried to change the version number (It used to say 9.eu, legacy from when we were running IE9). We have also tried "updating" IE to version 11 again. Nothing has worked or allowed the driver to connect.
Question
How do we get our UK IE browser to work on the selenium grid again? We have many tests failing simply because they cannot connect to a driver instance. Any help would be appreciated, thanks!
Reference
For reference, here is our node_XXXX.json file:
{
"capabilities": [
{
"seleniumProtocol": "WebDriver",
"browserName": "firefox",
"maxInstances": 1,
"version": "17.eu",
"platform": "WINDOWS"
},
{
"seleniumProtocol": "WebDriver",
"browserName": "internet explorer",
"maxInstances": 1,
"version": "11.eu",
"platform": "windows"
},
{
"seleniumProtocol": "WebDriver",
"browserName": "chrome",
"maxInstances": 1,
"version": "77.eu",
"platform": "WINDOWS"
}
],
"loadedFromFile":
"node_5555.json",
"proxy": "com.groupon.seleniumgridextras.grid.proxies.SetupTeardownProxy",
"servlets": [],
"maxSession": 3,
"port": 5555,
"register": true,
"unregisterIfStillDownAfter": 10000,
"hubPort": 4444,
"hubHost": "test-slum01.ndtest.local",
"registerCycle": 5000,
"nodeStatusCheckTimeout": 10000,
"custom": {},
"downPollingLimit": 0
}
And this is the code that calls the remote web driver:
case "iehta9UK":
var ieUkOptions = new InternetExplorerOptions();
ieUkOptions.EnsureCleanSession = true;
ieUkOptions.BrowserVersion = "11.eu";
return IS_REMOTE_RUN ? CreateRemoteWebDriver(ieUkOptions) : new InternetExplorerDriver(ieUkOptions);
This is the strictly US IE code that works fine:
case "IE":
case "ie":
case "InternetExplorer":
case "iehta11":
var ieOptions = new InternetExplorerOptions();
ieOptions.EnsureCleanSession = true;
return IS_REMOTE_RUN ? CreateRemoteWebDriver(ieOptions) : new InternetExplorerDriver(ieOptions);
Aha! We figured it out. We had made the changes to the node_XXXX.json file shown above, but had not restarted the selenium grid service.
Make sure you restart the server after making changes to the json file for them to take affect.

Nightwatch vs. self signed certificates

My nightwatch.js setup for Geckodriver is as follows:
"firefox": {
"launch_url": "...",
"selenium_port": 4444,
"selenium_host": "localhost",
"silent": true,
...
"desiredCapabilities": {
"browserName": "gecko",
"marionette": true,
"acceptSslCerts": true
}
}
When running, all tests fail because my certificate is insecure testing on a local installation and enforced ssl. Chromedriver (with basically identical setup) seems to accept the "acceptSslCerts" property and ignores the wrong cert. Geckodriver does not. Is the config wrong or does Nightwatch or Selenium have a problem with "acceptSslCerts"?
I am using the latest version of Geckodriver and Selenium 3.8.1
It looks like the correct capability for the firefox driver is acceptInsecureCerts.
You can see it listed here.

Error when running Selenium Server via Nightwatch

I'm attempting to run a simple test script. But I receive the following error:
I have my nightwatch config file setup as so:
nightwatch.conf.js
module.exports = {
"src_folders": [
"tests"// Where you are storing your Nightwatch e2e/UAT tests
],
"output_folder": "./reports", // reports (test outcome) output by nightwatch
"selenium": {
"start_process": true, // tells nightwatch to start/stop the selenium process
"server_path": "./node_modules/selenium-standalone/.selenium/selenium-server/2.53.1-server.jar",
"host": "127.0.0.1",
"port": 4444, // standard selenium port
"cli_args": { "webdriver.chrome.driver" : "./node_modules/selenium-standalone/.selenium/chromedriver/2.25-x64-chromedriver"
}
},
"test_settings": {
"default": {
"screenshots": {
"enabled": true, // if you want to keep screenshots
"path": './screenshots' // save screenshots here
},
"globals": {
"waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
},
"desiredCapabilities": { // use Chrome as the default browser for tests
"browserName": "chrome"
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true // set to false to test progressive enhancement
}
}
}
}
guinea-pig.js
module.exports = { // addapted from: https://git.io/vodU0
'Guinea Pig Assert Title': function(browser) {
browser
.url('https://saucelabs.com/test/guinea-pig')
.waitForElementVisible('body')
.assert.title('I am a page title - Sauce Labs')
.saveScreenshot('ginea-pig-test.png')
.end();
}
};
The server path and chromedriver path are accurate and the most recent copy. I also have the latest version of chrome installed. Can someone please help me understand what could be the problem? Thanks!
Edit: I've also restarted the whole computer, same issue.
Try using the latest version of the Selenium standalone server v.3.0.1
If that doesn't work, then you can upgrade your chromedriver to the latest version and test. You can find the different versions here:
https://chromedriver.storage.googleapis.com/index.html
Also make sure you are using the most recent version of Nightwatch v0.9.9 and update it in you package.json file.
It is written very clear , your chrome version is lower than what chromedriver needs, just update your chrome to the latest version

Can nightwatch.js use usingServer from selenium-webdriver?

I have a suite of tests using local drivers built with nightwatch. Works well.
I am running a basic test using Perfecto Mobile and selenium-webdriver. It works with this example.(https://community.perfectomobile.com/series/20208/posts/1002862)
I am trying to connect my suite of nightwatch test to perfecto, but can't start selenium. If this is the url of the selenium server.
var url = "https://mobilecloud.perfectomobile.com/nexperience/perfectomobile/wd/hub";
I tried a few ways to set it up under nightwatch config, but can't make it work.
"selenium" : {
"start_process" : true,
"host" : "mobilecloud.perfectomobile.com/nexperience/perfectomobile/wd/hub"
}
Is there an equivalent to usingServer in nightwatch? I haven't seen anything in the docs.
driver = new webdriver.Builder().
usingServer(url).
withCapabilities(capabilities).
build();
Turns out this was the setup needed.
"test_settings" : {
"perfecto" : {
"use_ssl": true,
"default_path_prefix": "/nexperience/perfectomobile/wd/hub",
"selenium_port" : 443,
"selenium_host" : "mobilecloud.perfectomobile.com",
"desiredCapabilities": {
"browserName": "xxx",
"deviceName": "xxx",
"user": "xxx#xxx.xxx",
"password": "xxx",
"platformName": "xxx"
}
}
}
The important part that didn't work at the time of writing the question: the default_path_prefix was not customizable.
/wd/hub was the default prefix. But I really needed /nexperience/perfectomobile/wd/hub.
Two days later, this commit was introduced. It is available in 0.9.5 release.
https://github.com/nightwatchjs/nightwatch/commit/aa24c2c2334c42388318498f654d8fe2957967d1