Our tests are done mainly using Cucumber. We believe in Cucumber, because we can test the whole stack of the application: JavaScript logic, view logic, controller, model and database all in one take. You may disagree with this, but that is not the point of this article.
We have set up the Cucumber tests to work with Capybara. When invoking Cucumber, a browser window opens and it’s like someone is clicking and inserting things on the page much like a user would do (I call it “Browser-TV”). We wanted to be able to use continuous integration with Jenkins and still be able to test all the Cucumber tests. The Jenkins Server is headless, meaning that there is no X Server running on the machine that could open the browser and click around on the page.
We’re also using RVM in our project and it took a little time to set that up on the Jenkins Server as well.
Installing Jenkins (Ubuntu 10.04 Server)
To begin with, we had our normal development environment setup on the server (databases and everything) before we started to put Jenkins on top. This way we made sure that the databases were working. The machines runs Ubuntu 10.04 Server edition, the setup of Jenkins was really straight forward:
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list' sudo aptitude update sudo aptitude install jenkins
Installing RVM
After that go ahead and login to your server and become the Jenkins user. Within the shell, just install a default RVM installation as described on the RVM page. There seem to be a couple of options out there for integrating RVM with Jenkins, but none of them really worked smoothly for me. Since I’m a command line guy, I hit it off like this in Jenkins:

It is a bit ugly to read, but that really doesn’t matter to me, it simply works.
Getting the Cucumber tests to pass
In order to test the Cucumber features that rely on the browser to be opened, you first have to install a virtual framebuffer X-Server and of course the browser that you are testing in (in our case Firefox):
sudo apt-get install firefox xvfb
Test if you can start the Xvfb Server:
Xvfb :99 -ac -screen 0 1024x768x16 export DISPLAY=:99 firefox
If everything goes well and Firefox doesn’t complain, then your Xvfb setup is working. Next it’s a good idea to make a start- and stop-script for Xvfb and place it into /etc/init.d/xvfb:
XVFB=/usr/bin/Xvfb
XVFBARGS=":99.0 -ac -screen 0 1024x768x16"
PIDFILE=~/xvfb.pid
case "$1" in
start)
echo -n "Starting virtual X frame buffer: Xvfb"
/sbin/start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile
--background --exec $XVFB -- $XVFBARGS
echo "."
;;
stop)
echo -n "Stopping virtual X frame buffer: Xvfb"
/sbin/start-stop-daemon --stop --quiet --pidfile $PIDFILE
echo "."
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/xvfb {start|stop|restart}"
exit 1
esac
exit 0
Make that script executable for everyone. Now you are pretty much ready to add three tasks to your Jenkins build:
The three steps are: starting the Xvfb server, executing your Cucumber tests and passing along the display variable and lastly stopping the Xvfb server again.
And there you have it! Your headless Capybara-Cucumber tests dones by Jenkins.



