SlideShare a Scribd company logo
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

More Related Content

PDF
Rspec and Capybara Intro Tutorial at RailsConf 2013
PDF
Capybara testing
PDF
Lunch and learn: Cucumber and Capybara
PDF
Acceptance Test-driven Development with Cucumber-jvm
PPTX
Test automation with Cucumber-JVM
PPTX
Test automation with cucumber jvm
PDF
The LAZY Developer's Guide to BDD (with Cucumber)
PDF
cf.Objective() 2017 - Design patterns - Brad Wood
Rspec and Capybara Intro Tutorial at RailsConf 2013
Capybara testing
Lunch and learn: Cucumber and Capybara
Acceptance Test-driven Development with Cucumber-jvm
Test automation with Cucumber-JVM
Test automation with cucumber jvm
The LAZY Developer's Guide to BDD (with Cucumber)
cf.Objective() 2017 - Design patterns - Brad Wood

What's hot (20)

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

Viewers also liked (11)

PPTX
Capybara + RSpec - ruby dsl-based web ui qa automation
PDF
Rocket Fuelled Cucumbers
PPTX
Cucumber_Capybara
PDF
Mobile automation using selenium cucumber & appium
PDF
Future of test automation tools & infrastructure
PPTX
Using Selenium and Cucumber to test a Healthcare Information System
PPTX
Cucumber
PDF
Mobile automation using selenium cucumber & appium
PPT
Cucumber - Curso de Automatización de Pruebas
PPTX
Automated Testing with Cucumber, PhantomJS and Selenium
PDF
Cucumber ppt
Capybara + RSpec - ruby dsl-based web ui qa automation
Rocket Fuelled Cucumbers
Cucumber_Capybara
Mobile automation using selenium cucumber & appium
Future of test automation tools & infrastructure
Using Selenium and Cucumber to test a Healthcare Information System
Cucumber
Mobile automation using selenium cucumber & appium
Cucumber - Curso de Automatización de Pruebas
Automated Testing with Cucumber, PhantomJS and Selenium
Cucumber ppt
Ad

Similar to Ruby onrails cucumber-rspec-capybara (20)

PPTX
BDD Selenium for Agile Teams - User Stories
PPTX
Cucumber_Training_ForQA
PPTX
Guidelines to understand durable functions with .net core, c# and stateful se...
PDF
Perl Behavior Driven Development (BDD)
PDF
Behat for writing tests in a stylized way
PDF
Master Cucumber cheat sheet for testing .pdf
ODP
2014 11 20 Drupal 7 -> 8 test migratie
PPTX
Behat - Drupal South 2018
PPTX
BDD / cucumber /Capybara
PDF
Leveraging Playwright for API Testing.pdf
PPTX
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
PDF
EuroPython 2013 - Python3 TurboGears Training
PDF
RSpec User Stories
PDF
Mastering BDD with Cucumber & Java for Test Automation
PPTX
Azure Functions in Action #OrlandoCC
PPTX
Front end development with Angular JS
ODP
Introduction to Swagger
PDF
Go swagger tutorial how to create golang api documentation using go swagger (1)
PDF
QTP Descriptive programming Tutorial
PPTX
Introduction to Javascript
BDD Selenium for Agile Teams - User Stories
Cucumber_Training_ForQA
Guidelines to understand durable functions with .net core, c# and stateful se...
Perl Behavior Driven Development (BDD)
Behat for writing tests in a stylized way
Master Cucumber cheat sheet for testing .pdf
2014 11 20 Drupal 7 -> 8 test migratie
Behat - Drupal South 2018
BDD / cucumber /Capybara
Leveraging Playwright for API Testing.pdf
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
EuroPython 2013 - Python3 TurboGears Training
RSpec User Stories
Mastering BDD with Cucumber & Java for Test Automation
Azure Functions in Action #OrlandoCC
Front end development with Angular JS
Introduction to Swagger
Go swagger tutorial how to create golang api documentation using go swagger (1)
QTP Descriptive programming Tutorial
Introduction to Javascript

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