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.
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.:
The next step is to install Firefox, which Selenium RC will use to test your web pages.
yum install firefox
- Create a selenium-server directory
- Download Selenium RC – Remote Control
- Extract the selenium-rc archive
To the Selenium RC server:
- Navigate into the selenium-server-* directory (e.g. selenium-server-1.0.3 directory
- Run the selenium-server: java -jar selenium-server.jar
- Check code out from version control
- Code, code, code (code, test, code, test, code, test? 🙂
- 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 http://192.168.1.15/accounts/user).
- Commit/check in code
- 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.