Firefox Profile Settings

There are often times when you would want to modify browser preferences to suit your needs. Some preferences are relatively easy to guess and modify as you might have done many a time. This post specifically talks about Firefox. Manually you can open up Firefox preferences dialog and you have a bunch of options as below (Alt+F -> Tools -> Options when firefox is open):

Firefox_pref_manual

Case:

Each of the preference we set on this above window in turn has a configuration parameter in the browser’s engine, that gets set / modified when we make changes on this dialog window. As part of Continuous Test Automation, we will need to programmatically be able to modify and change these preferences. To take a look at the meta-preferences, type “about:config” in the Firefox browser’s URL, hit enter and click “I’ll be careful, I promise”. In my case, I am using FF 33.1 and I have typed “browser.startup” at the top of the window below. Feel free to look at the ton of preferences we have there.

firefox_about_config

firefox_about_config_opened

 

Do I have to worry about so many?

Thankfully no ! It would be excruciating to remember so many preferences and let alone modifying or changing them. The reason we have to give this context is so that you know that we can modify preferences and who knows you might need to modify a preference that many of us might not need, so you can always come back here and revisit the basics.

Preferences that matter:

I found the following preferences helpful so far.

  1. The first one is for setting the browser’s home page,
  2. the second one is to bypass the ssl cert issue that appears and
  3. The third is to set the basic HTTP proxy settings in your browser (the pop up that will ask your single sign on)
  4. The fourth one is for automating responsive web design apps by simulating a user agent.

Network Proxy Setting:

There is yet another way to set the network proxy in firefox profile if the above Selenium WebDriver proxy doesn’t work. Feel free to use whichever applies to your company or Firewall settings

Automatically download without file dialog

When we download files, we get a file dialog box that asks us to save/open. It looks as below on windows. Since this dialog is NOT a browser pop up or javascript pop up, it is NOT possible to interact with this dialog using Selenium. There are some solutions like AutoIt, however we would have to learn yet another library kind of situation, so a simple way in firefox is to set profile settings that automatically downloads the file to a ‘specified’ folder. And we can do this programmatically meaning, we need NOT set the configuration manually. And that way, the setting is effective only during the execution of script. Let’s see how to do this.

file_download_firefox

 

Specify the mime-type

Identifying the mime-type [as recognized by firefox] can be tricky, however below steps will help us.

  1. Manually download the file using firefox [lets say you download a zip file] and save it. At this point, firefox would identify the mime-type and store it in its profile
  2. Go to firefox profile folder on your machine and open the file “mimeTypes.rdf” [Below is a screeshot]
  3. Identify the mime type be reading the line “NC:value=” and put the value. For example I downloaded the .zip file and its value is “application/x-zip-compressed” 

mime-type_zip

A couple of mime-types that might be helpful are below. If you like to read more on Mime Types for firefox, here is an article.

  • PDF: application/pdf
  • ZIP: application/x-zip-compressed
  • CSV: text/csv
  • IMAGE: image/png
  • Plain Text: text/plain
  • Html: text/html

Example Cucumber Scenarios:

Step Definitions:

 

Closing Thoughts:

There are some other ways to download an online file, however that would be more code and using other supporting libraries. Download online file