Saturday, September 24, 2016

How to create firefox profile in selenium webdriver


When we run selenium webdriver using firefox browser, the launched session is free of cookies and no firefox browser history is remembered. When clean browser is launched everytime, tests tend to become slower. So to make our tests faster, we can set firefox profile to run our tests faster. By default, the firefox profile is named as "default". We can view/create/rename/delete firefox profiles using firefox -p command in run window in windows OS. Make sure no firefox browser session is open when you run this command.

Generally defining the default profile works, but if you want to use any other profile, you can set it. When defining the new webdriver use the below code:

ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("enter your firefox profile name here within double quotes");
WebDriver driver = new FirefoxDriver(profile);

The above steps will define a new firefox profile for your selenium tests with all cookies remembered.
If you still face any issue, please write in comments section.