January 20, 2016

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.

The Solution:

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.

An Example:

Start our proxy server

ProxyServer bmp = new ProxyServer(4444);

bmp.start();

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();

capabilities.setCapability(CapabilityType.PROXY, proxy);

WebDriver driver = new FirefoxDriver(capabilities);

And that’s it. Now we can open the required page without getting any log in dialogs.

driver.get("http://secured.testserver.com/");

BACK TO MAIN PAGE

Previous blogs

Successes and Failures in AI Build vs. Buy Decisions

April 10, 2024
Read more

Developing a Comprehensive AI Strategy for Competitive Advantage

Read more

Let’s Talk