Category Archives: ubuntu / debian / linux

Using hudson to run selenium tests

Having a maven project with a selenium test and a Hudson continuous integration server, it would be nice to be able to combine the two.

However, the hudson is running on a headless Ubuntu server, so Selenium won’t start.

The trick is to install xorg and xvfb and firefox
sudo apt-get install xorg xvfb firefox

This also needs to be started, creating a virtual screen. This can be done by including the following lines in the startup script for your hudson or application server (tomcat in my case):

export DISPLAY=:7
Xvfb :7 -ac -screen 0 1024x768x8 &

No you need to verify that this works. With your application server running (as this now started xvfb) try starting firefox (you will probably have to set the DISPLAY variable again first). If this immediately returns, then starting xvfb failed. If it doesn’t return, you can check whether it is displayed properly. Run the following command from a different console.

xwd -root -display :7.0 -out xwdout

This will take a snapshot of the screen (with the running firefox hopefully). If you transfer this file to another computer (with screen), you can check the contents using:

xwud -in xwdout

If that all works, and your maven build works on your system, then it should also work in Hudson.

It should, but in my case it didn’t. Try running you maven build outside Hudson first. It that works, you are probably running Hudson as root. You need to add the HOME environment variable in your Hudson settings, pointing that to /root to make sure Selenium can find your firefox profile.