Friday 11 March 2016

Automating Firefox http Authentication Window with Selenium WebDriver

Automating Firefox http Authentication Window:

As all of you know that Selenium WebDriver have no sufficient capability to automate html based pop up windows like Image/Video Upload windows.To come over this issue we mostly use AutoIT tool with selenium Webdriver.Being an Automation Engineer accepted new challenge of automating Browser Basic Authentication Window, initially tried my best with AutoIT but failed then visited different blogs and finally came with this solution mentioned below step by step.

1-Open Eclipse IDE

2-Press on File -->New-->Java Project and Enter Project Name "BasicAuthenticationProject" and press on save button.

3-Right Click on Project-->New-->Package and Enter Package Name "com.basic.auth"

4-Right Click on Package-->New-->Class and Enter Class Name "AuthenticationTests"

5-Create three instance variables and assigned them values.
     static WebDriver driver=null;
     static String userName="xyz";
     static String userPassword="xyz";

6-Create a method browserInitialization and use instance variables in driver.get(); method
public static void browserInitialization(){}

7-Using Webdriver initialize firefox instance in browserInitialization method
    driver=new FirefoxDriver();

8-Call the driver.get method and concatenate userName and userPassword variables with url as a argument
driver.get("http://" + userName + ":" + userPassword+ "@" +"google.com");

9-Execute your Class and observe that Browser Authentication does not displayed and user logins successfully.

Note:Don't forget to import all required libraries.

See below Complete Code:

public class AuthenticationTests{
static WebDriver driver=null;
static userName="xyz";
static userPassword="xyz";

public void browserInitialization(){
driver=new FirefoxDriver();
driver.get("http://" + userName + " : " + userPassword+ "@" +"google.com");

}

}