Capybara/Webkit: Running Integration Test

Reading Time: < 1 minute

Have you ever had a big Ruby app where your tests are too complex with all those strong>@javascript tagst that testing takes like.... forever? Then, you should try Capybara/Webkit, a library that provides a webkit-powered driver for your integration tests using the webkit implementation in Qt.

The first step to get this done is to install the Qt libraires.

You can use this command if you are using Linux

sudo apt-get install libqt4-dev

Or this other one if you are using Mac OS

brew install qt

It might take a while, so... you may want to get a cup of coffee.

After that cup of coffee, if you are running under Linux platforms, capybara-webkit requires an X server to run, although it doesn't create any visible windows. Xvfb works fine for this you can install it by typing

sudo apt-get install xvfb

To finish with the installation add the following to your app Gemfile then run bundle.

gem 'capybara-webkit'

Once everything is installed you can set Capybara's Javascript driver to use webkit by default, to do this just open your /features/support/env.rb and add the following line:

Capybara.javascript_driver = :webkit

And that's it. If you are using linux as I am, use this command to run your tests

xvfb-run bundle exec cucumber

and if you are a Mac user just run your tests normally with

bundle exec cucumber

as your tests begin to run you will notice that the Firefox window won't open and all your strong>@javascript tagged scenarios will run in the "background".

Conclusions

You'll be able to notice a speed increase running the tests with capybara-webkit instead of Selenium.

So, these are my results:

Running with selenium & firefox

6 scenarios (6 passed)
21 steps (21 passed)
0m22.937s

Running with capybara & webkit

6 scenarios (6 passed)
21 steps (21 passed)
0m16.759s

As you can see, the app I'm testing is quite simple with only 21 steps, nevertheless you can see there is a 6 seconds difference between tests.

6 seconds may not be a huge difference right now, but, as your project starts growing and growing you will notice the difference in speed when running your tests.

You can check these references for more info.

Know more about us!

0 Shares:
You May Also Like
Read More

Lambda In ActiveRecord

Reading Time: 2 minutes On one occasion, I had a problem with a couple of ActiveRecord scopes. The problem showed up when…
Read More

Data Encryption with Rails 7

Reading Time: 4 minutes There are massive amounts of sensitive information managed and stored online in the cloud or connected servers. Encryption…