6 Jul 2011

Run Cucumber with Selenium RC and a custom Firefox profile

Proxy, proxy, proxy ... My head is spinning and it took me quite a while to figure out how to get Firefox and Selenium working behind a proxy. Guess what, it's quite simple.

Global environment configuration

First i tried the unix environment variable http_proxy and no_proxy but it seems Firefox doesn't respect those (Issue, Addon).

Use a firefox profile

Second i tried to create a Firefox profile with the correct proxy settings and started Selenium RC with the parameter "webdriver.firefox.profile" and the name of the created profile. The problem here is that the Selenium Webdriver for Ruby always creates an anonymous profile for Firefox.

I've created an issue for that.

The workaround

At the moment Selenium RC and the tests for our Ruby on Rails project are running on the same machine and the Selenium configuration for Capybara is flexible enough to apply a workaround for our problem.

Open features/support/env.rb in your Ruby on Rails project and add the following:

This snippet will configure Capybara based on the Firefox profile "default" but you could use any profile you want. The environment variable SELENIUM_REMOTE ensures that this configuration will not apply for any of your team members.

You can enable the configuration by running cucumber like this: SELENIUM_REMOTE=1 bundle exec cucumber