Setting up and Automation Friendly Firefox Profile

Tags: 

Step – 1: Create a Firefox profile that you want to use with selenium

How to create Firefox profile for your Selenium?

 

  1. Make sure all your firefox instance are closed
  2. Click Start>Run
  3. Type “firefox.exe -ProfileManager -no-remote”
  4. Select “Create Profile” (i.e. selenium)
  5. Click “Next”
  6. Enter new profile name. It is wise NOT to use the same name for your profile as you do for your profile folder (as described in step 7 below). So if your directory will be named "..\ffprofiles\seleniumAutomationProfile", then consider making your profile name "SeleniumUser" so you can tell them apart if you need to debug profile issues and find yourself looking at all kinds of logging, or configuration files/screens etc. Just makes it easier to immediately distinguish the two values.
  7. Select a directory folder to store your new profile. I have found that it is wise to create a "ffprofiles" directory in a common location where the rest of your automation folders can be found (a shared location regardless of the logged in user). Inside of that folder, create a "seleniumAutomationProfile" folder. Select this folder as the directory to store your new profile.
  8. Click “Finish”
  9. Select “Don’t ask at startup”
  10. Click “Start Firefox” and configure settings(below) based on suggestion below
  11. Set Profile back to “default” (enable you to use your previous settings on your browser)

Configure Settings (Optional)

  1. From “View\Toolbars” tab, uncheck “Bookmarks Toolbar”
  2. Right click from toolbar and click “Customize”
  3. Remove “Google search” by dragging it to the “Customize Toolbar” window
  4. From the “Customize Toolbar” window, click “Use Small Icons” check box then hit “Done”
  5. Click “Tools\Options” then set the following:
    1. “Main” tab
      1. set Home Page to “about:blank”
      2. uncheck “Show the Downloads..” option
    2. “Tabs” tab
      1. Select “a new window” for new pages
      2. Uncheck all warning options
    3. “Content” tab
      1. uncheck “Block pop-up” windows option
    4. “Privacy” tab
      1. uncheck all “History” options
    5. “Security” tab
      1. uncheck all “Security” options
      2. click “Settings” and uncheck all warning options
    6. “Advanced” tab
      1. Uncheck “autoscrolling” option from “General” tab
      2. uncheck “warn me …” and “Ssearch Engines”option from “Update” tab
    7. From “Tools\Add-ons” install the following:
      1. Firebug: allows you to edit, debug, and monitor CSS, HTML, and JavaScript on your application under test
      2. Selenium IDE: allows you to record, edit, and debug Selenium tests
      3. ScreenGrab: saves entire webpages as images.
    8. From the address bar type “about:config” and add the following by right-click anywhere on the page and selecting “new”
      1. extensions.update.notifyUser (type=boolean; value=false)
      2. extensions.newAddons (type=boolean; value=false)

Step-2 Handle Windows Authentication in firefox

Open firefox of above created profile

 

  1. Navigate to about:config (by typing in browser)
  2. Locate the following preference names and put as the value the comma separated values of the address roots.
  • network.automatic-ntlm-auth.trusted-uris
  • network.negotiate-auth.delegation-uris
  • network.negotiate-auth.trusted-uris
  1. Your value should look something like this: localhost,server1,server2,serverX
  2. Now, open firefox and navigate to the site – it doesn’t prompt for uid and pwd

Step -3 Start selenium servers from command line using the firefox profile created in Step – 1

Java –jar selenium-server.jar –firefoxProfileTemplate "profilepath"

Note, that the -firefoxProfileTemplate parameter needs to be before the -htmlSuite parameter. And, if you are running the scripts remotely on a Windows 7 machine, your profile should be located in the "roaming" folder of your windows path, like such (NOTE: Unless of course you heeded my recommendations in Step 1, bullet number 7 and created the profile folder in a shared location, avoiding romaing profiles altogether):

START java -jar S:\selenium-server-standalone-2.31.0.jar -port 4446 -firefoxProfileTemplate "C:\Users\lalbright3\AppData\Roaming\Mozilla\Firefox\Profiles\gz3hlbly.default" -htmlSuite "*firefox" "http://www.google.com" "S:\scripts\OnlineDirectory\suite-datatests.html" "S:\scripts\OnlineDirectory\results\result.html"

Now, when you run server it will start selenium with an instance of the profile you’ve selected. VERY IMPORTANT NOTE: Using this method, the selenium server first copies the profile you created to its own unique instance. That is important to note because when the copied instance of that profile run in Selenium RC, the browser will not have the profile name you created associated with it because it is a copied instance ... instead, it will say something like "customProfileDir123456" on its title bar. A quick way of knowing that you do in fact have the right profile running, is by adding the "ShowProfile" plugin to your source profile and no other profiles. Then when the source profile is copied and starts running in its own instance, the ShowProfile plugin will show you the new unique copied instance name of the profile ... and because its showing the profile name at all on the title bar means the ShowProfile plugin that you installed ONLY to the source profile is in fact the copied version.

For example, if your source profile was named "seleniumUser" and you stored that profile in the "../ffprofiles/seleniumAutomationProfile" folder, and you installed the "ShowProfile" addon to this profile, then when the selenium server runs it will copy the source profile directory to a temporary location, naming it something like "customProfileDir456009" (see screenshot below) ... which is what will show from the ShowProfile addon when the browser launches. Your default firefox profile, not having the ShowProfile addon installed, will not.

In addition, you are not yet done. If you need certain things to be configured for your test executions, modifying the temporary firefox profile when it runs will NOT do the trick. That's because each time Selenium runs up, it copies the original source profile and gives its tmeporary folder an entirely new naming convention ... and therefore anything you do to the temporary profile will NOT BE SAVED for future runs. Instead, you need to make a test run using the original source profile to make your configurations changes. Then, and only then will your changes be copied over to the temporary profile for all future test runs.

The way this feature was originally documented led me to believe that a temporary profile was not being created ... and instead, it was using the source profile. That is NOT the case. So remember to modify your source profile first so that Selenium copies those configurations to any temporary profiles its creates during runtime. I struggled with this forever. I think because somewhere along the line, this behavior changes without explanation. Hope this helps someone else.

 

Some additional references: