Selenium RC Firefox 2 support on Ubuntu Hardy

Published Mon 26 May 2008 20:12 (+1200)

You may find after upgrading your Ubuntu boxes to Hardy Heron that Selenium RC stops working with Firefox, giving the following error:

java.lang.RuntimeException: Firefox couldn't be found in the path!
Please add the directory containing 'firefox-bin' to your PATH environment
variable, or explicitly specify a path to Firefox like this:
*firefox /blah/blah/firefox-bin

The problem is that by default Hardy uses Firefox 3. Firefox 3 support for Selenium RC is out of the scope of this page; the below assumes you want to test against Firefox 2, the current stable release.

First, you need to install the Firefox 2 package:

apt-get install firefox-2

If you don't want to use Firefox 3 on this box, you can remove it:

apt-get remove firefox-3

If you try and run Selenium RC now, you'll still get the same error we saw before – and yes, firefox-bin still isn't on our PATH.

The ‘firefox’ command is on the PATH, but it's not what Selenium RC is after – if you try linking that up as firefox-bin, you'll get:

java.lang.RuntimeException: File was a script file,
  not a real executable: /usr/local/bin/firefox-bin

Briefly, Selenium RC need to know the real binary so that it can pass in a bunch of custom options, and know what the real process is so that it can shut it down again at the end.

So, we need to find the real firefox-bin.

The odd thing is, if you check on a Feisty box, you'll find that firefox-bin isn't on the path there either.

After a lot of debugging I discovered that the Selenium RC developers have in fact hardcoded the old firefox-bin path for Ubuntu, as one of the special paths checked in addition to those actually on your PATH!:

private static final String DEFAULT_NONWINDOWS_LOCATIONS[] = {
    "/usr/lib/firefox/firefox-bin", // Ubuntu 7.04 default location

So at this point we can see what we have to do. With Hardy the Firefox 2 binary path in is now /usr/lib/firefox/firefox-2-bin.

Your first option is to explicitly give this full path to Selenium RC in the open call, as the original error suggested.

The second option is to make a link to this binary from somewhere on your PATH. But, if you try using say:

sudo ln -s /usr/lib/firefox/firefox-2-bin /usr/local/bin/firefox-bin

You'll just get:

firefox-bin: error while loading shared libraries: libmozjs.so: 
  cannot open shared object file: No such file or directory

The problem is that Firefox is built to use a number of .so shared libraries, and on Ubuntu these numerous libraries are installed not in /usr/lib itself, but the /usr/lib/firefox directory. When you run the Firefox binary in that directory, it looks for .so files there (in addition to the usual system paths); but if you run it from /usr/local/bin, it looks in /usr/local/bin, and there's nothing there.

So rather than linking up all the other resources that the binary needs, just put the firefox-bin link in /usr/lib/firefox, where it used to be on Feisty.


sudo apt-get install firefox-2
# optionally: sudo apt-get remove firefox-3.0
sudo ln -s /usr/lib/firefox/firefox-2-bin /usr/lib/firefox/firefox-bin

Selenium RC should then work with Firefox 2 ‘out of the box’ as it used to on Feisty.