Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

[Latest]How to Create a Firefox Profile to use in Selenium scripts?

When WebDriver launches browser then a new session gets created and you don’t see extensions, plugins or settings which are available on your browser. Sometimes few settings become mandatory that we even want to use them with the browser opened by WebDriver. I am pretty sure that you would be searching for the solution to carry forward your personal settings with test execution browser. This article will solve your problem in Mozilla Firefox; thus, Firefox Profile is the concept to some personal settings in test execution.

Firstly, we will discuss a way to create a Firefox Profile in Windows OS then further we will look at coding implementation to use profile in Selenium WebDriver.

Recommended: Technique to handle AJAX Call in Selenium WebDriver

What is Firefox Profile?

A Firefox profile is a personalized setting of the user which consists of personal bookmarks, extensions, plugins and saved passwords.

What is the location of the Firefox profile in my system?

If you are using windows OS then follow the path below to find out the location where the profile is stored.

C:\Users\\AppData\Roaming\Mozilla\Firefox\Profiles\6whirxma.SeleniumWebDriverProfile

If you are not able to find AppData Folder then simply type %AppData% in Cortana search bar.

How to create a Firefox Profile?

Follow the steps below to create a Firefox profile. This profile will be used in your Selenium scripts for testing purpose. Also, make sure that you don’t have opened Mozilla Firefox in your system.

Step# 1: Go to Firefox profile selection option

Open run dialogue (Win+R) and type firefox.exe -p, then click OK

Step# 2: Create a New Profile

A new dialogue box will appear, then click on the Create Profile button.

Click Next.

Step# 3: Finish profile creation process

Another dialogue box appears; Give a name to your custom profile, then click Finish.

Now you have successfully created a profile. Just click on Start Firefox and customize your profile for further use in Selenium scripts.

How to use Firefox profile in Selenium WebDriver?

This is the agenda for this article. We will use the newly created profile in our automation scripts.

By using ProfilesIni class

ProfilesIni profile = new ProfilesIni();
		
		FirefoxProfile fFoxProfile = profile.getProfile("SeleniumWebDriverProfile");
		
		FirefoxOptions opt = new FirefoxOptions();
		
		opt.setCapability(FirefoxDriver.PROFILE, fFoxProfile);
			
		WebDriver driver = new FirefoxDriver(opt);

Code Explanation

In the above code, we use ProfilesIni class to instantiate the profiles and we further use getProfile() to get the Firefox profile which we created above. Since DesiredCapabilities() class is deprecated, hence, we used FirefoxOptions() here and passes the instance of FirefoxProfile in setCapability() method.

Following is the sample program which opens the Firefox browser with custom settings in the custom profile.

Sample Program

package Test;

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

public class FirefoxProfiles {

	public static void main(String[] args) throws InterruptedException {
		
		System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
		
		ProfilesIni profile = new ProfilesIni();
		
		FirefoxProfile fFoxProfile = profile.getProfile("SeleniumWebDriverProfile");
		
		FirefoxOptions opt = new FirefoxOptions();
		
		opt.setCapability(FirefoxDriver.PROFILE, fFoxProfile);
			
		WebDriver driver = new FirefoxDriver(opt);
		
		driver.get("http://www.inviul.com");
		
		Thread.sleep(3000);
		
		System.out.println(driver.getTitle());
		
		driver.close();
		
		driver.quit();
	}

}

This was all about Firefox profile handling in Selenium WebDriver. If you have any confusions then write your queries in the comment section below. Don’t miss to support us on social media for more updates on Selenium and Test Automation.

The post [Latest]How to Create a Firefox Profile to use in Selenium scripts? appeared first on Inviul.



This post first appeared on Inviul, please read the originial post: here

Share the post

[Latest]How to Create a Firefox Profile to use in Selenium scripts?

×

Subscribe to Inviul

Get updates delivered right to your inbox!

Thank you for your subscription

×