I was determined to get our CI server running cucumber features in headless mode. I ran into a few webdriver problems which resulting in a small monkey patch (capybara patch being written and submitted) for capybara. This is how I got it running on a fedora 12 server (and some tips on getting it working on an ubuntu server).
sudo yum install xorg-x11-server-Xvfb
sudo apt-get install xvfb
To run Xvfb, in console simply type, then set a environment variable to bind all X requests from the command line to go to the new virtual deskspace
Xvfb -ac :99
This will launch a new virtual display bound to display 99.
Install X11VNC to see whats happening!!
This is very cool. You can actually set up a vnc server and bind it to the virtual display to see what is happening!!! On Fedora
sudo yum install x11vnc
sudo apt-get install x11vnc>
Simple run the following command! And point your VNC client to the installation server!
x11vnc -display :99
Test it by going to the command line and typing something like
Install the hudson gem The hudson gem is in the gems repo, but for docmentation go http://github.com/cowboyd/hudson.rb. I generally do this as the user “hudson”.
gem install term-ansicolor
gem install yajl-ruby
gem install httparty -v=0.5.2
gem install builder -v=2.1.2
gem install thor -v=0.13.6
gem install hpricot
gem install hudson --pre
On the command line just type
this will install hudson, and save configuration to the ~/.hudson directory
Checkout your application to this box
First thing is to ensure you have set up a git user and email in the global config
git config --global user.name "hudson"
git config --global user.email "email@example.com"
Then clone your app down, install all associated gems and create your testing database
git clone firstname.lastname@example.org:username/mygitrepo.git
RAILS_ENV=test rake db:schema:load
Test cucumber/webdriver runs
cucumber in your apps directory
Create a new Hudson Project
Thanks to the hudson gem, you can set up the inital project skeleton via the command line (isn’t technology great) Here we can use the hudson create command and tell hudson to use the current directory, and that hudson is installed on localhost:3001
hudson create . --host localhost --port 3001
Set up the hudson project
Log into the project, if its on your local computer, point your browser to http://localhost:3001 and click on your project, also skip this next section. If you’re installing hudson on a remote server you’ll need to ssh port forward since hudson at this point is only listening on localhost.
ssh -L 8123:localhost:3001 email@example.com
Then open a browser and point it to http://localhost:8123 and click on your project
Set up the build
- Remove all defined build sets.
- Add a new build step “Execute Shell” with the command “cp config/database.tests.yml config/database.yml”
- Add a new build step “Exceute Shell” with the command “RAILS_ENV=test rake gems:install”
- Add a new build step “Execute Shell” with the command “RAILS_ENV=test rake db:migrate”
- Add a new build step “Execute shell” with the command “spec spec” # if you have specs
- Add a new build step “Execute shell” with the command “DISPLAY=:99 cucumber” # with cucumber
Press the save button.
If webdriver doesn’t append to your virtual display
If webdriver doesn’t append to your Xvfb then you can put this script in /features/support/capybara_webdriver_patch.rb
# Added profile support for capybara, so we can run our tests in headless mode
class Capybara::Driver::Selenium < Capybara::Driver::Base
profile = Selenium::WebDriver::Firefox::Profile.new
profile.load_no_focus_lib = false
@driver = Selenium::WebDriver.for :firefox, :profile => profile
Some after thoughts
Some extras you should set up before you think your finished. They’re outside of the scope of this document but there are plenty of docs out there on the interwebs who can give you all the information you need to rock and roll.
- At the moment its open to everyone, go to global configuration and set up ACL’s
- Your builds aren’t very continuous yet, you can schedule builds periodically by going into the project configuration area, or I believe you can tie it into githubs callback mechanisms
Alister Scott: There is a ‘headless’ gem that does all the xvfb stuff for you. Also, there is a Jenkins rake plugin which can execute rake for you automatically. See this blog post of mine for further info: http://watirmelon.com/2011/08/29/running-your-watir-webdriver-tests-in-the-cloud-for-free/