Custom Firefox Profile for Selenium Webdriver
Introduction
In this tutorial, we will learn how to create a Custom Firefox Profile. A Firefox profile is a collection of bookmarks, browser settings, history etc.
Why you need a custom profile ?
A simple example is that you may want to have all your tests run under same Firefox profile across all tests.
The most common example is an SSL certificate settings or browser plug-ins.Furthermore, it makes sense to create a profile that handles these special test needs.
You should be consistent with the profile you use on all test execution machines. If you used different profiles everywhere, the certificates you accepted or the plug-ins you installed would be different and that would make the tests behave differently across machines.
How to create Firefox custom profile on Windows ?
Step1 : If Firefox is open, close Firefox:
Step2 : Press Windows Key +R on the keyboard. A Run dialog will open.
Step3 : as shown above , in the Run dialog box, type in firefox.exe -P
( You can also use -P, -p or -ProfileManager )
Steps4 : Follow the steps of profile manager as shown in the pictures.
Step 5:
Step 6
How to use the custom profile created in selenium webdriver automation ?
Below code example to demonstrate how to use the custom profile.
public class FirefoxCustomProfile { WebDriver firefoxdriver; @BeforeSuite public void launchBrowser() { ProfilesIni profileIni = new ProfilesIni(); FirefoxProfile customprofile = profileIni.getProfile("testingdocs"); firefoxdriver = new FirefoxDriver(customprofile); } @Test public void openFacebookURL() { firefoxdriver.get("https://www.facebook.com"); } @AfterSuite public void closeBrowser() { firefoxdriver.quit(); } }
Another example :
For example to disable Flash within Firefox for Browserstack test as passing it to desiredcapabilities .It is possible to disable Flash within Firefox, by setting the profile capability to 0. Flash is enabled by default.
FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("plugin.state.flash", 0); caps.setCapability(FirefoxDriver.PROFILE, profile);
Conclusion:
You should use a custom profile for all your firefox tests if you need customization for the entire execution. Also, each time Selenium starts a new session driving a Firefox instance, it copies the entire profile in a temporary directory. So, having lightweight profile makes the tests fast and also reliable!
Selenium Tutorials on this website:
https://www.testingdocs.com/selenium-webdriver-tutorial/
Official Website: