SlideShare a Scribd company logo
1 of 29
Download to read offline
Intro to Capybara
    Amir Barylko
Capybara


Who 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 Capybara


Why Projects Fail?
• Delivering   late or over budget

• Delivering   the wrong thing

• Unstable   in production

• Costly   to maintain
Amir Barylko - Intro to Capybara


Improve Quality
• Unit Testing

• Integration Testing

• Acceptance Testing
Amir Barylko - Intro to Capybara


BDD
• Implementing    an application

• by   describing its behavior

• from   the perspective of the stakeholder
Amir Barylko - Intro to Capybara


Outside In Approach


       BDD        TDD
Amir Barylko - Intro to Capybara


Test 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 Capybara


Gherkin DSL
•   Business readable DSL

•   Flush out requirements

•   Documentation

•   Automated testing

•   Used by Cucumber,
    SpecFlow, jBehave
Amir Barylko - Intro to Capybara


Gherkin Keywords
• Feature    • Then

• Scenario   • And

• Given      • But

• When
Amir Barylko - Intro to Capybara


Features
Feature: 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 Capybara


Scenario
Scenario: List all projects
  Given I'm 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 Capybara


Running Features
•   Parse the feature

    •   Parse the scenario

        •   For each scenario

            •   Find a step implementation

            •   Execute the code
Amir Barylko - Intro to Capybara


Matching 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 Capybara


Step
Given /^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 Capybara


The 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 Capybara


Why?
• 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 Capybara


Forms
•   click_link             •   check

•   click_button           •   uncheck

•   click_link_or_button   •   attach_file

•   choose                 •   select_option

•   fill_in(“FirstName”, :with => “John”)
Amir Barylko - Intro to Capybara


Finders
•   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 Capybara


Matchers
•   has_selector?

•   has_no_selector?

•   has_content?

•   has_no_content
Amir Barylko - Intro to Capybara


Javascript
• 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 Capybara


Drivers
              Rack?   External?   JS?    Headless?      Windows?


Rack           ✔         ✕        ✕          ✕             ✔
Selenium       ✔         ✔        ✔          ✕             ✔
Webkit         ✔         ✔        ✔          ✔             ✔
Poltergeist    ✔         ✔        ✔          ✔             ✕
Summary
Amir Barylko - Intro to Capybara


Next 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 Capybara


Resources
• Email: amir@barylko.com,

• Twitter: @abarylko

• Blog: http://orthocoders.com

• Website: http://maventhought.com
Amir Barylko - Intro to Capybara


Resources II
Amir Barylko - Intro to Capybara


Resources III
• Capybara: https://github.com/jnicklas/
 capybara

• Cucumber: https://github.com/cucumber

More Related Content

What's hot

Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Bruce Li
 
Advanced Skinning & Styling for Android
Advanced Skinning & Styling for AndroidAdvanced Skinning & Styling for Android
Advanced Skinning & Styling for Android
cephus07
 

What's hot (7)

creative commons about license only with three colors
creative commons about license only with three colorscreative commons about license only with three colors
creative commons about license only with three colors
 
Refactoring Workshop (Rails Pacific 2014)
Refactoring Workshop (Rails Pacific 2014)Refactoring Workshop (Rails Pacific 2014)
Refactoring Workshop (Rails Pacific 2014)
 
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
 
Call Control Power Tools with Adhearsion
Call Control Power Tools with AdhearsionCall Control Power Tools with Adhearsion
Call Control Power Tools with Adhearsion
 
Gamemaker - More core objects
Gamemaker - More core objectsGamemaker - More core objects
Gamemaker - More core objects
 
Testing Alexa Skill
Testing Alexa SkillTesting Alexa Skill
Testing Alexa Skill
 
Advanced Skinning & Styling for Android
Advanced Skinning & Styling for AndroidAdvanced Skinning & Styling for Android
Advanced Skinning & Styling for Android
 

Similar to DevTeach12-Capybara

prdc10-Bdd-real-world
prdc10-Bdd-real-worldprdc10-Bdd-real-world
prdc10-Bdd-real-world
Amir Barylko
 
Open source libraries and tools
Open source libraries and toolsOpen source libraries and tools
Open source libraries and tools
Amir Barylko
 
Cpl12 continuous integration
Cpl12 continuous integrationCpl12 continuous integration
Cpl12 continuous integration
Amir Barylko
 
PRDC-ror-trilogy-part1
PRDC-ror-trilogy-part1PRDC-ror-trilogy-part1
PRDC-ror-trilogy-part1
Amir Barylko
 

Similar to DevTeach12-Capybara (20)

YEG-UG-Capybara
YEG-UG-CapybaraYEG-UG-Capybara
YEG-UG-Capybara
 
PRDCW-advanced-design-patterns
PRDCW-advanced-design-patternsPRDCW-advanced-design-patterns
PRDCW-advanced-design-patterns
 
Page objects pattern
Page objects patternPage objects pattern
Page objects pattern
 
Page-objects-pattern
Page-objects-patternPage-objects-pattern
Page-objects-pattern
 
PRDC12 advanced design patterns
PRDC12 advanced design patternsPRDC12 advanced design patterns
PRDC12 advanced design patterns
 
sdec11-Advanced-design-patterns
sdec11-Advanced-design-patternssdec11-Advanced-design-patterns
sdec11-Advanced-design-patterns
 
prdc10-Bdd-real-world
prdc10-Bdd-real-worldprdc10-Bdd-real-world
prdc10-Bdd-real-world
 
Capybara1
Capybara1Capybara1
Capybara1
 
Agile requirements
Agile requirementsAgile requirements
Agile requirements
 
2012 regina TC - 103 quality driven
2012 regina TC - 103 quality driven2012 regina TC - 103 quality driven
2012 regina TC - 103 quality driven
 
CPL12-Agile-planning
CPL12-Agile-planningCPL12-Agile-planning
CPL12-Agile-planning
 
Open source libraries and tools
Open source libraries and toolsOpen source libraries and tools
Open source libraries and tools
 
YEG-Agile-planning
YEG-Agile-planningYEG-Agile-planning
YEG-Agile-planning
 
Nuget
NugetNuget
Nuget
 
Agile planning
Agile planningAgile planning
Agile planning
 
2012 regina TC - 101 welcome & resources
2012 regina TC - 101 welcome & resources2012 regina TC - 101 welcome & resources
2012 regina TC - 101 welcome & resources
 
Cpl12 continuous integration
Cpl12 continuous integrationCpl12 continuous integration
Cpl12 continuous integration
 
PRDC-ror-trilogy-part1
PRDC-ror-trilogy-part1PRDC-ror-trilogy-part1
PRDC-ror-trilogy-part1
 
Ro r trilogy-part-1
Ro r trilogy-part-1Ro r trilogy-part-1
Ro r trilogy-part-1
 
sdec11-ror-trilogy-part1
sdec11-ror-trilogy-part1sdec11-ror-trilogy-part1
sdec11-ror-trilogy-part1
 

More from Amir Barylko

Beutiful javascript with coffeescript
Beutiful javascript with coffeescriptBeutiful javascript with coffeescript
Beutiful javascript with coffeescript
Amir Barylko
 

More from Amir Barylko (20)

Functional converter project
Functional converter projectFunctional converter project
Functional converter project
 
Elm: delightful web development
Elm: delightful web developmentElm: delightful web development
Elm: delightful web development
 
Dot Net Core
Dot Net CoreDot Net Core
Dot Net Core
 
No estimates
No estimatesNo estimates
No estimates
 
User stories deep dive
User stories deep diveUser stories deep dive
User stories deep dive
 
Coderetreat hosting training
Coderetreat hosting trainingCoderetreat hosting training
Coderetreat hosting training
 
There's no charge for (functional) awesomeness
There's no charge for (functional) awesomenessThere's no charge for (functional) awesomeness
There's no charge for (functional) awesomeness
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6
 
Productive teams
Productive teamsProductive teams
Productive teams
 
Who killed object oriented design?
Who killed object oriented design?Who killed object oriented design?
Who killed object oriented design?
 
From coach to owner - What I learned from the other side
From coach to owner - What I learned from the other sideFrom coach to owner - What I learned from the other side
From coach to owner - What I learned from the other side
 
Communication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivityCommunication is the Key to Teamwork and productivity
Communication is the Key to Teamwork and productivity
 
Acceptance Test Driven Development
Acceptance Test Driven DevelopmentAcceptance Test Driven Development
Acceptance Test Driven Development
 
Refactoring
RefactoringRefactoring
Refactoring
 
Agile requirements
Agile requirementsAgile requirements
Agile requirements
 
Agile teams and responsibilities
Agile teams and responsibilitiesAgile teams and responsibilities
Agile teams and responsibilities
 
Refactoring
RefactoringRefactoring
Refactoring
 
Beutiful javascript with coffeescript
Beutiful javascript with coffeescriptBeutiful javascript with coffeescript
Beutiful javascript with coffeescript
 
Sass & bootstrap
Sass & bootstrapSass & bootstrap
Sass & bootstrap
 
SDEC12 Beautiful javascript with coffeescript
SDEC12 Beautiful javascript with coffeescriptSDEC12 Beautiful javascript with coffeescript
SDEC12 Beautiful javascript with coffeescript
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

DevTeach12-Capybara

  • 1. Intro to Capybara Amir Barylko
  • 2. Capybara Who 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 Capybara Why Projects Fail? • Delivering late or over budget • Delivering the wrong thing • Unstable in production • Costly to maintain
  • 5. Amir Barylko - Intro to Capybara Improve Quality • Unit Testing • Integration Testing • Acceptance Testing
  • 6. Amir Barylko - Intro to Capybara BDD • Implementing an application • by describing its behavior • from the perspective of the stakeholder
  • 7. Amir Barylko - Intro to Capybara Outside In Approach BDD TDD
  • 8. Amir Barylko - Intro to Capybara Test First • Write a test before any line of code • Write minimum amount of code to make the test pass • Refactor code to eliminate “smells”
  • 10. Amir Barylko - Intro to Capybara Gherkin DSL • Business readable DSL • Flush out requirements • Documentation • Automated testing • Used by Cucumber, SpecFlow, jBehave
  • 11. Amir Barylko - Intro to Capybara Gherkin Keywords • Feature • Then • Scenario • And • Given • But • When
  • 12. Amir Barylko - Intro to Capybara Features Feature: 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 Capybara Scenario Scenario: List all projects Given I'm 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 Capybara Running Features • Parse the feature • Parse the scenario • For each scenario • Find a step implementation • Execute the code
  • 15. Amir Barylko - Intro to Capybara Matching 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 Capybara Step Given /^I have some projects stored$/ do projects = 10.times { random_valid_project } fake_response = create_response(projects) FakeWeb.register_uri(....) end Plain Ruby!
  • 18. Amir Barylko - Intro to Capybara The 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 Capybara Why? • 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 Capybara Forms • 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 Capybara Finders • 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 Capybara Matchers • has_selector? • has_no_selector? • has_content? • has_no_content
  • 23. Amir Barylko - Intro to Capybara Javascript • 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 Capybara Drivers Rack? External? JS? Headless? Windows? Rack ✔ ✕ ✕ ✕ ✔ Selenium ✔ ✔ ✔ ✕ ✔ Webkit ✔ ✔ ✔ ✔ ✔ Poltergeist ✔ ✔ ✔ ✔ ✕
  • 26. Amir Barylko - Intro to Capybara Next 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 Capybara Resources • Email: amir@barylko.com, • Twitter: @abarylko • Blog: http://orthocoders.com • Website: http://maventhought.com
  • 28. Amir Barylko - Intro to Capybara Resources II
  • 29. Amir Barylko - Intro to Capybara Resources III • Capybara: https://github.com/jnicklas/ capybara • Cucumber: https://github.com/cucumber