SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Downloaden Sie, um offline zu lesen
BDD(ROR) using
    Cucumber/Rspec
:acceptance=> :capybara




         By: Bindesh Vijayan
Cucumber
●   Cucumber is a tool that executes
    plain-text functional descriptions
    as automated tests.
●   While Cucumber can be thought of as
    a “testing” tool, the intent of the
    tool is to support BDD
●   This means that the “tests” (plain
    text feature descriptions with
    scenarios) are typically written
    before anything else and verified by
    business analysts, domain experts,
    etc. non technical stakeholders.
4 steps in defining a
           feature
●   Cucumber begins by defining a
    “Feature” that we are trying to
    implement
●   After that we specify what we want to
    do using “In Order”
●   The we specify a user who will be
    interacting with that feature using
    “As a”
●   And then we finally specify what do
    we expect using “I want”
#Example: user.feature
Feature: User login
 In order to login
 As a User
 I want to specify a valid
 credential and login
Defining the scenario
           for login
●   After the feature is specified
    you need to specify “Scenario”
    for Cucumber
●   Scenario consists of the
    following clauses
     Given
     When
     Then
Lets extend our
      user.feature
Scenario: Logging into the
system
 Given when i visit the login page
 And I enter a valid username and
 password
 When I press login button
 Then I should see a success message
User.feature in a nutshell
Feature: User login
 In order to login
 As a User
 I want to see a login page with username and
 password

Scenario: Logging into the system
 Given when i visit the login page
 And I enter a valid username and password
 When I press login button
 Then I should see a success message
Cucumber on terminal
●   Installing
     gem install cucumber
●   Cucumber help
     cucumber –help
●   Running cucumber tests
     cucumber features/user.feature
Specifying steps
●   Once you run cucumber it will report the
    missing steps with examples of how you
    can write them
●   Create a new folder name step_definitions
    and add a new file called
    <object>_steps.rb
●   Copy paste the code from the output
●   Re run, the Feature would pass but the
    scenario would fail
Cucumber steps
●   Cucumber internally uses
    capybara
●   You can use any other acceptance
    test framework e.g. Webrat
●   For this session we will stick
    to capybara
Capybara DSL to simulate
       user steps
●   Navigating
     visit('/projects')
     visit(post_comments_path(post))
●   Clicking links and buttons
     click_link('id-of-link')
     click_link('Link Text')
     click_button('Save')
     click_on('Link Text') # clicks on
     either links or buttons
     click_on('Button Value')
Interacting with forms


 fill_in('First Name', :with => 'John')
 fill_in('Password', :with => 'Seekrit')
 fill_in('Description', :with => 'Really
 Long Text...')
 choose('A Radio Button')
 check('A Checkbox')
 uncheck('A Checkbox')
 attach_file('Image', '/path/to/image.jpg')
 select('Option', :from => 'Select Box')
●   Querying
    page.has_selector?('table tr')
    page.has_selector?(:xpath,
    '//table/tr')

    page.has_xpath?('//table/tr')
    page.has_css?('table tr.foo')
    page.has_content?('foo')
Scoping
●   Capybara makes it possible to
    restrict certain actions, such as
    interacting with forms or clicking
    links and buttons, to within a
    specific area of the page
●   You can use within DSL to specify
    a scope
     e.g. within(“#form-group”)
●   You can also further restrict it
    to a table
     e.g. within_table(“customer-table”)
A note about Capybara
            drivers
●   Drivers are the internal selectors, if
    you may want to call it, used by
    Capybara
●   By default capybara uses rack_test,
    which is faster than others
●   The limitation it doesn't support
    Javascript and can't access external
    HTTP resources like remote APIs or Oauth
    services
●   You can change the default driver by
    specifying this line in your helper
     Capybara.default_driver = :selenium
Rspec and Capybara
●   Instead of using Cucumber you can use
    Rspec and Capybara
●   We use the same basic principle that we
    used with Rspec
●   Only difference is that you now use
    capybara dsl insidel your rspec “it” blocks
Configuring rspec with capybara
#Gem file
group :development, :test do
  gem 'rspec-rails'
  gem 'capybara'
end
#spec_helper
require 'rspec/rails'
# Add this to load Capybara integration:
require 'capybara/rspec'
require 'capybara/rails
Example
require 'spec_helper'

describe 'home page' do
  it 'welcomes the user' do
    visit '/'
    page.should
have_content('Welcome')
  end
end

Weitere ähnliche Inhalte

Was ist angesagt?

AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEGavin Pickin
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testingdversaci
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017Ortus Solutions, Corp
 
Jest: Frontend Testing leicht gemacht @EnterJS2018
Jest: Frontend Testing leicht gemacht @EnterJS2018Jest: Frontend Testing leicht gemacht @EnterJS2018
Jest: Frontend Testing leicht gemacht @EnterJS2018Holger Grosse-Plankermann
 
Jasmine - A BDD test framework for JavaScript
Jasmine - A BDD test framework for JavaScriptJasmine - A BDD test framework for JavaScript
Jasmine - A BDD test framework for JavaScriptSumanth krishna
 
DevQA: make your testers happier with Groovy, Spock and Geb
DevQA: make your testers happier with Groovy, Spock and GebDevQA: make your testers happier with Groovy, Spock and Geb
DevQA: make your testers happier with Groovy, Spock and GebAlvaro Sanchez-Mariscal
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React AppAll Things Open
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION APIGavin Pickin
 
Bdd – with cucumber and gherkin
Bdd – with cucumber and gherkinBdd – with cucumber and gherkin
Bdd – with cucumber and gherkinArati Joshi
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by ExampleNalin Goonawardana
 
Integration and Acceptance Testing
Integration and Acceptance TestingIntegration and Acceptance Testing
Integration and Acceptance TestingAlan Hecht
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJSPeter Drinnan
 
Behavior Driven Development with Cucumber
Behavior Driven Development with CucumberBehavior Driven Development with Cucumber
Behavior Driven Development with CucumberBrandon Keepers
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineGil Fink
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWHolger Grosse-Plankermann
 

Was ist angesagt? (20)

DDD with Behat
DDD with BehatDDD with Behat
DDD with Behat
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testing
 
Behavior Driven Development Testing (BDD)
Behavior Driven Development Testing (BDD)Behavior Driven Development Testing (BDD)
Behavior Driven Development Testing (BDD)
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
 
Jest: Frontend Testing leicht gemacht @EnterJS2018
Jest: Frontend Testing leicht gemacht @EnterJS2018Jest: Frontend Testing leicht gemacht @EnterJS2018
Jest: Frontend Testing leicht gemacht @EnterJS2018
 
Jasmine - A BDD test framework for JavaScript
Jasmine - A BDD test framework for JavaScriptJasmine - A BDD test framework for JavaScript
Jasmine - A BDD test framework for JavaScript
 
DevQA: make your testers happier with Groovy, Spock and Geb
DevQA: make your testers happier with Groovy, Spock and GebDevQA: make your testers happier with Groovy, Spock and Geb
DevQA: make your testers happier with Groovy, Spock and Geb
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
 
Jbehave selenium
Jbehave seleniumJbehave selenium
Jbehave selenium
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
 
Bdd – with cucumber and gherkin
Bdd – with cucumber and gherkinBdd – with cucumber and gherkin
Bdd – with cucumber and gherkin
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by Example
 
Integration and Acceptance Testing
Integration and Acceptance TestingIntegration and Acceptance Testing
Integration and Acceptance Testing
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
 
Behavior Driven Development with Cucumber
Behavior Driven Development with CucumberBehavior Driven Development with Cucumber
Behavior Driven Development with Cucumber
 
Automate Thyself
Automate ThyselfAutomate Thyself
Automate Thyself
 
Continuous feature-development
Continuous feature-developmentContinuous feature-development
Continuous feature-development
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
 

Andere mochten auch

Capybara + RSpec - ruby dsl-based web ui qa automation
Capybara + RSpec - ruby dsl-based web ui qa automationCapybara + RSpec - ruby dsl-based web ui qa automation
Capybara + RSpec - ruby dsl-based web ui qa automationCOMAQA.BY
 
Rocket Fuelled Cucumbers
Rocket Fuelled CucumbersRocket Fuelled Cucumbers
Rocket Fuelled CucumbersJoseph Wilk
 
Mobile automation using selenium cucumber & appium
Mobile automation using selenium cucumber & appiumMobile automation using selenium cucumber & appium
Mobile automation using selenium cucumber & appiumSelenium Cucumber
 
Future of test automation tools & infrastructure
Future of test automation tools & infrastructureFuture of test automation tools & infrastructure
Future of test automation tools & infrastructureAnand Bagmar
 
Using Selenium and Cucumber to test a Healthcare Information System
Using Selenium and Cucumber to test a Healthcare Information SystemUsing Selenium and Cucumber to test a Healthcare Information System
Using Selenium and Cucumber to test a Healthcare Information Systemandytinkham
 
Mobile automation using selenium cucumber & appium
Mobile automation using selenium cucumber & appiumMobile automation using selenium cucumber & appium
Mobile automation using selenium cucumber & appiumSelenium Cucumber
 
Cucumber - Curso de Automatización de Pruebas
Cucumber - Curso de Automatización de PruebasCucumber - Curso de Automatización de Pruebas
Cucumber - Curso de Automatización de PruebasTestingBaires
 
Automated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and SeleniumAutomated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and SeleniumDev9Com
 

Andere mochten auch (11)

Capybara + RSpec - ruby dsl-based web ui qa automation
Capybara + RSpec - ruby dsl-based web ui qa automationCapybara + RSpec - ruby dsl-based web ui qa automation
Capybara + RSpec - ruby dsl-based web ui qa automation
 
Rocket Fuelled Cucumbers
Rocket Fuelled CucumbersRocket Fuelled Cucumbers
Rocket Fuelled Cucumbers
 
Cucumber_Capybara
Cucumber_CapybaraCucumber_Capybara
Cucumber_Capybara
 
Mobile automation using selenium cucumber & appium
Mobile automation using selenium cucumber & appiumMobile automation using selenium cucumber & appium
Mobile automation using selenium cucumber & appium
 
Future of test automation tools & infrastructure
Future of test automation tools & infrastructureFuture of test automation tools & infrastructure
Future of test automation tools & infrastructure
 
Using Selenium and Cucumber to test a Healthcare Information System
Using Selenium and Cucumber to test a Healthcare Information SystemUsing Selenium and Cucumber to test a Healthcare Information System
Using Selenium and Cucumber to test a Healthcare Information System
 
Cucumber
CucumberCucumber
Cucumber
 
Mobile automation using selenium cucumber & appium
Mobile automation using selenium cucumber & appiumMobile automation using selenium cucumber & appium
Mobile automation using selenium cucumber & appium
 
Cucumber - Curso de Automatización de Pruebas
Cucumber - Curso de Automatización de PruebasCucumber - Curso de Automatización de Pruebas
Cucumber - Curso de Automatización de Pruebas
 
Automated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and SeleniumAutomated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and Selenium
 
Cucumber ppt
Cucumber pptCucumber ppt
Cucumber ppt
 

Ähnlich wie Ruby onrails cucumber-rspec-capybara

BDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User StoriesBDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User StoriesSauce Labs
 
Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...Concetto Labs
 
Perl Behavior Driven Development (BDD)
Perl Behavior Driven Development (BDD)Perl Behavior Driven Development (BDD)
Perl Behavior Driven Development (BDD)Tudor Constantin
 
Behat for writing tests in a stylized way
Behat for writing tests in a stylized wayBehat for writing tests in a stylized way
Behat for writing tests in a stylized wayRavindra Singh
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratiehcderaad
 
Behat - Drupal South 2018
Behat  - Drupal South 2018Behat  - Drupal South 2018
Behat - Drupal South 2018Berend de Boer
 
BDD / cucumber /Capybara
BDD / cucumber /CapybaraBDD / cucumber /Capybara
BDD / cucumber /CapybaraShraddhaSF
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF SummitOrtus Solutions, Corp
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingAlessandro Molina
 
RSpec User Stories
RSpec User StoriesRSpec User Stories
RSpec User Storiesrahoulb
 
Azure Functions in Action #OrlandoCC
Azure Functions in Action #OrlandoCCAzure Functions in Action #OrlandoCC
Azure Functions in Action #OrlandoCCBaskar rao Dsn
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JSBipin
 
Introduction to Swagger
Introduction to SwaggerIntroduction to Swagger
Introduction to SwaggerKnoldus Inc.
 
Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)Katy Slemon
 
QTP Descriptive programming Tutorial
QTP Descriptive programming TutorialQTP Descriptive programming Tutorial
QTP Descriptive programming TutorialJim Orlando
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascriptambuj pathak
 
3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - 3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - Ortus Solutions, Corp
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWP Engine
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWP Engine UK
 

Ähnlich wie Ruby onrails cucumber-rspec-capybara (20)

BDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User StoriesBDD Selenium for Agile Teams - User Stories
BDD Selenium for Agile Teams - User Stories
 
Cucumber_Training_ForQA
Cucumber_Training_ForQACucumber_Training_ForQA
Cucumber_Training_ForQA
 
Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...Guidelines to understand durable functions with .net core, c# and stateful se...
Guidelines to understand durable functions with .net core, c# and stateful se...
 
Perl Behavior Driven Development (BDD)
Perl Behavior Driven Development (BDD)Perl Behavior Driven Development (BDD)
Perl Behavior Driven Development (BDD)
 
Behat for writing tests in a stylized way
Behat for writing tests in a stylized wayBehat for writing tests in a stylized way
Behat for writing tests in a stylized way
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie
 
Behat - Drupal South 2018
Behat  - Drupal South 2018Behat  - Drupal South 2018
Behat - Drupal South 2018
 
BDD / cucumber /Capybara
BDD / cucumber /CapybaraBDD / cucumber /Capybara
BDD / cucumber /Capybara
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears Training
 
RSpec User Stories
RSpec User StoriesRSpec User Stories
RSpec User Stories
 
Azure Functions in Action #OrlandoCC
Azure Functions in Action #OrlandoCCAzure Functions in Action #OrlandoCC
Azure Functions in Action #OrlandoCC
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JS
 
Introduction to Swagger
Introduction to SwaggerIntroduction to Swagger
Introduction to Swagger
 
Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)
 
QTP Descriptive programming Tutorial
QTP Descriptive programming TutorialQTP Descriptive programming Tutorial
QTP Descriptive programming Tutorial
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - 3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API -
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST API
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST API
 

Ruby onrails cucumber-rspec-capybara

  • 1. BDD(ROR) using Cucumber/Rspec :acceptance=> :capybara By: Bindesh Vijayan
  • 2. Cucumber ● Cucumber is a tool that executes plain-text functional descriptions as automated tests. ● While Cucumber can be thought of as a “testing” tool, the intent of the tool is to support BDD ● This means that the “tests” (plain text feature descriptions with scenarios) are typically written before anything else and verified by business analysts, domain experts, etc. non technical stakeholders.
  • 3. 4 steps in defining a feature ● Cucumber begins by defining a “Feature” that we are trying to implement ● After that we specify what we want to do using “In Order” ● The we specify a user who will be interacting with that feature using “As a” ● And then we finally specify what do we expect using “I want”
  • 4. #Example: user.feature Feature: User login In order to login As a User I want to specify a valid credential and login
  • 5. Defining the scenario for login ● After the feature is specified you need to specify “Scenario” for Cucumber ● Scenario consists of the following clauses Given When Then
  • 6. Lets extend our user.feature Scenario: Logging into the system Given when i visit the login page And I enter a valid username and password When I press login button Then I should see a success message
  • 7. User.feature in a nutshell Feature: User login In order to login As a User I want to see a login page with username and password Scenario: Logging into the system Given when i visit the login page And I enter a valid username and password When I press login button Then I should see a success message
  • 8. Cucumber on terminal ● Installing gem install cucumber ● Cucumber help cucumber –help ● Running cucumber tests cucumber features/user.feature
  • 9. Specifying steps ● Once you run cucumber it will report the missing steps with examples of how you can write them ● Create a new folder name step_definitions and add a new file called <object>_steps.rb ● Copy paste the code from the output ● Re run, the Feature would pass but the scenario would fail
  • 10. Cucumber steps ● Cucumber internally uses capybara ● You can use any other acceptance test framework e.g. Webrat ● For this session we will stick to capybara
  • 11. Capybara DSL to simulate user steps ● Navigating visit('/projects') visit(post_comments_path(post)) ● Clicking links and buttons click_link('id-of-link') click_link('Link Text') click_button('Save') click_on('Link Text') # clicks on either links or buttons click_on('Button Value')
  • 12. Interacting with forms fill_in('First Name', :with => 'John') fill_in('Password', :with => 'Seekrit') fill_in('Description', :with => 'Really Long Text...') choose('A Radio Button') check('A Checkbox') uncheck('A Checkbox') attach_file('Image', '/path/to/image.jpg') select('Option', :from => 'Select Box')
  • 13. Querying page.has_selector?('table tr') page.has_selector?(:xpath, '//table/tr') page.has_xpath?('//table/tr') page.has_css?('table tr.foo') page.has_content?('foo')
  • 14. Scoping ● Capybara makes it possible to restrict certain actions, such as interacting with forms or clicking links and buttons, to within a specific area of the page ● You can use within DSL to specify a scope e.g. within(“#form-group”) ● You can also further restrict it to a table e.g. within_table(“customer-table”)
  • 15. A note about Capybara drivers ● Drivers are the internal selectors, if you may want to call it, used by Capybara ● By default capybara uses rack_test, which is faster than others ● The limitation it doesn't support Javascript and can't access external HTTP resources like remote APIs or Oauth services ● You can change the default driver by specifying this line in your helper Capybara.default_driver = :selenium
  • 16. Rspec and Capybara ● Instead of using Cucumber you can use Rspec and Capybara ● We use the same basic principle that we used with Rspec ● Only difference is that you now use capybara dsl insidel your rspec “it” blocks
  • 17. Configuring rspec with capybara #Gem file group :development, :test do gem 'rspec-rails' gem 'capybara' end #spec_helper require 'rspec/rails' # Add this to load Capybara integration: require 'capybara/rspec' require 'capybara/rails
  • 18. Example require 'spec_helper' describe 'home page' do it 'welcomes the user' do visit '/' page.should have_content('Welcome') end end