Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Cucumber and Capybara

rtyler edited this page May 13, 2012 · 11 revisions

Introduction

Cucumber is a behavior-driven development framework that, when coupled with Capybara, provides a very good foundation for writing acceptance tests that use Sauce Labs.

In order to use the Sauce gem's Cucumber+Capybara support, add the following to your features/support/env.rb

require 'sauce/capybara'
require 'sauce/capybara/cucumber'

The integration is enabled by way of the @selenium tag in Cucumber. For example's sake, let's write a quick Feature for some of DuckDuckGo's !bang syntax

@selenium @ddg
Feature: Search for Ruby gems with !rubygems
  As a Ruby developer
  In order to quickly find fancy gems
  The '!rubygems <gemname>` query should take me directly to fancy gems

  Scenario: Finding the Sauce gem
    Given I am on the DDG homepage
    When I search for "!rubygems sauce"
    Then I should see an match on the Ruby Gems search page

In the above example, the Sauce gem will handle wrapping the entire "Finding the Sauce gem" scenario with the necessary hooks to install a custom Capybara driver and report the necessary job information to Sauce Labs.

For completeness' sake, here are some matching step definitions for the above scenario

Given /^I am on the DDG homepage$/ do
  visit 'http://duckduckgo.com'
end

When /^I search for "([^"]*)"$/ |query|
  @query = query
  fill_in 'q', :with => query
end

Then /^I should see an exact match on the Ruby Gems search page$/ do
  gem_name = @query.split(' ').last
  page.should have_selector("a[href='/gems/#{gem_name}']")
end
Clone this wiki locally