Integration Test
 with Cucumber and Webrat




     Kang-min Liu
   gugod@gugod.org
Integration Test

•
•
• Web App:
: twitter
: twitter

1.            http://twitter.com/home

2.     status

3.   update

4.
Webrat

visit "http://twitter.com/home"
fill_in "status", :with => "lorem ipsum"
click_button "update"

response.body.should =~ /lorem ipsum/
Webrat
Browser emulation / control
Webrat

•
•
•
•
Webrat


•   javascript

•   css
Webrat

•
    • Selenium
    • Watir
Webrat Core API
•   visit        •   select

•   click_link   •   attach_file

•   fill_in       •   click_button

•   check

•   uncheck

•   choose
Webrat Core API

• visit, click_link
 • get + assert_response :success
• click_button
 • submit form + assert_response :success
 • submit form default values if any
Webrat + RSpec
describe "tweeting" do
  it "should show my tweets" do
    visit "/home"
    fill_in "status", :with => "lorem ipsum"
    click_button "update"
    response.body.should =~ /lorem ipsum/
  end
end
?
Goods

•
•    HTML

•
Cucumber

• BDD (Behavior Driven Development) Tool
• Ruby implementation
•
•
Feature: Update my status
  In order to keep friends posted
  As a friendly person
  I post my status to twitter

  Scenario: Update my status
    Given I go to “/home”
    When I fill in “status” with “lorem ipsum”
    And I click “send”
    Then I should see “lorem ipsum”
Feature: Update my status
  In order to keep friends posted
  As a friendly person
  I post my status to twitter

  Scenario: Update my status
    Given I go to “/home”
    When I fill in “status” with “lorem ipsum”
    And I click “send”
    Then I should see “lorem ipsum”
Feature: Update my status
  In order to keep friends posted
  As a friendly person
  I post my status to twitter

  Scenario: Update my status
    Given I go to “/home”
    When I fill in “status” with “lorem ipsum”
    And I click “send”
    Then I should see “lorem ipsum”
Scenario: Update my status
   Given I go to “/home”
   When I fill in “status” with “lorem ipsum”
   And I click “send”
   Then I should see “lorem ipsum”

Given –
When –
Then –
Given /^I go to "(.*)"$/ do |url|
  visit url
end

When /^I fill in "(.*)" with "(.*)"$/ do |field,value|
  fill_in field, :with => value
end

When /^I click "(.*)"$/ do |link|
  click_link(link)
end

Then /^I should see "(.*)"$/ do |text|
  response.body.should =~ /#{text}/m
end
?
Goods...
•

•
    •
    •
Goods...


•
    •
Scenario: Update my status
  Given I go to “/home”
  When I fill in “status” with “lorem ipsum”
  And I click “send”
  Then I should see “lorem ipsum”
describe "tweeting" do
  it "should show my tweets" do
    visit "/home"
    fill_in "status", :with => "lorem ipsum"
    click_button "update"
    response.body.should =~ /lorem ipsum/
  end
end
Reference

• Cucumber http://cukes.info/
• Webrat http://github.com/brynary/webrat/
  tree/master
• Test::Cukes http://search.cpan.org/dist/Test-
  Cukes/ (Perl implementation)

Integration Test With Cucumber And Webrat

  • 1.
    Integration Test withCucumber and Webrat Kang-min Liu gugod@gugod.org
  • 2.
  • 3.
  • 7.
    : twitter 1. http://twitter.com/home 2. status 3. update 4.
  • 8.
    Webrat visit "http://twitter.com/home" fill_in "status",:with => "lorem ipsum" click_button "update" response.body.should =~ /lorem ipsum/
  • 9.
  • 10.
  • 11.
    Webrat • javascript • css
  • 12.
    Webrat • • Selenium • Watir
  • 13.
    Webrat Core API • visit • select • click_link • attach_file • fill_in • click_button • check • uncheck • choose
  • 14.
    Webrat Core API •visit, click_link • get + assert_response :success • click_button • submit form + assert_response :success • submit form default values if any
  • 15.
    Webrat + RSpec describe"tweeting" do it "should show my tweets" do visit "/home" fill_in "status", :with => "lorem ipsum" click_button "update" response.body.should =~ /lorem ipsum/ end end
  • 16.
  • 17.
  • 18.
    Cucumber • BDD (BehaviorDriven Development) Tool • Ruby implementation • •
  • 19.
    Feature: Update mystatus In order to keep friends posted As a friendly person I post my status to twitter Scenario: Update my status Given I go to “/home” When I fill in “status” with “lorem ipsum” And I click “send” Then I should see “lorem ipsum”
  • 20.
    Feature: Update mystatus In order to keep friends posted As a friendly person I post my status to twitter Scenario: Update my status Given I go to “/home” When I fill in “status” with “lorem ipsum” And I click “send” Then I should see “lorem ipsum”
  • 21.
    Feature: Update mystatus In order to keep friends posted As a friendly person I post my status to twitter Scenario: Update my status Given I go to “/home” When I fill in “status” with “lorem ipsum” And I click “send” Then I should see “lorem ipsum”
  • 22.
    Scenario: Update mystatus Given I go to “/home” When I fill in “status” with “lorem ipsum” And I click “send” Then I should see “lorem ipsum” Given – When – Then –
  • 23.
    Given /^I goto "(.*)"$/ do |url| visit url end When /^I fill in "(.*)" with "(.*)"$/ do |field,value| fill_in field, :with => value end When /^I click "(.*)"$/ do |link| click_link(link) end Then /^I should see "(.*)"$/ do |text| response.body.should =~ /#{text}/m end
  • 24.
  • 25.
  • 26.
  • 27.
    Scenario: Update mystatus Given I go to “/home” When I fill in “status” with “lorem ipsum” And I click “send” Then I should see “lorem ipsum”
  • 28.
    describe "tweeting" do it "should show my tweets" do visit "/home" fill_in "status", :with => "lorem ipsum" click_button "update" response.body.should =~ /lorem ipsum/ end end
  • 29.
    Reference • Cucumber http://cukes.info/ •Webrat http://github.com/brynary/webrat/ tree/master • Test::Cukes http://search.cpan.org/dist/Test- Cukes/ (Perl implementation)