I encountered an interesting problem last week.
I had to make an automated test scripts on a test site which was protected by Basic HTTP Authentication.
I’ll assume that everybody knows how Basic HTTP Authentication works and will just focus on the solution:
WebDriver driver = new ChromeDriver();
driver.get("http://username:password@URL");
Of course you should change the username, password and URL strings to your data .
To pass the basic http authentication in firefox, you have to set a browser preference during the driver creation.
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("network.http.phishy-userpass-length", 255);
driver = new FirefoxDriver(profile);
driver.get("http://username:password@URL");
The added setting will disable the anti-phishing dialog box.
Similar Posts from the author:
- How to integrate a JUnit4 – Webdriver test into JMeter
- Browserstack integration with junit and webdriver
- How to setup Selenium WebDriver with Visual Studio and NUnit
- Running webdriver code in JMeter
- Some thoughts on Sauce
2 thoughts to “Basic HTTP authentication and Webdriver”
Firefox and Chrome both work great using the above method, except for in more recent releases, where it is disabled.
Internet Explorer requires a registry hack in order to do the above.
You could use a proxy server (like BrowserMob) to do the basic authentication without having to do any of that.
I just got done putting together a prototype project for C# Selenium WebDriver that should work for IE, Firefox, and Chrome out of the box.
https://sourceforge.net/projects/seleniumbasicauthwrapper/?source=navbar
Maybe it will help.
Thanks. We will look into this.
Comments are closed.