Browser Automation – Tea-Driven Development https://blog.mattwynne.net Matt Wynne taking it one tea at a time Wed, 21 Aug 2019 12:55:30 +0000 en-US hourly 1 https://wordpress.org/?v=6.2 165828820 Using Capybara with RSpec Outside Cucumber https://blog.mattwynne.net/2010/12/01/using-capybara-with-rspec-outside-cucumber/ https://blog.mattwynne.net/2010/12/01/using-capybara-with-rspec-outside-cucumber/#comments Tue, 30 Nov 2010 23:18:32 +0000 http://blog.mattwynne.net/2010/12/01/using-capybara-with-rspec-outside-cucumber/ Continue reading "Using Capybara with RSpec Outside Cucumber"

]]>
If you want to try using Capybara for browser automation on it’s own, here’s a simple script to get you started:

require 'rubygems'

require 'capybara'
require 'capybara/dsl'

Capybara.default_driver = :selenium
Capybara.app_host = "http://www.google.com"

require "rspec/expectations"
class Google
  include Capybara
  include RSpec::Matchers

  def search_for(text)
    visit "/"
    fill_in "q", :with => text
    click_button "Search"
  end

  def ensure_results_contain(expected_text)
    page.should have_content(expected_text)
  end
end

google = Google.new
google.search_for("Matt Wynne")
google.ensure_results_contain("Tea")

To make this work you’ll need to install the capybara and rspec Ruby gems:

gem install capybara rspec
]]>
https://blog.mattwynne.net/2010/12/01/using-capybara-with-rspec-outside-cucumber/feed/ 2 272