Capybara1

731 views
637 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
731
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Capybara1

  1. 1. AMIR BARYLKO INTRO TO CAPYBARA RUBY UG NOV 2010Amir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  2. 2. WHO AM I? • Architect • Developer • Mentor • Great cook • The one who’s entertaining you for the next hour!Amir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  3. 3. BDDAmir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  4. 4. WHY TRADITIONAL PROJECTS FAIL? • Delivering late or over budget • Delivering the wrong thing • Unstable in production • Costly to maintainAmir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  5. 5. BDD PRINCIPLES • Behaviour Driven development is about implementing an application by describing its behaviour from the perspective of the stakeholder • Enough is Enough • Deliver stakeholder value • It’s all behaviourAmir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  6. 6. OUTSIDE IN APPROACHAmir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  7. 7. GHERKIN DSL • Business readable DSL • Flush out requirements • Documentation • Automated testing • Used by Cucumber, SpecFlow, jBehaveAmir Barylko - BDD MavenThought Inc.Thursday, November 25, 2010
  8. 8. CUCUMBERAmir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  9. 9. FEATURES Feature: Listing projects As a user I Want to see the list of projects So I can choose one to see the details Scenario: List all projects Given Im logged in And I have the projects: | Caruso | | Pucini | | Mariachi | When I go to the projects page Then I should see "Caruso" And I should see "Pucini" And I should see "Mariachi"Amir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  10. 10. STEPS Given /^I have the projects:$/ do |table| projects = table.raw.collect do |project| {"id" => 4444, "name" => "#{project}", "description" => "Project developed in rails", "createTime" => "/Date(1256774726000-0500)/", "owner" => {"id" => 2222,"name" => "Some user"}} end fake_response = JSON.generate({"page" => 1,"pageSize" => 10,"totalPages" => 1,"totalItems" => 1, "items" => projects}) FakeWeb.register_uri(:get, "http://agilezen.com/api/v1/projects", :body => fake_response) FakeWeb.register_uri(:get, "http://agilezen.com/api/v1/project/4444", :body => JSON.generate(projects[0])) endAmir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  11. 11. CAPYBARAAmir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  12. 12. WHAT • Gem to simplify integration tests • Inspired by Webrat • Can be used with Cucumber steps or in any other test • Easy to install: gem install capybaraAmir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  13. 13. WHY • Support for different web browsers • Provides driver to run headless (without browser) • Can combine different scenarios with different browsers • Supports Rack and any remote web application • Supports asynchronous callsAmir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  14. 14. FORMS • click_link(...) • check(...) • click_button(...) • uncheck(...) • click_link_or_button(...) • attach_file(...) • choose(...) • select_option(...) • fill_in(“FirstName”, :with => “John”)Amir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  15. 15. FINDERS • all(*args) • find_button • page.all(:css, ‘a#user’) • find_by_id • page.all(:xpath, ‘//[@id=user]’) • find (same args as all) • find_field • find_linkAmir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  16. 16. MATCHERS • has_selector? • has_no_selector? • has_content? • has_no_contentAmir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  17. 17. STEPS • Given I am on Home • When I go to Projects • When I press “login” within “user” • When I follow “help” within “support”Amir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  18. 18. STEPS II • When I fill “username” with “mel” • When I select “Winnipeg” from “cities” • When I check “remember_me” • When I uncheck “remember_me” • When I choose “Option” • When I attach then file “settings.xml” to “file”Amir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  19. 19. STEPS III • Then I should see “Welcome” • Then I should not see “Welcome” • Then the field “user” should contain “Mel” • Then show me the pageAmir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  20. 20. XPATH • Then I should see “Welcome” • Then I should not see “Welcome” • Then the field “user” should contain “Mel” • Then show me the pageAmir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  21. 21. QUESTIONS?Amir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  22. 22. RESOURCES • Contact me: amir@barylko.com, @abarylko • Materials: http://www.orthocoders.com/presentationsAmir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010
  23. 23. RESOURCES II • Capybara: https://github.com/jnicklas/capybara • Cucumber: https://github.com/aslakhellesoy/cucumber/wiki/ • Culerity: https://github.com/langalex/culerity • Celerity: http://celerity.rubyforge.org/ • Selenium: http://seleniumhq.org/Amir Barylko - Capybara MavenThought Inc.Thursday, November 25, 2010

×