Posted 1 year ago
by albertoperdomo
Easy setup for your cucumber scenarios using the headless gem to run selenium on your CI server
At AENTOS we tend to avoid using selenium when writing cucumber features but we always end up writing some fancy scenarios that rely heavily on Javascript or AJAX calls and don’t work properly on the envjs or culerity capybara drivers. In the past we’ve setup a few CI environments to use the xvfb server, export displays before running the tests, etc. but I have to say it has always been quite a mess.
Recently I discovered Leonid Shevtsov had written a nice gem to wrap the xvfb stuff in Ruby: headless
This is an example on how to get your cucumber scenarios on selenium setup easily to run headlessly.
On your server:
- Install the headless gem: gem install headless
- Install the xvfb server: sudo apt-get install xvfb
- Install firefox: sudo apt-get install firefox
In your features/support/env.rb file add this code to start the xvfb server and export the display on start and shut it down when finished running the cucumber test suite.
We are using the environmet variable SELENIUM_HEADLESS so that it is only ran headlessly when we really want to. If you are working locally you don’t usually need this stuff, but it makes it really easy to run it on your CI server.
Just make sure to pass the environment variable when calling your rake task on your CI server, e.g:
HEADLESS_SELENIUM=true rake ci:run
Thumbs up to Leonid for writing this nice litlle gem that makes our lifes so much easier!

Notes