Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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.shou...
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...
Webrat Core API

• visit, click_link
 • get + assert_response :success
• click_button
 • submit form + assert_response :su...
Webrat + RSpec
describe "tweeting" do
  it "should show my tweets" do
    visit "/home"
    fill_in "status", :with => "lo...
?
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

  Scenar...
Feature: Update my status
  In order to keep friends posted
  As a friendly person
  I post my status to twitter

  Scenar...
Feature: Update my status
  In order to keep friends posted
  As a friendly person
  I post my status to twitter

  Scenar...
Scenario: Update my status
   Given I go to “/home”
   When I fill in “status” with “lorem ipsum”
   And I click “send”
  ...
Given /^I go to "(.*)"$/ do |url|
  visit url
end

When /^I fill in "(.*)" with "(.*)"$/ do |field,value|
  fill_in field,...
?
Goods...
•

•
    •
    •
Goods...


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

• Cucumber http://cukes.info/
• Webrat http://github.com/brynary/webrat/
  tree/master
• Test::Cukes http://sea...
Integration Test With Cucumber And Webrat
Integration Test With Cucumber And Webrat
Integration Test With Cucumber And Webrat
Upcoming SlideShare
Loading in …5
×

Integration Test With Cucumber And Webrat

5,993 views

Published on

my talk about cucumber and webrat on ruby tuesday

Published in: Self Improvement
  • Be the first to comment

Integration Test With Cucumber And Webrat

  1. 1. Integration Test with Cucumber and Webrat Kang-min Liu gugod@gugod.org
  2. 2. Integration Test • • • Web App:
  3. 3. : twitter
  4. 4. : twitter 1. http://twitter.com/home 2. status 3. update 4.
  5. 5. Webrat visit "http://twitter.com/home" fill_in "status", :with => "lorem ipsum" click_button "update" response.body.should =~ /lorem ipsum/
  6. 6. Webrat Browser emulation / control
  7. 7. Webrat • • • •
  8. 8. Webrat • javascript • css
  9. 9. Webrat • • Selenium • Watir
  10. 10. Webrat Core API • visit • select • click_link • attach_file • fill_in • click_button • check • uncheck • choose
  11. 11. Webrat Core API • visit, click_link • get + assert_response :success • click_button • submit form + assert_response :success • submit form default values if any
  12. 12. 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
  13. 13. ?
  14. 14. Goods • • HTML •
  15. 15. Cucumber • BDD (Behavior Driven Development) Tool • Ruby implementation • •
  16. 16. 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”
  17. 17. 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”
  18. 18. 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”
  19. 19. 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 –
  20. 20. 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
  21. 21. ?
  22. 22. Goods... • • • •
  23. 23. Goods... • •
  24. 24. 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”
  25. 25. 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
  26. 26. Reference • Cucumber http://cukes.info/ • Webrat http://github.com/brynary/webrat/ tree/master • Test::Cukes http://search.cpan.org/dist/Test- Cukes/ (Perl implementation)

×