I am trying to run a Selenium test with Google Chrome. I'd like this to login using HTTP basic authentication. This is not implemented in Selenium, so the advice is to load an extension. I'm using code from
https://github.com/RobinDev/Selenium-Chrome-HTTP-Private-Proxy and the answer to "How to override basic authentication in selenium2 with Java using chrome driver?"
I have tried to adapt it to my needs.
Update
Checkout the Minimum Working Example.
git clone git@github.com:alexbiddle/selenium-chrome-http-basic-auth.git
Excerpt below
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "https",
host: "subdomain.example.com"
},
bypassList: ["foobar.com"]
}
};
chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
function callbackFn(details) {
return {
authCredentials: {
username: "example",
password: "abc123"
}
};
}
chrome.webRequest.onAuthRequired.addListener(
callbackFn,
{urls: ["<all_urls>"]},
['blocking']
);
Loading it in Java using
ChromeOptions chromeOptions = new ChromeOptions();
File proxyPath = new ClassPathResource("proxy.zip").getFile();
chromeOptions.addExtensions(proxyPath);
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setCapability(CAPABILITY, chromeOptions);
webDriver = new ChromeDriver(capability);
I double-checked the docs at https://developer.chrome.com/extensions/proxy#type-ProxyServer in case there was a missing value of something, however when loading the test with the URL
https://subdomain.example.com
It fails with
ERR_TUNNEL_CONNECTION_FAILED
I'm using Chrome on Mac.