Your SlideShare is downloading. ×
0
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• Unstab...
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 ...
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 t...
Cucumber
Amir Barylko - Intro to CapybaraGherkin DSL•   Business readable DSL•   Flush out requirements•   Documentation•   Automat...
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!  ...
Amir Barylko - Intro to CapybaraScenarioScenario: List all projects  Given Im logged in                            Step 1 ...
Amir Barylko - Intro to CapybaraRunning Features•   Parse the feature    •   Parse the scenario        •   For each scenar...
Amir Barylko - Intro to CapybaraMatching Step• Matching   regular expression Given I have some projects stored            ...
Amir Barylko - Intro to CapybaraStepGiven /^I have some projects stored$/ do  projects = 10.times { random_valid_project }...
Capybara
Amir Barylko - Intro to CapybaraThe biggest rodent?• Gem    to simplify integration tests• Inspired   by Webrat• Used   to...
Amir Barylko - Intro to CapybaraWhy?• Support   for different drivers (browsers)• Even   a headless driver (capybara-webki...
Amir Barylko - Intro to CapybaraForms•   click_link             •   check•   click_button           •   uncheck•   click_l...
Amir Barylko - Intro to CapybaraFinders•   all(:css, ‘#user’)•   all(:xpath, ‘//[@id=user]’)•   find (throws exception if ...
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.acce...
Amir Barylko - Intro to CapybaraDrivers              Rack?   External?   JS?    Headless?      Windows?Rack           ✔   ...
Summary
Amir Barylko - Intro to CapybaraNext steps•   Learn about using capybara DSL•   Read and follow the Cucumber book•   Learn...
Amir Barylko - Intro to CapybaraResources• Email: amir@barylko.com,• Twitter: @abarylko• Blog: http://orthocoders.com• Web...
Amir Barylko - Intro to CapybaraResources II
Amir Barylko - Intro to CapybaraResources III• Capybara: https://github.com/jnicklas/ capybara• Cucumber: https://github.c...
Upcoming SlideShare
Loading in...5
×

DevTeach12-Capybara

1,133

Published on

Presentation done at Devteach/RubyTeach 2012

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

  • Be the first to like this

No Downloads
Views
Total Views
1,133
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "DevTeach12-Capybara"

  1. 1. Intro to Capybara Amir Barylko
  2. 2. CapybaraWho am I?• Architect• Developer• Mentor• Great cook• The one who’s entertaining you for the next hour!
  3. 3. Behavior Driven Dev. Text Text The rSpec Book
  4. 4. Amir Barylko - Intro to CapybaraWhy Projects Fail?• Delivering late or over budget• Delivering the wrong thing• Unstable in production• Costly to maintain
  5. 5. Amir Barylko - Intro to CapybaraImprove Quality• Unit Testing• Integration Testing• Acceptance Testing
  6. 6. Amir Barylko - Intro to CapybaraBDD• Implementing an application• by describing its behavior• from the perspective of the stakeholder
  7. 7. Amir Barylko - Intro to CapybaraOutside In Approach BDD TDD
  8. 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. 9. Cucumber
  10. 10. Amir Barylko - Intro to CapybaraGherkin DSL• Business readable DSL• Flush out requirements• Documentation• Automated testing• Used by Cucumber, SpecFlow, jBehave
  11. 11. Amir Barylko - Intro to CapybaraGherkin Keywords• Feature • Then• Scenario • And• Given • But• When
  12. 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. 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. 14. Amir Barylko - Intro to CapybaraRunning Features• Parse the feature • Parse the scenario • For each scenario • Find a step implementation • Execute the code
  15. 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. 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. 17. Capybara
  18. 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. 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. 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. 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. 22. Amir Barylko - Intro to CapybaraMatchers• has_selector?• has_no_selector?• has_content?• has_no_content
  23. 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. 24. Amir Barylko - Intro to CapybaraDrivers Rack? External? JS? Headless? Windows?Rack ✔ ✕ ✕ ✕ ✔Selenium ✔ ✔ ✔ ✕ ✔Webkit ✔ ✔ ✔ ✔ ✔Poltergeist ✔ ✔ ✔ ✔ ✕
  25. 25. Summary
  26. 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. 27. Amir Barylko - Intro to CapybaraResources• Email: amir@barylko.com,• Twitter: @abarylko• Blog: http://orthocoders.com• Website: http://maventhought.com
  28. 28. Amir Barylko - Intro to CapybaraResources II
  29. 29. Amir Barylko - Intro to CapybaraResources III• Capybara: https://github.com/jnicklas/ capybara• Cucumber: https://github.com/cucumber
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×