Your SlideShare is downloading. ×
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply



Published on

Presentation done at Devteach/RubyTeach 2012

Presentation done at Devteach/RubyTeach 2012

Published in: Technology, Education

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. Intro to Capybara Amir Barylko
  • 2. CapybaraWho am I?• Architect• Developer• Mentor• Great cook• The one who’s entertaining you for the next hour!
  • 3. Behavior Driven Dev. Text Text The rSpec Book
  • 4. Amir Barylko - Intro to CapybaraWhy Projects Fail?• Delivering late or over budget• Delivering the wrong thing• Unstable in production• Costly to maintain
  • 5. Amir Barylko - Intro to CapybaraImprove Quality• Unit Testing• Integration Testing• Acceptance Testing
  • 6. Amir Barylko - Intro to CapybaraBDD• Implementing an application• by describing its behavior• from the perspective of the stakeholder
  • 7. Amir Barylko - Intro to CapybaraOutside In Approach BDD TDD
  • 8. Amir Barylko - Intro to CapybaraTest First• Write a test before any line of code• Write minimum amount of code to make the test pass• Refactor code to eliminate “smells”
  • 9. Cucumber
  • 10. Amir Barylko - Intro to CapybaraGherkin DSL• Business readable DSL• Flush out requirements• Documentation• Automated testing• Used by Cucumber, SpecFlow, jBehave
  • 11. Amir Barylko - Intro to CapybaraGherkin Keywords• Feature • Then• Scenario • And• Given • But• When
  • 12. Amir Barylko - Intro to CapybaraFeaturesFeature: Listing projects As a user Free text! I Want to see the list of projects So I can choose one to see the details Scenario: List all projects (steps here to implement scenario) Scenario: No projects are available (steps here to implement scenario)
  • 13. Amir Barylko - Intro to CapybaraScenarioScenario: List all projects Given Im logged in Step 1 And I have some projects stored Step 2 When I browse the projects Step 3 Then I should see all of them listed Step 4
  • 14. Amir Barylko - Intro to CapybaraRunning Features• Parse the feature • Parse the scenario • For each scenario • Find a step implementation • Execute the code
  • 15. Amir Barylko - Intro to CapybaraMatching Step• Matching regular expression Given I have some projects stored Feature File Given /^I have some projects stored$/ Step Def File
  • 16. Amir Barylko - Intro to CapybaraStepGiven /^I have some projects stored$/ do projects = 10.times { random_valid_project } fake_response = create_response(projects) FakeWeb.register_uri(....)end Plain Ruby!
  • 17. Capybara
  • 18. Amir Barylko - Intro to CapybaraThe biggest rodent?• Gem to simplify integration tests• Inspired by Webrat• Used to implement Cucumber steps• Or with your favorite testing framework
  • 19. Amir Barylko - Intro to CapybaraWhy?• Support for different drivers (browsers)• Even a headless driver (capybara-webkit)• Supports Rack applications• But can be used with any web app!
  • 20. Amir Barylko - Intro to CapybaraForms• click_link • check• click_button • uncheck• click_link_or_button • attach_file• choose • select_option• fill_in(“FirstName”, :with => “John”)
  • 21. Amir Barylko - Intro to CapybaraFinders• all(:css, ‘#user’)• all(:xpath, ‘//[@id=user]’)• find (throws exception if not found)• find_field• find_link• find_button• find_by_id
  • 22. Amir Barylko - Intro to CapybaraMatchers• has_selector?• has_no_selector?• has_content?• has_no_content
  • 23. Amir Barylko - Intro to CapybaraJavascript• execute_script(....)• Only selenium page.driver.browser.switch_to.alert.accept page.driver.browser.switch_to.alert.dismiss page.driver.browser.switch_to.alert.text
  • 24. Amir Barylko - Intro to CapybaraDrivers Rack? External? JS? Headless? Windows?Rack ✔ ✕ ✕ ✕ ✔Selenium ✔ ✔ ✔ ✕ ✔Webkit ✔ ✔ ✔ ✔ ✔Poltergeist ✔ ✔ ✔ ✔ ✕
  • 25. Summary
  • 26. Amir Barylko - Intro to CapybaraNext steps• Learn about using capybara DSL• Read and follow the Cucumber book• Learn about page objects pattern• Start with a simple project
  • 27. Amir Barylko - Intro to CapybaraResources• Email:,• Twitter: @abarylko• Blog:• Website:
  • 28. Amir Barylko - Intro to CapybaraResources II
  • 29. Amir Barylko - Intro to CapybaraResources III• Capybara: capybara• Cucumber: