What Is the Firefox Profile?
When you Install Firefox In your computer, Firefox creates one default profile folder In your local drive to save your preferences like your bookmarks, your preferred home page on Firefox open, your toolbar settings, your saved passwords and all the other settings. You can create different profiles for your Firefox browser as per your software testing requirement. Now supposing same computer Is used by two users and both wants their own Firefox settings then both users can create their own Firefox profile to access their own settings when he/she opens Firefox browser.
You can LEARN SELENIUM WEBDRIVER STEP BY STEP to become master of selenium Webdriver software testing tool.
If you have noticed, When you will run your selenium webdriver software automation test In Firefox browser then WebDriver will open blank Firefox browser like No bookmarks, No saved passwords, No addons etc.. as shown In bellow given Image.
If you wants access of all these things In your selenium webdriver software automation test browser then you have to create new profile of Firefox and set all required properties In newly created profile and then you can access that profile In webdriver using FirefoxProfile class of webdriver.
First Of all, Let us see how to create new profile of Firefox and then we will see how to use that profile In your test.
How to Create New Custom Firefox Profile For Selenium WebDriver?
To create new firefox profile manually,
- Close Firefox browser from File -> Exit.
- Go to Start -> Run and type "firefox.exe -p" In run window and click OK. It will open "Firefox - Choose User Profile" dialogue as shown In bellow Image.
- Now click on Create profile button. It will open create profile wizard dialogue. Click On Next as shown In bellow given Image.
- On next screen, Give profile name = "WebDriver_Profile" and click on finish button as shown In bellow given Image.
- It Will create new profile of Firefox.
- To use that newly Created profile, Select that profile and click on Start Firefox button as shown In bellow given Image. It will open Firefox browser with newly created profile.
Now you can make you required settings on this new created profile browser like add your required addons, bookmark your required page, network settings, proxy settings, etc.. and all other required settings.
How To Access Custom Firefox(Changing User Agent) Profile In Selenium WebDriver Test
To access newly created Firefox profile In selenium WebDriver software test, We needs to use webdriver's Inbuilt class ProfilesIni and Its method getProfile as shown In bellow given example.
package Testng_Pack;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class custom_profile {
WebDriver driver;
@BeforeTest
public void StartBrowser() {
//Create object of webdriver's inbuilt class ProfilesIni to access Its method getProfile.
ProfilesIni firProfiles = new ProfilesIni();
//Get access of newly created profile WebDriver_Profile.
FirefoxProfile wbdrverprofile = firProfiles.getProfile("WebDriver_Profile");
//Pass wbdrverprofile parameter to FirefoxDriver.
System.setProperty("webdriver.gecko.driver", "D:\\Selenium Files\\geckodriver.exe");
driver = new FirefoxDriver(wbdrverprofile);
}
@Test
public void OpenURL(){
driver.get("http://only-testing-blog.blogspot.com/2014/05/login.html");
}
@AfterTest
public void CloseBrowser() {
driver.quit();
}
}
When you will run above given example, It will open Firefox browser with newly created profile settings.
Why needs To Set Firefox Profile In Selenium WebDriver
To perform some actions In your selenium webdriver software automation test, You need special Firefox profile. Some example actions are as bellow where we need to set Firefox profile. We will learn more about how to perform all those actions In Selenium webdriver software automation testing tool In my upcoming posts.
1. To Download files. VIEW EXAMPLE
2. To Set Proxy Settings. VIEW EXAMPLE
3. To Resolve Certificate related errors. VIEW EXAMPLE
If you have any example where we need to set Firefox profile properties then you can share It with world by commenting bellow.
Helpful. Thank you.
ReplyDeleteI have been posting you questions regarding this.
ReplyDeleteI am glad I found it. This is what I am looking for.
unable to open firebug in opened firefox window... what can be an issue ...pls help...
ReplyDeleteMay be there Is some issue with latest version of browser..
DeleteOpen "firefox.exe -p" from Start Menu -> Run and choose default profile in that window then click on "Start Firefox" button. it will open browser with your default settings.
ReplyDeleteNice help :)
ReplyDeleteEvery thing is awesome but one suggestion.
ReplyDeleteCould you change the color of the comments? It is very hard to read. Thank you.
Could you change the color of the comments? It is hard to read. Thank you for doing all the good work.
ReplyDeletethanks for the documentation, it is very useful
ReplyDeletein this line driver = new FirefoxDriver(wbdrverprofile);
ReplyDeletehighlights red wbdrverprofile
it does not work now
ReplyDeleteHi, according to internet, the below is the answer for "The constructor FirefoxDriver(wbdrverprofile) is undefined"
ReplyDeleteusing
@BeforeTest
public void StartBrowser() {
//Create object of webdriver's inbuilt class ProfilesIni to access Its method getProfile.
ProfilesIni firProfiles = new ProfilesIni();
//Get access of newly created profile WebDriver_Profile.
FirefoxProfile wbdrverprofile = firProfiles.getProfile("WebDriver_Profile");
//Pass wbdrverprofile parameter to FirefoxDriver.
wbdrverprofile.setPreference("browser.popups.showPopupBlocker", false);
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(wbdrverprofile);
System.setProperty("webdriver.gecko.driver",
"C:\\Users\\ermao\\eclipse-Aravind\\AravindSeleniumWebdriverpart_1_2\\src\\browersExe\\geckodriver.exe");
driver = new FirefoxDriver(firefoxOptions);
}
Thanks for the documentation. Do you know how to do with python
ReplyDelete