By: Vitali K
Sometimes we have to run our selenium tests on the remote servers which use the basic authentication. I bet you know the annoying browser pop up which forces you to enter the credentials:
Unfortunately, selenium cannot handle native browser dialogs and we have to bypass them somehow.
There is actually more than one solution to the problem. But from my experience, the most reliable solution is using the BrowserMob Proxy.
On it’s official site, the tool is described as one which can capture performance data for web apps (via the HAR format), as well as manipulate browser behavior and traffic, such as whitelisting and blacklisting content, simulating network traffic and latency, and rewriting HTTP requests and responses.
Sounds like that’s just what we need. Let’s see it in action.
Start our proxy server
ProxyServer bmp = new ProxyServer(4444);
Set domain name(empty one means that our credentials will be applicable to any host)
bmp.autoBasicAuthorization("", "username", “VerySecuredPassword");
Convert our proxy to the format known to selenium
Proxy proxy = bmp.seleniumProxy();
Setting desired capabilities and starting the WebDriver
DesiredCapabilities capabilities = new DesiredCapabilities();
WebDriver driver = new FirefoxDriver(capabilities);
And that’s it. Now we can open the required page without getting any log in dialogs.