Upcoming SlideShare
Loading in...5




Presentation done at Devteach/RubyTeach 2012

Presentation done at Devteach/RubyTeach 2012



Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds


Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

DevTeach12-Capybara DevTeach12-Capybara Presentation Transcript

  • Intro to Capybara Amir Barylko
  • CapybaraWho am I?• Architect• Developer• Mentor• Great cook• The one who’s entertaining you for the next hour!
  • Behavior Driven Dev. Text Text The rSpec Book
  • Amir Barylko - Intro to CapybaraWhy Projects Fail?• Delivering late or over budget• Delivering the wrong thing• Unstable in production• Costly to maintain
  • Amir Barylko - Intro to CapybaraImprove Quality• Unit Testing• Integration Testing• Acceptance Testing
  • Amir Barylko - Intro to CapybaraBDD• Implementing an application• by describing its behavior• from the perspective of the stakeholder
  • Amir Barylko - Intro to CapybaraOutside In Approach BDD TDD
  • 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”
  • Cucumber
  • Amir Barylko - Intro to CapybaraGherkin DSL• Business readable DSL• Flush out requirements• Documentation• Automated testing• Used by Cucumber, SpecFlow, jBehave
  • Amir Barylko - Intro to CapybaraGherkin Keywords• Feature • Then• Scenario • And• Given • But• When
  • 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)
  • 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
  • Amir Barylko - Intro to CapybaraRunning Features• Parse the feature • Parse the scenario • For each scenario • Find a step implementation • Execute the code
  • 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
  • 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!
  • Capybara
  • 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
  • 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!
  • 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”)
  • 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
  • Amir Barylko - Intro to CapybaraMatchers• has_selector?• has_no_selector?• has_content?• has_no_content
  • 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
  • Amir Barylko - Intro to CapybaraDrivers Rack? External? JS? Headless? Windows?Rack ✔ ✕ ✕ ✕ ✔Selenium ✔ ✔ ✔ ✕ ✔Webkit ✔ ✔ ✔ ✔ ✔Poltergeist ✔ ✔ ✔ ✔ ✕
  • Summary
  • 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
  • Amir Barylko - Intro to CapybaraResources• Email:,• Twitter: @abarylko• Blog:• Website:
  • Amir Barylko - Intro to CapybaraResources II
  • Amir Barylko - Intro to CapybaraResources III• Capybara: capybara• Cucumber: