putting cucumber to use n.
Skip this Video
Loading SlideShow in 5 Seconds..
Putting Cucumber to Use PowerPoint Presentation
Download Presentation
Putting Cucumber to Use

Loading in 2 Seconds...

play fullscreen
1 / 20

Putting Cucumber to Use - PowerPoint PPT Presentation

  • Uploaded on

Putting Cucumber to Use. Titus Fortner HomeAway 5 June 2013. Answers. What exactly is a tool like Cucumber? Is it something I should use? What does it look like in practice? Why did I go out of my way to spend an hour listening to this?. It isn’t Magic.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Putting Cucumber to Use' - janina

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
putting cucumber to use

Putting Cucumber to Use

Titus Fortner


5 June 2013

  • What exactly is a tool like Cucumber?
  • Is it something I should use?
  • What does it look like in practice?
  • Why did I go out of my way to spend an hour listening to this?
it isn t magic
It isn’t Magic

(Your boss will not all of a sudden be able to write all of your automated tests)

just an abstraction layer
Just an Abstraction Layer
  • Given – Do all of the setting up
  • When – Take the action under test
  • Then – Verify results

Match the natural language strings with regex

With a line of code that you want to run

The line of code can be anything you want; it doesn’t have to be for a functional test

for instance
For Instance

Current Code

user = owner_multiple_properties


Cucumber feature

Given I am logged in as an owner with multiple properties

Cucumber step

Given /^I am logged in as an owner(?: with )?(multiple properties|a single property)?/ do |which_owner|

user = create_owner(which_owner)


gherkin abstraction tools
Gherkin Abstraction Tools

Cucumber uses Ruby with RSpec matchers

Options are available in all languages

Cucumber, Lettuce, Robot Framework, JBehave

cucumber bdd atdd
Cucumber != BDD / ATDD

These tools are often called BDD or ATDD tools

  • Behavior Driven Development
  • Acceptance Test Driven Development

(I hate that)

Natural language abstraction is useful for many other things… Regression Tests, Smoke Tests, “Living Documentation,” etc

use vs don t use
Use vs Don’t Use
  • Cucumber is useful
    • Interface to interact with non-developers
      • Business? Management? Manual testers?
    • Distinguish Page Object unit tests (You are writing unit tests for your page objects, right?) from functional tests
    • Helps focus tests – more on this later…
  • Cucumber is not useful
    • Small set of tests
    • Too much overhead
    • Only developers will look at the tests
the problem at homeaway
The Problem at HomeAway
  • HomeAway site and features are complicated
    • Dozens of services
    • Dozens of brands with one-off features
    • Constantly adding new features
  • My Project is the Owner Dashboard
  • Slowly rolling it out by brand
    • 5 when I started
    • 8 now
  • All the manual testers were testing the entire site; One day for each brand.

(That doesn’t scale)

our approach
Our Approach
  • Updated project to Webdriver (because)
  • Hundreds of Test Cases, many written in cucumber format already by business analysts
  • Re-wrote these with an automation mindset
    • Build a vocabulary
    • Use conventions
    • Move from manual thought process to automated (One action per test)
my conventions
My conventions

Given I am logging to Test Case TC37300

And I am logged in as an owner with one property

And I am viewing recent activity for an active property listing

When I follow View Calendar link

Then I should see the current year calendar displayed

spot the issues
Spot the Issues
  • Given I am an HAO User viewing the login page
  • And I am able to log in
  • When I type “mike” in the user name field
  • And I type “test” in the password field
  • And I click the submit button
  • Then I should see a welcome popup
  • When I cancel welcome popup
  • Then I should see my property information
  • And I should see my user name
  • And The header should say “This is your Property!”
  • And I should see my reviews summary links
imperative vs declarative
Imperative vs Declarative

What does the consumers of your test care about?

-- Mike’s password?

-- How we welcome a user?

-- The content on the page?

-- The exact text of the header?

These are the most brittle kinds of tests

If this is in your Continuous Integration and your build fails as a result of one of these, are you going to roll it back and fix it?

Insist on a high bar for what gets automation

scenario log in
Scenario: Log in
  • Given I am an Owner
  • And I am viewing the Login Page
  • When I log in with good credentials
  • Then I should be logged in
  • And I should see a welcome message
scenario cancel the welcome message
Scenario: Cancel the welcome message
  • Given I am an Owner
  • And I have logged in
  • When I cancel the welcome message
  • Then I should see the Home Page
steps issues
Steps Issues

Given /^I am an? (.*)user (.*) the (.*) (modal|page)$/ do |a,b,c|

Matches things like:

“I am an awesome user automating the nifty modal that does amazing things”

scenario form submission
Scenario: Form Submission

Given I am logged in as an owner with multiple properties

And I am viewing <item_type> list page

When I submit <item_type>

Then I should see a success message



|a reservation|

|an inquiry|

|a review|

cucumber steps
Cucumber Steps

Given /^I am logged in as an owner(?: with )?(multiple properties|a single property)?/ do |which_owner|

user = which_owner.tr(‘ ‘,’_’)


Given /^I am viewing an? (reservation|inquiry|review) list page$/ do |page_type|

@action_page = “#{page_type} list”


/^When I submit an? (reservation|inquiry|review)$/ do |submit_type|

@result_page = @action_page.send(“submit_#{submit_type}”)

/^Then I should see an? (success|error) message$/ do |message_type|

@result_page.send(“is_#{message_type}_displayed?”).should be_true

  • Don’t nest steps!
    • Abstract in your PageObjects
    • It is ok to duplicate the PageObject call, the implementation of the PageObject method can change, which object and the method name “shouldn’t”
  • Be careful with complicated Regex
    • Just because you can make it work, doesn’t mean you should
  • Adapt methods to your test language, not the other way around
cuke approach improves testing
Cuke Approach Improves Testing
  • Helps enforce the idea that the test language should never change unless the business logic changes
  • Feature language informs the method names  more understandable
  • Matching vocabulary between page objects
  • Breaks the focus into concrete chunks (easier to muddle things in Rspec/xUnit type tests
  • Each chunk is ideally one line to let the Page Object do all the work
  • Really helps distingush the ‘What’ from the ‘How’