Selenium (RC) and Xvfb — Running Selenium (RC) on a (GUI-less) server

Note: This guide is tailored for CentOS/Red Hat distributions, so the startup scripts provided will not work on Debian-based systems.


Selenium is a testing-framework for web applications. The tester records their actions (e.g. mouse clicks, text-field entries, etc) using the Selenium IDE (a Firefox plugin), and can then later play them back. These recordings can also be used for regression testing, which is what this article primarily focuses on.


In my case, we were building a Django app and while we had unit tests, our client also wanted GUI testing. We had a (GUI-less/X-less) Linux server (CentOS 5.4), that hosted our SVN and we wanted to use this same server to run our Selenium tests. We didn’t want to install a complete X server, which is where Xvfb came in.


Installing Xvfb

Xvfb (X virtual frame buffer) is an X server that runs in memory (i.e. it does not require a physical display/mouse/keyboard). An X server is required for Firefox, which is required by Selenium to run its tests.

To install Xvfb:

yum install Xvfb

And to run Xvfb (listening to connections on :0), e.g.:

Xvfb :0 -screen 0 1024x768x24

You can then launch applications, by specifying their display on :0, e.g.:

DISPLAY=:0.0 firefox

Installing Firefox

The next step is to install Firefox, which Selenium RC will use to test your web pages.

yum install firefox

Installing Selenium

  1. Create a selenium-server directory
  2. Download Selenium RC – Remote Control
  3. Extract the selenium-rc archive

To the Selenium RC server:

  1. Navigate into the selenium-server-* directory (e.g. selenium-server-1.0.3 directory
  2. Run the selenium-server: java -jar selenium-server.jar

Example workflow

  1. Check code out from version control
  2. Code, code, code (code, test, code, test, code, test? 🙂
  3. Write Selenium tests using Selenium IDE. Note: It’s important to create your tests to the external URL of the pages (e.g. http://deployment/accounts/user, as opposed to
  4. Commit/check in code
  5. Your Continuous Integration server (e.g. Hudson) runs the unit tests and Selenium tests

Xvfb and Selenium Linux startup scripts

I have written CentOS/Red Hat (5.x) startup scripts for both Xvfb and Selenium. Both scripts need to be tweaked to fit your environment. All the parameters that you need to change are at the top of the scripts.