1

I am currently managing a staging environment with some authentication.

I was able to run my tests by embedding credentials to URL like this:

https://johndoe:foobar@app.s.product.com/#login

However, my tests fail because of chrome, dropping this feature(https://www.chromestatus.com/feature/5669008342777856). Is there any other way I can access our staging site? I tried inspecting the popup for credentials and maybe I can sendKeys(), but to no avail.

Thanks in advance!

Ross
  • 95
  • 1
  • 1
  • 8
  • Possible duplicate of [Chrome 59 and Basic Authentication with Selenium/Fluentlenium](https://stackoverflow.com/questions/44542740/chrome-59-and-basic-authentication-with-selenium-fluentlenium) – Florent B. Jun 19 '17 at 15:35

1 Answers1

2

Have this problem too. My solution is creation chrome extension and add it to chrome on startup.

  1. Create two files in some new folder:

background.js (change user and path with yourth)

chrome.webRequest.onAuthRequired.addListener(
        function(details, callbackFn) {
            console.log("onAuthRequired!", details, callbackFn);
            callbackFn({
                authCredentials: {username: "user", password: "pass"}
            });
        },
        {urls: ["<all_urls>"]},
        ['asyncBlocking']
    );

manifest.json

{
  "manifest_version": 2,
  "name": "Authentication for tests",
  "version": "1.0.0",
  "permissions": ["<all_urls>", "webRequest", "webRequestBlocking"],
  "background": {
    "scripts": ["background.js"]
  }
}
  1. Pack them into crx (chrome://extensions/ -> Pack extension)

  2. Add this file to project

  3. Add to conf.js:

As first line

var fs = require('fs');
const ext64 = fs.readFileSync('./ext.crx', 'base64');
exports.config = {
...

and to chrome options

capabilities: {
    browserName: 'chrome',
    chromeOptions: {
        args: ['--no-sandbox'],
        extensions: [ext64]
    }
},
Pavel Varenik
  • 71
  • 1
  • 7