3

I'm trying to open a URL on ChromeDriver (for Chrome 75.0.3770.142) with authentication having a password containing the character "@", the solution of adding username/password to URL like: "https://username:p@ssword@www.test.com" and even "https://username:p%40ssword@www.test.com" didn't work for me (indeed, it worked ONLY for the FIRST time and then in all next runs the browser shows the authentication popup and asks for session credentials)

Then I tried to add a basic authentication extension to chrome with a zip file (credential.zip) containing:

manifest.json

{
  "manifest_version": 2,
  "name": "Authentication for Cartier PreProd",
  "version": "1.0.0",
  "permissions": ["<all_urls>", "webRequest", "webRequestBlocking"],
  "background": {
    "scripts": ["background.js"]
  }
}

background.js

var username = "username";
var password = "p@ssword";

var retry = 3;

chrome.webRequest.onAuthRequired.addListener(
  function handler(details) {
    if (--retry < 0)
      return {cancel: true};
    return {authCredentials: {username: username, password: password}};
  },
  {urls: ["<all_urls>"]},
  ['blocking']
);

And in Selenium (3.141.59), i setup a remotedriver as follows:

DesiredCapabilities capability = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
options.addArguments("--start-maximized");
File file = new File("src/main/resources/conf/credential.zip");
options.addExtensions(file);
capability.setCapability(ChromeOptions.CAPABILITY, options);
capability.setBrowserName("chrome");
capability.setPlatform(Platform.WINDOWS);
URL nodeUrl = new URL(<host:port>);
WebDriver  driver = new RemoteWebDriver(nodeUrl, capability);

When lunching the WebDriver, it seems that it cannot load the extension, it throws an error:

unknown error: failed to wait for extension background page to load: chrome-extension://knocbjhpojhilndiecljamdcccjifakk/_generated_background_page.html

Anyone has an idea how to resolve this ? thanks a lot in advance !

Shessuky
  • 1,846
  • 21
  • 24

0 Answers0