Firefox user preferences with selenium (behat+mink) to bypass a proxy or disable cache

At work we are testing an existing application with behat+mink. We normally use goutte driver, but in some cases (when javascript is needed) we need to use selenium server piloting firefox.

When using firefox, the page is loaded including external javascript (google analytics, network ads etc..) so it needs connetivity. An alternative is disabling external requests on the testing environment or use a fake DNS entry, but that wasn’t a viable solution for us.

A small problem I had was bypassing the office network proxy, that requires a proxy auto config file (PAC) when firefox was running. You can find many links online mentioning the various firefox preferences you can set, for example network.proxy.http and network.proxy.http_port to specify a proxy, or network.http.use-cache to enable/disable the browser cache.

In my configuration (ubuntu 12.04, with selenium 2.28, firefox 18.0.1), the preferences file read by firefox is located at /usr/lib/firefox/defaults/pref/proxy.js, where you can add the various calls to user_pref([settings], [value]) .

Here an example of how I changed the puppet manifest of the box to make things working for us

file { "/usr/lib/firefox/defaults/pref/proxy.js":
 content =>
'user_pref("network.proxy.autoconfig_url", "http://chante-with-your-value/default.pac");
user_pref("network.http.use-cache", false);
user_pref("network.dnsCacheExpiration", 1);
user_pref("network.proxy.type", 2);'
}