HTTP Basic Auth via URL in Firefox does not work? HTTP Basic Auth via URL in Firefox does not work? selenium selenium

HTTP Basic Auth via URL in Firefox does not work?


Contributing to Druska´s answer, you can do the same configuration using Selenium 2 API:

FirefoxProfile profile = new FirefoxProfile();profile.setPreference("network.http.phishy-userpass-length", 255);profile.setPreference("network.automatic-ntlm-auth.trusted-uris","yourDomain");new FirefoxDriver(profile);

This approach is simpler and you do not have to ask every developer to change their Firefox configuration. I only tested with the Firefox driver.

UPDATE:

For some reason (maybe the ones explained at https://stackoverflow.com/a/14348701/256245), the above solution does not work with newer versions of Firefox. Here is what works for me now (tested with Firefox 19.0.2):

  1. Install AutoAuth Firefox plugin;
  2. Visit the site where the authentication is needed. Enter your username and password and make sure to choose to save the credentials;
  3. Save AutoAuth installation file at your hard drive: at the plugin page, right click at “Add to Firefox” and “Save link as”;
  4. Instantiate Firefox webdriver as following:

    FirefoxProfile firefoxProfile = new ProfilesIni().getProfile("default");File pluginAutoAuth = new File("src/test/resources/autoauth-2.1-fx+fn.xpi");firefoxProfile.addExtension(pluginAutoAuth);return new FirefoxDriver(firefoxProfile);

Make sure to instantiate the pluginAutoAuth File with the correct path where you saved the plugin installation. If you do not feel comfortable using the default profile, you can use Firefox Profile Manager and create one specific to your tests.

Reference to this new solution: http://watirmelon.com/2012/06/27/automatic-firefox-authentication-when-using-selenium-webdriver-with-autoauth/


I have a solution for Firefox and Internet Explorer.

For Firefox, you need to go into about:config and create the integer network.http.phishy-userpass-length with a length of 255. This tells Firefox not to popup an authentication box if the username and password are less than 255 characters. You can now use http://user:pass@domain.com to authenticate.

For Internet Explorer, you must edit the registry. In the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE, create the DWORD values iexplore.exe and explorer.exe and make sure their values are 0.

I had to override NTLM authentication aswell. To NTLM authenticate using the HTTP basic authentication syntax in Firefox, simply specify the domains being used in the Firefox config string network.automatic-ntlm-auth.trusted-uris (accompanying the first config option). This will work in IE with the registy edit alone.


Add a slash after the context root:

Instead of:selenium.open("http://myusername:myuserpassword@mydomain.com/mypath");

use:selenium.open("http://myusername:myuserpassword@mydomain.com/mypath/");

It makes all the difference of the world adding the slash at the end of the context root. Without the slash, the popup opens, with the slash it gets authenticated as expected.

Note, that this is not a selenium bug or whatnot, but a firefox thing. You can use your command line as well to see for yourself:

 C:\Program Files\Mozilla Firefox>firefox http://myusername:myuserpassword@mydomain.com/mypath/

For me, it works even without settings the networks uris:

FirefoxProfile profile = new FirefoxProfile();//profile.setPreference("network.automatic-ntlm-auth.trusted-uris", "mydomain.com");//profile.setPreference("network.negotiate-auth.trusteduris", "mydomain.com");WebDriver driver = new FirefoxDriver(profile);driver.navigate().to("http://myusername:myuserpassword@mydomain.com/mypath/");


versions
Firefox 19.0,
selenium-java 2.31.0