Windows Capybara Setup

When our managers decided to use Calaba.sh for our Android/iOS UI Automation, they really chose to use Cucumber for the Android/iOS and Web products. This just happened to mean Calaba.sh and Capybara. The theory behind this is that Cucumber’s syntax is all nice and pretty, easy to understand because it uses natural language. However, Cucumber has to have ‘step definitions’ written in Ruby for everything written in Cucumber.

Cucumber is basically just a wrapper around a Ruby framework. The way it works is Cucumber uses this syntax called Gerkin to write tests in natural language. Gerkin’s syntax makes tests look like this (example from Calaba.sh’s website)

Cucumber takes this Gerkin syntax and looks at all of your step definitions which are written in ruby to determine how to actually perform each step. If the whole test runs without any problems, the test passes, otherwise it fails. This means that in order for Cucumber to work, you have to have a Ruby framework to support Cucumber. In Android/iOS, this framework is Calaba.sh. For web development, the framework I like is Capybara.

Capybara is a wrapper around a web driver. This wrapper allows common api regardless of which web driver you’re using. More importantly, it lets you write your tests synchronously instead of having to take account of the asynchronous nature of the web with wait statements in your tests.

After a lot of experimenting with the Capybara/Cucumber combination, I eventually realized that Cucumber just isn’t worth the work. Capybara with RSpec is easier and faster to write. Using Cucumber to write the tests is of no benefit. Because you have to use Capybara to write your step definitions, there is no transferrable knowledge between the Android/iOS tests and the Web tests. One of the main benefits to Cucumber was supposed to be sharing knowledge between the products, but since that isn’t the case, my personal opinion is just use Capybara with Rspec and ask for forgiveness if the need arises (though I don’t think it will)

To get things set up in Windows, first thing you need to do is install Ruby and the Ruby DevKit.

  • Head over to rubyinstaller.org and download Ruby 2.0.0
    • make sure to get the x86 version not the 64x version. I haven’t tried to use the x64 version and their website recommends not using it because many gems aren’t compatible with 64x.
  • Install Ruby. Make sure you check the box for putting it in your path.
  • Download the DevKit (also from rubyinstaller.org)
  • Unzip the DevKit where you want it installed (permanent location)
    • I put mine in C:\Ruby200\DevKit, but I’ve read that you can unzip it into your Ruby install directory instead of into it’s own folder
  • Open cmd.exe and cd to your Ruby install directory
  • execute ruby dk.rb init
  • check the config.yaml file to ensure it is correct
  • execute ruby dk.rb install
  • Make sure that the DevKit’s bin folder is in your path

Now that you have Ruby and the DevKit installed, the steps are the same whether you’re in Windows or OS X.

Install Firefox. Selenium’s Webdriver uses Firefox by default.

Install the following gems

My computer at work is on a network with our own root CA, and the gem command didn’t seem to like that, so in the .gemrc I put in the line :ssl_verify_mode: 0. Note: I used gVim to create my .gemrc because Windows throws a fit when you try to name a file starting with a ‘.’ but gVim or a wide array of Unix tools can do it just fine (sill Windows).

Once all of the gems are installed, you now have everything you need to get started. Head over to my post on getting into interactive mode to learn how to start Capybara in interactive mode.

Leave a Comment

Your email address will not be published. Required fields are marked *