Capybara Webkit Centos

23 Jun 2011 | By | Comments | Tags

layout: post title: Running Capybara-Webkit on CentOS author: Matt Robbins categories: - testing - cucumber - capybara - webkit —

Capybara-Webkit is a headless driver for Capybara that uses Qt-Webkit. Although it does not actually create a head (and therefore should be a great deal quicker than say running firefox via Xvfb) it still needs an X11 server running for access to fonts etc, Xvfb will do the job just fine.

Running this on CentOS is complicated by a number of factors:

  1. No official CentOS RPMs for Qt (or at least upto date ones)
  2. No official CentOS RMPs for Ruby 1.8.7
  3. Need to setup and run Xvfb.

The following guide should get you well on the way…

Pre-Requisites:

Install Xvfb

yum install Xvfb Xorg

Install Ruby 1.8.7 (as no CentOS RPM exists we must compile from source)

yum install -y gcc zlib zlib-devel  
wget http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p334.tar.gz  
tar xvf ruby-1.8.7-p330.tar.gz  
cd ruby-1.8.7-p330  
./configure --enable-pthread  
make  
make install

You may need to add the ruby executable to your path.

Install RubyGems 1.3.7

Download: rubygems-1.3.7.zip and unzip run setup.rb

Install Qt

Add the following repo using rpm:

rpm -ivh http://software.freivald.com/centos/software.freivald.com-1.0.0-1.noarch.rpm

Then:

yum groupinstall Qt4  
yum groupinstall Qt4-Devel

Add the qtmake binary to your path e.g.

export PATH=$PATH:/usr/lib64/qt4/bin

Testing your Xvfb setup

You can do this using Firefox…

yum install firefox

Start Xvfb:

Xvfb :1 -screen 0 1024x768x16 -nolisten inet6  (the no listen flag suppresses warnings related to no IPv6 support)
export DISPLAY=localhost:1.0 (exports the display)
DISPLAY=localhost:1.0 firefox (starts a headless firefox)

Using the headless gem

It is probably easiest to use the headless gem to manage your Xvfb server

For an example program using firefox and selenium-webdriver you could do something like the following:

require 'rubygems'
require 'bundler/setup'
require 'headless'
require 'selenium-webdriver'

headless = Headless.new
headless.start

driver = Selenium::WebDriver.for :firefox
driver.navigate.to 'http://google.com'
p driver.browser
puts driver.title

headless.destroy

Using Capybara-Webkit with Cucumber

Your env.rb could look something like this:

require 'capybara/cucumber'
require 'capybara-webkit'
require 'headless'

headless = Headless.new
headless.start

Capybara.javascript_driver = :webkit
Capybara.run_server = false

at_exit do
  headless.destroy
end

Welcome...

13 Jun 2011 | By Matt Robbins | Comments | Tags testing

Hi, welcome to ‘OpenSourceTester’, it’s a blog about testing software (primarily web apps) with free tools. I have started this blog for a few reasons:

  1. A place for me to record and cement my thoughts on anything which has proved really useful for me or which has given me significant grief!
  2. To hopefully share some of these issues (and the resolutions) in order inspire others or save them from going through the same pain…
  3. As a scratchpad for me to try out various things on a live site (so if this looks crap in IE6…sorry…).

Finally a bit about the technology behind this blog. Doubtless Wordpress, Tumblr et al are all superb blogging platforms and can produce sites which are significantly more attractive than this one. However in part this is a learning exercise for me so I finally settled on using Jekyll served up by Github Pages, which to name but a few has the advantages of free hosting and the ability to ‘git push’ posts created in your editor of choice…more about this in future posts I hope!

Anyway that’s more than enough for now, let’s see how things progress.

1 2 3