Selenium requires launching a browser on whatever machine is running the tests. Having a display connected to every machine you wish to run Selenium tests on is incredibly cumbersome. To get around this, you can do headless Selenium testing using a program called Xvfb which is a display server implementing the X11 display server protocol. I realize that there is a Xvfb plugin for Jenkins. However, I’ve experimented with it and found it wasn’t completely stable.
First we install Xvfb:
1 |
sudo yum install xvfb |
I made a previous post about installing a command line tool as a Linux service, so you could go that route. But if you’d prefer to just use it on the fly then you could do the following:
Add an init.d file to start Xvfb on a particular display variable, in this case 99:
1 |
sudo vi /etc/init.d/xvfb |
Add the following to the xvfb file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#!/bin/bash if [ -z "$1" ]; then echo "`basename $0` {start|stop}" exit fi case "$1" in start) /usr/bin/Xvfb :99 -ac -screen 0 1024x768x8 & ;; stop) killall Xvfb ;; esac |
Then change the permissions on the script and see if it works!
1 2 |
sudo chmod 755 /etc/init.d/xvfb /etc/init.d/xvfb start |
Then in the Manage Jenkins menu, we add an environment variable DISPLAY with it’s value set to :99 in the Jenkins system configurations. I believe by default these variables are inherited by every Jenkins project unless you choose otherwise. If you wish, you can also add ‘/etc/init.d/xvfb start’ to /etc/rc.d/rc.local in order to have it start a server on DISPLAY=:99 every time the machine is rebooted.