• Jobs
  • About
  • Custom Firefox profile for Selenium April 14, 2010

    Why create a new Firefox profile

    A profile in Firefox is a collection of bookmarks, browser settings, extensions, passwords, and history; in short, all of your personal settings. When you want to run automation reliably on a Firefox browser:

    • You should be consistent with the profile you use on all development and test execution machines. If you used different profiles everywhere, the SSL certificates you accepted or the plug-ins you installed would be different and that would make the tests behave differently on the machines.
    • There are several times when you need something special in your profile to make test execution reliable. The most common example is a SSL certificate settings or browser plug-ins that handle self-signed certs. It makes a lot of sense to create a profile that handles these special test needs and packaging and deploying it along with the test execution code.
    • You should use a very lightweight profile with just the settings and plug-ins you need for the execution. Each time Selenium starts a new session driving a Firefox instance, it copies the entire profile in some temporary directory and if the profile is big, it makes it, not only slow but unreliable as well.

    Creating a new profile using the Profile Manager

    Here are the steps:

    • Close the application and make sure that it is not running in the background.
    • Start the Profile Manager
      • Windows
        • Open the Windows “Start” menu, select “Run” (on Windows Vista, use “Start Search” or enable the Run box, as described here) then type and enter one of the following:
          firefox.exe -P
          or run the Profile Manager
          "C:\Program Files\Mozilla Firefox\firefox.exe" -profilemanager
      • Linux
        • Open the terminal and execute cd firefox program directory. If you don’t know where firefox is installed, you can always do
          locate firefox
        • Then execute:
          ./firefox -profilemanager
      • Mac OS X
        • Assuming the program is installed in the “Applications” folder, launch Terminal (“Applications -> Utilities -> Terminal”)
        • Enter the command starting with / after the prompt in Terminal:
          /Applications/Firefox.app/Contents/MacOS/firefox-bin -profilemanager
          Adding -bin after the application name is necessary on some systems and application versions. If you have problems starting the Profile Manager with one of the above commands, try again using just the application name.

      It looks something like this:

    • Click the “Create Profile” button and click “Continue”
    • Set the folder name. Here I am setting it as “QAAutomationFFProfile”. Click the “Create” button.
    • Now set this new profile name. I am setting it as “QAAutomation”. Click “Done”.
    • Create your profile:
      • Start the firefox session using the firefox executable with the -P "QAAutomation" option. For example on Mac it would be:
        /Applications/Firefox.app/Contents/MacOS/firefox-bin -P "QAAutomation"
      • If you see the “Default Browser” question, click Yes.
      • This will create all the files for your new profile in the folder you specified earlier.

    Make it part of your selenium session

    In Selenium2 – WebDriver

    You can now add the path to your profile that you would use while instantiating the FirefoxDriver:

    File profileDirectory = new File(profileDirectory);
    FirefoxProfile profile = new FirefoxProfile(profileDirectory);
    WebDriver webDriver = new FirefoxDriver(profile);

    If you want more details about how to instantiate the various WebDrivers, see this post.

    In Selenium RC

    If you are using ant to start selenium as described in the Getting started with Selenium Remote Control post. First copy your Firefox profile directory under your project dir/config folder. Then modify your start-selenium target to:

    <target name="start-selenium" description="starts selenium server">
        <echo>Starting selenium server</echo>
        <java jar="${lib.dir}/selenium-server.jar" fork="true" spawn="true" classpathref="testautomation.classpath">
            <arg line="-port ${selenium.port} -firefoxProfileTemplate ${basedir}/config/QAAutomationFFProfile -trustAllSSLcertificates"/>

    Now when you run the ant start-selenium target, selenium will use this new profile when the test drives a firefox browser.

    Posted by Rahul Poonekar in : Selenium

    3 responses to “Custom Firefox profile for Selenium”

    1. Tetiana says:

      Note, that -firefoxProfileTemplate option is ignored by WebDriver and it will use default profile.

      The profile should be added to capabilities, for example, if you need on Selenium Grid and RemoteWebDriver to add Firebug plugin to the profile, this may help:
      1. Download firebug-1.7.3-fx.xpi to your disk in advance
      2. Use code like:

      File ext = new File(“firebug-1.7.3-fx.xpi”);
      FirefoxProfile profile = new FirefoxProfile();
      if (ext.exists()) {
      profile.setPreference(“extensions.firebug.currentVersion”, “1.7.3”); //avoid startup screen
      profile.setPreference(“extensions.firebug.console.enableSites”, true); //enable console

      //some more prefs:
      profile.setPreference( “app.update.enabled”, false);
      profile.setPreference( “browser.tabs.autoHide”, true);

      //use this profile:
      DesiredCapabilities capability = DesiredCapabilities.firefox();
      capability.setCapability(FirefoxDriver.PROFILE, profile); //FirefoxDriver.PROFILE = “firefox_profile”;

      //run driver with this profile this profile:
      RemoteWebDriver driver = new RemoteWebDriver(capability);

    2. Darra says:

      Thanks for that, it really helped me out!

      I guess there is no faster way to do this? i.e. it takes about 10/15 seconds for firefox to now launch.

    3. fv says:

      This solution it’s slower, but works.
      Otherwise it is incomprehensible why this bug is not resolved quickly in selenium2.

    Leave a Reply

    Your email address will not be published. Required fields are marked *