Authentication dialog with selenium and Firefox profile

Previously I published a post to handle Authentication dialog with autoit.But today we handle this dialog without autoit. For this purpose we need to create a new firefox profile. If you don’t know how to create new firefox profile , you can see this article.
We need autoauth addon to store authentication password to our local.

Now open new profile and add this addon and also save it to your local.
It will required for our test script.
And open that particular site which asked for authentication.
[Example – http://demo.tanmaysarkar.com/authentication/ id-“tanmay” pw-“sarkar”]

Enter id and password and you will see “password save” message is coming.
Now authentication credentials are saved into your local on that profile.

Now everything is ready , just run the following code to automate your test.

package com.tanmaysarkar.demo;

import java.io.File;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;

public class Check {

	public WebDriver driver;
	private String baseUrl;
	
	public static void main(String[] args) {
		Check c = new Check();
		c.launch_browser();
	}
	public void launch_browser(){
		try{
		 FirefoxProfile firefoxProfile = new ProfilesIni().getProfile("Test User");
		 File pluginAutoAuth = new File("e:\\auto-auth.xpi");
		 firefoxProfile.addExtension(pluginAutoAuth);
		 driver = new FirefoxDriver(firefoxProfile);
		 baseUrl = "http://demo.tanmaysarkar.com/authentication/";
		 driver.get(baseUrl);
		 driver.manage().window().maximize();
		 System.out.println("Opening " + baseUrl);
		 System.out.println("Without Authentication i am running");
		 //driver.quit();
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}

}

Note :- “Test User” is my new Firefox profile name.

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *