..random notes of a tester..

Capybara Tutorial Using Irb

At one of my previous projects, a fellow ThoughtWorker named Rob Hunter showed me how to use irb (Interactive Ruby Shell) to play around with a test framework for web applications called Capybara. I’ve found it pretty useful so I figured I’d share it here.

To get started, make sure you have ruby installed. (Below I am using ruby version 1.9.2 and creating a gemset using RVM)

rvm use 1.9.2@cucumberplay --create

Install Capybara if you haven’t already.

gem install capybara

Launch irb with the following requirements (ruby, capybara, and capybara/dsl)

irb -r rubygems -r capybara -r capybara/dsl

Include Cabybara DSL:

include Capybara::DSL

Set the default driver.

Capybara.default_driver = :selenium

Now test that capybara commands work by visiting google

visit ""

Here’s an example for logging into GMAIL

visit ""
page.has_content?("A Google approach to email.")

fill_in 'Email', :with => ""
fill_in 'Passwd', :with => "johnjames4u"
click_button 'Sign in'