Running Selenium on headless Ubuntu 11.04 (like Ubuntu Server) with Xvfb

How to set up Selenium Server to run headless on a Ubuntu 11.04 machine with the use of Xvfb.

Download the Selenium Server

wget http://selenium.googlecode.com/files/selenium-server-standalone-2.4.0.jar

Enable partner repository in /etc/apt/sources.list:

sudo nano /etc/apt/sources.list
# (Edit the file)

In Ubuntu 11.04 the partner repository line reads:

deb http://archive.canonical.com/ubuntu natty partner
deb-src http://archive.canonical.com/ubuntu natty partner

Update the package manager, upgrade any upgradable packages and install Java, Firefox and Xvfb

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install sun-java6-jre firefox xvfb

Install Firefox 3.6

wget -O firefox-3.6.20.tar.bz2 http://download.mozilla.org/?product=firefox-3.6.20&os=linux&lang=en-GB
tar xvjf firefox-3.6.20.tar.bz2
sudo mv firefox /firefox
sudo mv /usr/bin/firefox /usr/bin/firefox-ubunturepo
sudo ln -s /firefox/firefox /usr/bin/firefox
firefox -v
# Output: Mozilla Firefox 3.6.20, Copyright (c) 1998 - 2011 mozilla.org

Start Xvfb on display 15 with a resolution of 1024×768. Let the Selenium server know what display to use and start it.

/usr/bin/Xvfb :15 -ac -screen 0 1024x768x8 &
export DISPLAY=localhost:15.0
/usr/bin/java -jar selenium-server-standalone-2.4.0.jar

See also article about automatically starting a headless Selenium server.

Sources:

Dette innlegget ble publisert i Selenium og merket med , , , , , , . Bokmerk permalenken.