Gearing up cucumber and capybara for testing javascript.
Posted: January 28, 2012 Filed under: Uncategorized Leave a comment »With the explosion of rich internet applications, the usage of javascript is kind of becoming mandatory for all of the web applications these days. We at Dharana, work extensively on backbone.js which is a javascript MVC framework. While we worked on backbone.js, we also found that writing a tests for javascript can be extremely exciting and challenging. Being a cucumber and capybara fan boys, we looked at many solutions like selenium, celerity, culerity, envjs, akephalos browser simulators which supports javascript.
We found selenium to work well with our previous projects. But the problem with selenium is that, it is little heavy and most of all it simulates the entire browser on the GUI which makes it extremely slow. Thanks to thoughtbot for releasing the capybara-webkit. Capybara-webkit is just a rendering engine coupled with a DOM implementation and full javascript support. And it runs on a headless mode(no GUI). Here is why you should capybara-webkit,
1. Runs bloody fast.
2. Runs on a headless mode.
3. console.log support. You can see the javascript console.log outputs while running the tests from your console.
4. Uses webkit.
5. Setting up is super easy.
capybara-webkit depends on qtwebkit, make sure you have qtwebkit before you install capybara-webkit.
qtwebkit:
apt-get install libqt4-dev libqtwebkit-dev
Gemfile:
capybara-webkit
features/support/env:
Capybara.javascript_driver = :webkit
In my next post I will probably write about some useful tips which I learnt during writing javascript tests. Thanks.