Selenium
Selenium Headless Browser Testing: HTMLUnitDriver & PhantomJS
Selenium Web driver is a web automation tool which enables you to run the tests against different...
Firefox profile is the collection of settings, customization, add-ons and other personalization settings that can be done on the Firefox Browser. You can customize Firefox profile to suit your Selenium automation requirement.
Also, Firefox or any other browser handles the SSL certificates settings. So automating them makes a lot of sense along with the test execution code.
In short a profile is a user's personal settings. When you want to run a reliable automation on a Firefox browser, it is recommended to make a separate profile.
In this tutorial, you will learn-
Firefox profile is just like different users using Firefox. Firefox saves personal information such as bookmarks, passwords, and user preferences which can be edited, deleted or created using the program manager.
Location of profile is as follows
In order to run a successful Selenium Test, a Firefox profile should be -
Let see step by step how to create a Firefox profile.
Step 1) First of all close the Firefox if open.
Step 2) Open Run (windows key + R) and type firefox.exe –p and click OK
Note: If it doesn't open you can try using full path enclosed in quotes.
Step 3) A dialogue box will open named Firefox – choose user profile
Step 4) Select option "Create Profile" from the window, and a wizard will open. Click on next
Step 5) Give your profile name which you want to create and click on finish button
Now your profile is ready you can select your profile and open Firefox.
You will notice that the new Firefox window will not show any of your Bookmarks and Favorite icons.
Note: The last selected profile, will load automatically at next Firefox launch. You will need to restart profile manager if you wish to change profiles.
To access newly created Firefox profile in Selenium Webdriver software test, we need to use webdrivers inbuilt class 'profilesIni' and it's method getProfile as shown below.
Selenium code for the profile
This is a code to implement a profile, which can be embedded in the selenium code.
ProfilesIni profile = new ProfilesIni();
// this will create an object for the Firefox profile
FirefoxProfile myprofile = profile.getProfile("xyzProfile");// this will Initialize the Firefox driver
WebDriver driver = new FirefoxDriver(myprofile)
Let see the implementation of this code in following examples.
// import the package
import java.io.File;
import java.util.concurrent.TimeUnit;
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 FirefoxProfile {
public static void main(String[] args) {
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("xyzProfile");
// Initialize Firefox driver
WebDriver driver = new FirefoxDriver(myprofile);
//Maximize browser window
driver.manage().window().maximize();
//Go to URL which you want to navigate
driver.get("http://www.google.com");
//Set timeout for 5 seconds so that the page may load properly within that time
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//close firefox browser
driver.close();
}
}
EXPLANATION FOR THE CODE:
Below is the explanation of code line by line.
Let's see one more example.
import java.io.File;
import java.util.concurrent.TimeUnit;
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 FirefoxProfile2{
public static void main(String[] args) {
// Create object for FirefoxProfile
FirefoxProfilemyprofile=newFirefoxProfile (newFile("\c:users\AppData\MozillaFirefoxProfile_name.default "));
// Initialize Firefox driver
WebDriver driver = new FirefoxDriver(myprofile);
//Maximize browser window
driver.manage().window().maximize();
//Go to URL
driver.get("http://www.google.com");
//Set timeout
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//close firefox browser
driver.close();
}
Explanation for the code:
Below is the explanation of code line by line.
Summary:
Selenium Web driver is a web automation tool which enables you to run the tests against different...
Before we look into anything else, let's first understand - Why do we need reporting? When we are...
What is an Object Repository? An object repository is a common storage location for all objects. In...
What is JavaScriptExecutor? JavaScriptExecutor is an Interface that helps to execute JavaScript...
There are two types of HTML tables published on the web- Static tables : Data is static i.e....
In this tutorial, we will see how to identify the following form elements Radio Button Check Box...