Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform Basic Authentication for FirefoxDriver, ChromeDriver and IEdriver in Selenium WebDriver?

I am using the Selenium-Firefox-driver and Selenium-Chrome-Driver version 2.0a5 (Web Driver API), and I am trying to test a web app that has BASIC authentication (there is a popup that come up to authenticate the user when I hit whatever page, the popup is not part of the HTML).

Now, I need to a strategy to authenticate the user in Firefox, Chrome and IE (I'm going to import the IE Driver soon).

I was reading in few articles that I can set a Firefox profile for instance..something like:

FirefoxProfile ffProfile = new FirefoxProfile(); ffProfile.setPreference("network.http.phishy-userpass-length", 255); WebDriver driver = new FirefoxDriver(ffProfile); driver.get("http://username:password@hostname");   

but it doesn't seem to work for me. Does anyone have a working solution for those browsers?

like image 209
sebarmeli Avatar asked Apr 15 '11 04:04

sebarmeli


People also ask

How does Selenium handle basic authentication pop up?

To handle the basic authentication popup, we can pass the username and password along with the web page's URL. When the login pop-up is prompted, we enter the username as “admin” and the password as “admin” and then login. Thus, the user would be successfully logged into the website.

How do I authenticate in Selenium?

New Selenium IDE We can handle browser authentication with Selenium webdriver. We have to pass the credentials appended with the URL. The username and password must be added with the format: https://username:password@URL. Let us make an attempt to handle the below browser authentication.

What is basic auth in Selenium?

To test a website which is protected by basic auth (username and password), you can authenticate yourself using one of the following techniques in the test script: Basic authentication technique. Use case. Pass username and password in the URL.

What is the difference between WebDriver and FirefoxDriver?

WebDriver is an interface. FirefoxDriver is the implementation. To understand better, please do read docs on Java Interface.


1 Answers

I got it to work with Firefox webdriver by the following:

profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", "google.com"); driver = new FirefoxDriver(profile);  driver.Navigate().GoToUrl("http://user:[email protected]"); 
like image 133
Rod Avatar answered Sep 19 '22 16:09

Rod