From the archive. This was written in 2012 and is kept here unchanged. Some of it has aged better than the rest. It originally lived at /blog/2012/02/25/capybara-on-the-command-line-live-browser-testing-from-irb/.

Everyone knows retro fitting tests is not the best way to go, but you can’t escape the fact that sometimes it’s unavoidable. Writing integration tests after the fact can sometimes be tricky, especially when dealing with complex xpaths or trying to assert against deeply buried elements. So if you’re as tired of digging around in web inspector as I am, try this instead:

gem install capybara

And then fire up console:

require 'capybara/dsl'
=> true
include Capybara::DSL
=> Object
Capybara.default_driver = :selenium
=> :selenium
visit "http://google.co.uk"
=> ""

Capybara driving a live Firefox window from an IRB session

Watch and smile as Firefox opens, and then access anything on it with page

page.fill_in('q', :with => 'capybara')
=> ""
page.click_link "jnicklas/capybara - GitHub"
=> "ok"

And by getting instant feedback in this way, those steps will write themselves.