Firefox Profiling in Selenium
In the previous post, we have learnt few useful operations on Excel File using POI API. In this post, we will see the importance of Firefox Profiling in Selenium.
When we start Fire fox browser using Selenium, it opens a fresh instance of browser. If you have some customized setting in browser like book marks, plugin, Firebug ,Fire path etc. It will not be loaded with the opened browser instance in selenium. That’s a good point, it will speed up the browser slightly.
But sometimes, there might be requirements you would like to customize your browser that should open during execution.
- You might want your browser to handle some SSL certification error, so you don’t need to add the separate code for handling it.
- You may add some required site in trustworthy sites of the browser.
- You may add preferred privacy options.
- You may add preferred security options.
All of this is possible by creating your customized Firefox Profiling.
In short, Profile in Firefox is a collection of bookmarks, browser settings, extensions, passwords, and history customized by you to have a personal browser. This may help to to make automation reliable and smooth in terms of browser handling.
Where to find the profile folder in System?
Find below the path of the folders where the firefox profile is residing for different operating systems.
Operating Systems | Firefox Profile Folder path |
Window XP/2000/Windows 7 , 8 | %AppData%\Local\Mozilla\Firefox\Profiles\xxxxxxxx.default |
Linux | ~/.mozilla/firefox/xxxxxxxx.default |
Mac OS X | ~/Library/Application Support/Firefox/Profiles/xxxxxxxx.default |
Note: The String ‘xxxxxxxx’ is nothing but the name of Profile, which is made up of 8 random character and numbers. It is assigned by Firefox itself. There is already one default profile present in the profile folder.
How to create Firefox Profile?
Note: Make sure before creating Firefox profile, all firefox browser windows should be closed.
Step#1 Open a Run command window by pressing “windows Key + R” . It will open a window as shown below.
Step#2 Type “firefox.exe -p” in the Edit box of the run window and click OK. It will open a Firefox Profile manager window. Which have few buttons to create profile, rename profile, delete profile, Exit etc. (as shown below).
Step#3 You can see a default profile already present which we have seen in the profile folder as well above. Now, Click on button“Create Profile” and follow the steps as screen shots given below.
Step#4 Provide the desired profile name (We have given “Selenium_User”) and you have the option to choose folder location to keep your profile. Click Finish.
Step#5 After Clicking Finish, It will show your profile Create in the Firefox Profile manager.
Step#6 To customize the browser settings according to your need, Click “Start Firefox” button.It will open Firefox browser instance.
For demo purpose, we are bookmarking “Gmail” and “Yahoo”. So, next time when we open out Firefox Profile through Selenium. Both the bookmarks should be available.
Step#7 After Customizing setting, Close the browser. It is suggested not to directly close the browser, Instead Go to File –> Exit.
How to use your Firefox Profile in Selenium?
Create a class and use the below code to open you Firefox Profile. In the code first we are loading Firefox profile using method “getProfile” and that profile is passed to FirefoxDriver instance.
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 FireFoxProfileExample { public static void main(String[] args) { ProfilesIni Prof = new ProfilesIni(); //Provide your profile name FirefoxProfile profile = Prof.getProfile("Selenium_User"); //Open Firefoxdriver that will open your Firefox Profile WebDriver driver = new FirefoxDriver(profile); } }
Output: As an output, you will be able to see the bookmark which were saved with the profile.