Reprocessed, by Matt Patterson

Something approaching a weblog

Snow Leopard, Firefox, and Selenium

I've got a longer post about setting up your Cucumber/Selenium environment coming, but since this is a hot issue I'd thought I'd address it. In short: There's a problem running the firefox.sh script on Mac OS X 10.6, which is the definitive way for things to invoke Firefox. Selenium RC runs firefox.sh to run tests, and Cucumber in turn uses Selenium RC. The result is that if you use Cucumber with Selenium and upgrade to 10.6, all your Selenium tests fail. The problem is detailed in Firefox's Bugzilla bug #513747 and Selenium's bug SRC-743. After a bit of poking about, I found a workaround. It's not great but it does get you going again...

The bug is that the Firefox runner script sets the environment variable DYLD_LIBRARY_PATH which causes Firefox's version of SQLite to override OS X's, which causes the crash. The solution is to get Selenium to invoke Firefox without setting that environment variable. You don't seem to be able to invoke the Firefox binary directly, because it crashes with the same error. I got it to work using a wrapper script:

#!/bin/sh

/Applications/Firefox.app/Contents/MacOS/firefox-bin $@
exit $?

Next, you need to tell Selenium to use your wrapper script. I use Cucumber (through Webrat) to define and run my Selenium tests, so this next bit is Webrat-specific.

In your Webrat configuration (usually features/support/env.rb with Cucumber) in your Webrat.configure block you need something like:

Webrat.configure do |config|
  config.mode = :selenium
  config.open_error_files = false # Set to true if you want error pages to pop up in the browser
  browser_key = "*chrome"

  # special browser script iff we're running on Snow Leopard
  browser_key = "*chrome ./script/selenium-firefox" unless (`uname -a` =~ /Darwin Kernel Version 10/).nil?

  config.selenium_browser_key = browser_key
end

I use a test on the result from uname to figure out if we're on Snow Leopard. There may well be a better way to do that which doesn't involve shelling out. That's it - Firefox and Selenium should now successfully collaborate again.

The only caveat is that, for me at least, the Firefox instance spawned by Selenium doesn't quit after a test run. This makes it pretty tricky for use in an unattended environment (like on a Continuous Integration box). I'm keeping my CI box on 10.5 until this is properly resolved.

Not forgetting:

This page is: