TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
Â
YEG-UG-Capybara
1. AMIR BARYLKO
INTRO TO
CAPYBARA
EDMONTON RUBY USER GROUP
JUNE 2011
Amir Barylko - Capybara MavenThought Inc.
2. WHO AM I?
⢠Architect
⢠Developer
⢠Mentor
⢠Great cook
⢠The one whoâs entertaining you for the next hour!
Amir Barylko - Capybara MavenThought Inc.
4. WHY TRADITIONAL
PROJECTS FAIL?
⢠Delivering late or over budget
⢠Delivering the wrong thing
⢠Unstable in production
⢠Costly to maintain
Amir Barylko - Capybara MavenThought Inc.
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 behaviour
Amir Barylko - Capybara MavenThought Inc.
7. GHERKIN DSL
⢠Business readable DSL
⢠Flush out requirements
⢠Documentation
⢠Automated testing
⢠Used by Cucumber,
SpecFlow, jBehave
Amir Barylko - Capybara MavenThought Inc.
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 I'm 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.
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,...})
FakeWeb.register_uri(:get, "http://agilezen....", :body => fake_response)
FakeWeb.register_uri(:get, "http://agilezen....", :body => JSON.generate(projects[0]))
end
Amir Barylko - Capybara MavenThought Inc.
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 capybara
Amir Barylko - Capybara MavenThought Inc.
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 calls
Amir Barylko - Capybara MavenThought Inc.
14. FORMS
⢠click_link(...) ⢠check(...)
⢠click_button(...) ⢠uncheck(...)
⢠click_link_or_button(...) ⢠attach_ďŹle(...)
⢠choose(...) ⢠select_option(...)
⢠ďŹll_in(âFirstNameâ, :with =>
âJohnâ)
Amir Barylko - Capybara MavenThought Inc.
15. FINDERS
⢠all(*args) ⢠ďŹnd_button
⢠page.all(:css, âa#userâ)
⢠ďŹnd_by_id
⢠page.all(:xpath, â//[@id=user]â)
⢠ďŹnd (same args as all)
⢠ďŹnd_ďŹeld
⢠ďŹnd_link
Amir Barylko - Capybara MavenThought Inc.
16. MATCHERS
⢠has_selector?
⢠has_no_selector?
⢠has_content?
⢠has_no_content
Amir Barylko - Capybara MavenThought Inc.
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.
18. STEPS II
⢠When I ďŹll â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 ďŹle âsettings.xmlâ to âďŹleâ
Amir Barylko - Capybara MavenThought Inc.
19. STEPS III
⢠Then I should see âWelcomeâ
⢠Then I should not see âWelcomeâ
⢠Then the ďŹeld âuserâ should contain âMelâ
⢠Then show me the page
Amir Barylko - Capybara MavenThought Inc.
20. XPATH
⢠Then I should see âWelcomeâ
⢠Then I should not see âWelcomeâ
⢠Then the ďŹeld âuserâ should contain âMelâ
⢠Then show me the page
Amir Barylko - Capybara MavenThought Inc.