SlideShare a Scribd company logo
Copyright © 2015 spriteCloud B.V. All rights reserved.
Introduction to Cucumber with Lapis Lazuli
Getting Started with Test Automation
Copyright © 2015 spriteCloud B.V. All rights reserved.
Getting started:
This presentation will take you through the steps needed to set up a test automation
project using Cucumber - a software tool that runs automated tests in the BBD style -
in combination with Lapis Lazuli, a gem that provides Cucumber helper functions and
scaffolding for easier web test automation suite development.
To do this you will need to have installed Ruby with some drivers and libraries. You
can find detailed notes on how to do this here:
http://www.testautomation.info/Getting_Started
Copyright © 2015 spriteCloud B.V. All rights reserved.
What you need:
To successfully follow this tutorial, prior
knowledge of test automation isn’t needed, but
knowledge of scripting - especially Ruby - and
HTML skills are recommended.
Copyright © 2015 spriteCloud B.V. All rights reserved.
You will find out about:
- Gherkin
- Cucumber
- Browser testing
- Creating a TA project
- Best practices
Copyright © 2015 spriteCloud B.V. All rights reserved.
Example website
To set up this project, we will test on a
small web application as an example.
Try the following steps out at:
http://www.testautomation.info/training-page/
Note:
The web app doesn’t store information,
closing the browser window will reset the page
and created user accounts.
Copyright © 2015 spriteCloud B.V. All rights reserved.
HTML introduction
Firstly, this is HTML Structure you will
need to refer to:
<parent>
<element>
<child></child>
<child></child>
</element>
<element/>
</parent>
HTML Element:
<a id="homepage"
href="http://www.spritecloud.com">
spriteCloud
</a>
Element (node)
Attribute (node) name
Attribute (node) value
Text (node)
Copyright © 2015 spriteCloud B.V. All rights reserved.
Code examples
A very short explanation of code you
need during this training:
A variable is a label you can give to a
piece of data. Data can be simple
(numbers, text, functions) or
complex. Complex data or objects
contain variables.
Functions return data based on
certain input data.
# This is a comment
variable = "string"
variable2 = :symbol
variable3 = 1000 * 3 + 200
Object.variable
puts("Hello World!")
=> "Hello World!"
$ program "on commandline"
# Red is used as a highlight
Copyright © 2015 spriteCloud B.V. All rights reserved.
Browser testing
Install Lapis Lazuli with:
$ gem install lapis_lazuli
Run the Interactive Ruby Shell
$ irb
# Load the library
require("lapis_lazuli")
# Activate LL in this IRB session
include(LapisLazuli)
# Goto the website
browser.goto("http://www.testautomatio
n.info/training-page/")
# Print the page title
browser.title()
=> "Calliope Training"
Copyright © 2015 spriteCloud B.V. All rights reserved.
Browser testing
Finding elements on page using LL
uses the .find / .find_all function.
It allows you to do complex searches,
but today we will focus on the basics.
# Find the title
# using the unique ID attribute
browser.find("title").text()
# or the longer syntax
browser.find({:id => "title"})
# Number of links on a page
# using the element
browser.find_all(:a).length()
Copyright © 2015 spriteCloud B.V. All rights reserved.
Browser testing
Sometimes elements don’t have an
ID and you will have to use other
attributes.
# Number text fields on the page
# using attributes
browser.find_all({:like => {
:element => "input",
:attribute => "type",
:include => "text"}}
).length()
# or a short notation
browser.find_all({
:like => ["input","type","text"]
})
Copyright © 2015 spriteCloud B.V. All rights reserved.
Browser testing
Website automation requires more
interaction than loading pages and
finding elements.
Start by clicking the login button
# Find the login button
# and save it in a variable
login = browser.find({
:id => "button-login"
})
# Correct button?
login.flash()
# Click the button
login.click()
Copyright © 2015 spriteCloud B.V. All rights reserved.
Browser testing
To do a successful login we need to
enter our credentials:
# Username text field
username = browser.find({
:id => "login-username"
})
# Enter the username
username.send_keys("test")
# Repeat with password field
# Do the login
login.click()
Username test
Password test
Copyright © 2015 spriteCloud B.V. All rights reserved.
Browser testing
What happens if you try to find an
element that doesn’t exist on the
page?
# Search for not existing element
browser.find({:id => "HIDDEN"})
=> RuntimeError: Error in find -
Cannot find elements with
selectors: {:pick=>:first,
:mode=>:match_one,
:selectors=>[{:element=>"HIDDEN"}]}
(http://www.spritecloud.com/)
Copyright © 2015 spriteCloud B.V. All rights reserved.
Browser testing
The find functions allow you to set
your own custom error message to
helps non-technical users understand
the issue.
# Search for not existing element
browser.find({
:id => “HIDDEN”,
:message => “Could not find
hidden element”
})
=> RuntimeError: Could not find
hidden element - Cannot find
elements with selectors: { … }
(http://www.spritecloud.com/)
Copyright © 2015 spriteCloud B.V. All rights reserved.
Browser testing
Now try it yourself:
- Click the first todo item
- Add a todo
Or try out automating another website, like searching on Google.com
Copyright © 2015 spriteCloud B.V. All rights reserved.
Technology framework
- BDD Language to describe tests
- Test specification and execution
- Tools to improve Watir for cucumber testing
- Tools to improve WebDriver
- Browser automation
- Programming Language
- Cucumber Software-as-a-Service by spriteCloud
Lapis Lazuli
Watir
Selenium WebDriver
Ruby
Cucumber
Gherkin
Calliope
Copyright © 2015 spriteCloud B.V. All rights reserved.
Gherkin
Gherkin is the language that
Cucumber understands. It is a
Business Readable, Domain
Specific Language that lets you
describe software's behaviour without
detailing how that behaviour is
implemented. Gherkin serves two
purposes — documentation and
automated tests.
Feature: Some terse yet descriptive
text of what is desired
Scenario: Some situation
Given some precondition
And some other precondition
When some action by the actor
And some other action
And yet another action
Then some outcome is achieved
And something else we can check
Copyright © 2015 spriteCloud B.V. All rights reserved.
Gherkin
For the feature description, a three-
line user story is ideal:
● In order to <achieve goal>
● As a <role>
● I want to <activity details>
Feature: Todo Clicking
In order to complete a todo
As a test automation novice
I want to click a todo
Scenario: Regular numbers
Given I am logged in
When I click the fist todo
Then 2 todos remain
Copyright © 2015 spriteCloud B.V. All rights reserved.
Cucumber
Cucumber is a software tool that
computer programmers use for
testing other software. It runs
automated acceptance tests written
in a behavior-driven development
(BDD) style.
Given /I am logged in/ do
browser.goto
"http://www.testautomation.info/training-page/"
end
When /I click the first todo/ do
browser.find("todo-item-0").click
end
Then /(d+) todos remain/ do
|number|
browser.find("todo-remaining")
# … some extra code
end
Copyright © 2015 spriteCloud B.V. All rights reserved.
Cucumber
Given /I am logged in/ do
browser.goto
"http://www.testautomation.info/training-page/"
end
When /I click the first todo/ do
browser.find("todo-item-0").click
end
Then /(d+) todos remain/ do
|number|
browser.find("todo-remaining")
end
Feature: Todo Clicking
In order to complete a todo
As a test automation novice
I want to click a todo
Scenario: Regular numbers
Given I am logged in
When I click the fist todo
Then 2 todos remain
Copyright © 2015 spriteCloud B.V. All rights reserved.
Starting a new project
To create a project type:
$ lapis_lazuli create MyTaTraining
The project already includes an
example scenario, so lets run it:
$ cd MyTaTraining/
$ cucumber
MyTaTraining/
config/
config.yml
cucumber.yml
features/
example.feature
step_definitions/
interaction_steps.rb
validation_steps.rb
support/
env.rb
Copyright © 2015 spriteCloud B.V. All rights reserved.
Cucumber result
Let’s look at the cucumber output:
Scenario: example01 - Google Search # example.feature:8
Given I navigate to Google in english # interaction_steps.rb:6
And I search for "spriteCloud" # interaction_steps.rb:16
Then I see "www.spriteCloud.com" on the page # validation_steps.rb:6
1 scenario (1 passed)
3 steps (3 passed)
0m9.976s
Copyright © 2015 spriteCloud B.V. All rights reserved.
Cucumber result
Let’s look at the cucumber output:
Scenario: example01 - Google Search
#example.feature:8
Given I navigate to Google in english
# interaction_steps.rb:6
And I search for "spriteCloud"
# interaction_steps.rb:16
Then I see "www.spriteCloud.com" on the page
# validation_steps.rb:6
1 scenario (1 passed)
3 steps (3 passed)
0m9.976s
MyTaTraining/
config/
config.yml
cucumber.yml
features/
example.feature
step_definitions/
interaction_steps.rb
validation_steps.rb
support/
env.rb
Copyright © 2015 spriteCloud B.V. All rights reserved.
Cucumber options
By default Cucumber will run all
feature files it can find, but it has
multiple options for customized runs
Advanced:
To view all options
$ cucumber --help
# Using feature file
$ cucumber features/test.feature
# With line number
$ cucumber features/test.feature:10
# Run a single tag
$ cucumber --tags @example
# Run two tags (logical OR)
$ cucumber -t @example,@dev
# Run scenario with both tags (AND)
$ cucumber -t @example -t @dev
# Excluding a tag
$ cucumber -t ~@dev
# Check which scenarios will run
$ cucumber --dry-run
Copyright © 2015 spriteCloud B.V. All rights reserved.
TA Best practices
1. Don’t add ‘code’ to Gherkin
2. Validate if a step has been completed
3. Try to use XPath or the like and not RegExp
4. Don’t use hard timeouts
5. Work with the development team
6. Use shortest possible selector
7. Scenarios are independent
8. Keep your code clean and simple

More Related Content

What's hot (20)

PDF
BDD with cucumber
Kerry Buckley
 
KEY
SproutCore is Awesome - HTML5 Summer DevFest
tomdale
 
PDF
Implementing Testing for Behavior-Driven Development Using Cucumber
TechWell
 
PDF
A tech writer, a map, and an app
Sarah Maddox
 
PPT
Wookie Meetup
scottw
 
PDF
A Debugging Adventure: Journey through Ember.js Glue
Mike North
 
PDF
The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017
Matt Raible
 
PPT
Selenium and Cucumber Selenium Conf 2011
dimakovalenko
 
PDF
Behavior Driven Development - How To Start with Behat
imoneytech
 
PDF
Lets make a better react form
Yao Nien Chung
 
PDF
How to create OpenSocial Apps in 45 minutes
Bastian Hofmann
 
PDF
"Will Git Be Around Forever? A List of Possible Successors" at UtrechtJUG
🎤 Hanno Embregts 🎸
 
PDF
Front End Development for Back End Java Developers - NYJavaSIG 2019
Matt Raible
 
PPT
Intro to jQuery
Ralph Whitbeck
 
PDF
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...
Ho Chi Minh City Software Testing Club
 
PPT
Intro to jQuery - LUGOR - Part 1
Ralph Whitbeck
 
ODP
Developing and testing ajax components
Ignacio Coloma
 
PDF
Bootiful Development with Spring Boot and Angular - Spring I/O 2017
Matt Raible
 
PDF
Jumping Into WordPress Plugin Programming
Dougal Campbell
 
PDF
Front End Development for Back End Developers - UberConf 2017
Matt Raible
 
BDD with cucumber
Kerry Buckley
 
SproutCore is Awesome - HTML5 Summer DevFest
tomdale
 
Implementing Testing for Behavior-Driven Development Using Cucumber
TechWell
 
A tech writer, a map, and an app
Sarah Maddox
 
Wookie Meetup
scottw
 
A Debugging Adventure: Journey through Ember.js Glue
Mike North
 
The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017
Matt Raible
 
Selenium and Cucumber Selenium Conf 2011
dimakovalenko
 
Behavior Driven Development - How To Start with Behat
imoneytech
 
Lets make a better react form
Yao Nien Chung
 
How to create OpenSocial Apps in 45 minutes
Bastian Hofmann
 
"Will Git Be Around Forever? A List of Possible Successors" at UtrechtJUG
🎤 Hanno Embregts 🎸
 
Front End Development for Back End Java Developers - NYJavaSIG 2019
Matt Raible
 
Intro to jQuery
Ralph Whitbeck
 
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...
Ho Chi Minh City Software Testing Club
 
Intro to jQuery - LUGOR - Part 1
Ralph Whitbeck
 
Developing and testing ajax components
Ignacio Coloma
 
Bootiful Development with Spring Boot and Angular - Spring I/O 2017
Matt Raible
 
Jumping Into WordPress Plugin Programming
Dougal Campbell
 
Front End Development for Back End Developers - UberConf 2017
Matt Raible
 

Similar to Getting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli (20)

PDF
Software Testing
superphly
 
PPTX
End-to-end testing with geb
Jesús L. Domínguez Muriel
 
PPTX
Different Android Test Automation Frameworks - What Works You the Best?
Bitbar
 
PPTX
Continuous Quality
Stefano Galati
 
PPTX
Sst hackathon express
Aeshan Wijetunge
 
ODP
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
mguillem
 
PDF
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Ondřej Machulda
 
PPTX
An Introduction to Web Components
Red Pill Now
 
PDF
Mobile App Feature Configuration and A/B Experiments
lacyrhoades
 
PDF
End-to-end web-testing in ruby ecosystem
Alex Mikitenko
 
PDF
Automatisation in development and testing - within budget
David Lukac
 
PDF
aautoPilot
AbhishekBirdawade
 
PPTX
Testdroid:
Lingkai Shao
 
PPTX
Behat - Drupal South 2018
Berend de Boer
 
PPT
Cucumber Presentation Kiev Meet Up
dimakovalenko
 
PDF
Building Creative Product Extensions with Experience Manager
connectwebex
 
PDF
Behaviour driven infrastructure
Lindsay Holmwood
 
PDF
Behavior & Specification Driven Development in PHP - #OpenWest
Joshua Warren
 
PPTX
Building Creative Product Extensions with Experience Manager
Justin Edelson
 
KEY
iOSDevCamp 2011 - Getting "Test"-y: Test Driven Development & Automated Deplo...
Rudy Jahchan
 
Software Testing
superphly
 
End-to-end testing with geb
Jesús L. Domínguez Muriel
 
Different Android Test Automation Frameworks - What Works You the Best?
Bitbar
 
Continuous Quality
Stefano Galati
 
Sst hackathon express
Aeshan Wijetunge
 
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
mguillem
 
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Ondřej Machulda
 
An Introduction to Web Components
Red Pill Now
 
Mobile App Feature Configuration and A/B Experiments
lacyrhoades
 
End-to-end web-testing in ruby ecosystem
Alex Mikitenko
 
Automatisation in development and testing - within budget
David Lukac
 
aautoPilot
AbhishekBirdawade
 
Testdroid:
Lingkai Shao
 
Behat - Drupal South 2018
Berend de Boer
 
Cucumber Presentation Kiev Meet Up
dimakovalenko
 
Building Creative Product Extensions with Experience Manager
connectwebex
 
Behaviour driven infrastructure
Lindsay Holmwood
 
Behavior & Specification Driven Development in PHP - #OpenWest
Joshua Warren
 
Building Creative Product Extensions with Experience Manager
Justin Edelson
 
iOSDevCamp 2011 - Getting "Test"-y: Test Driven Development & Automated Deplo...
Rudy Jahchan
 
Ad

Recently uploaded (20)

PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
Executive Business Intelligence Dashboards
vandeslie24
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Executive Business Intelligence Dashboards
vandeslie24
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Ad

Getting Started with Test Automation: Introduction to Cucumber with Lapis Lazuli

  • 1. Copyright © 2015 spriteCloud B.V. All rights reserved. Introduction to Cucumber with Lapis Lazuli Getting Started with Test Automation
  • 2. Copyright © 2015 spriteCloud B.V. All rights reserved. Getting started: This presentation will take you through the steps needed to set up a test automation project using Cucumber - a software tool that runs automated tests in the BBD style - in combination with Lapis Lazuli, a gem that provides Cucumber helper functions and scaffolding for easier web test automation suite development. To do this you will need to have installed Ruby with some drivers and libraries. You can find detailed notes on how to do this here: http://www.testautomation.info/Getting_Started
  • 3. Copyright © 2015 spriteCloud B.V. All rights reserved. What you need: To successfully follow this tutorial, prior knowledge of test automation isn’t needed, but knowledge of scripting - especially Ruby - and HTML skills are recommended.
  • 4. Copyright © 2015 spriteCloud B.V. All rights reserved. You will find out about: - Gherkin - Cucumber - Browser testing - Creating a TA project - Best practices
  • 5. Copyright © 2015 spriteCloud B.V. All rights reserved. Example website To set up this project, we will test on a small web application as an example. Try the following steps out at: http://www.testautomation.info/training-page/ Note: The web app doesn’t store information, closing the browser window will reset the page and created user accounts.
  • 6. Copyright © 2015 spriteCloud B.V. All rights reserved. HTML introduction Firstly, this is HTML Structure you will need to refer to: <parent> <element> <child></child> <child></child> </element> <element/> </parent> HTML Element: <a id="homepage" href="http://www.spritecloud.com"> spriteCloud </a> Element (node) Attribute (node) name Attribute (node) value Text (node)
  • 7. Copyright © 2015 spriteCloud B.V. All rights reserved. Code examples A very short explanation of code you need during this training: A variable is a label you can give to a piece of data. Data can be simple (numbers, text, functions) or complex. Complex data or objects contain variables. Functions return data based on certain input data. # This is a comment variable = "string" variable2 = :symbol variable3 = 1000 * 3 + 200 Object.variable puts("Hello World!") => "Hello World!" $ program "on commandline" # Red is used as a highlight
  • 8. Copyright © 2015 spriteCloud B.V. All rights reserved. Browser testing Install Lapis Lazuli with: $ gem install lapis_lazuli Run the Interactive Ruby Shell $ irb # Load the library require("lapis_lazuli") # Activate LL in this IRB session include(LapisLazuli) # Goto the website browser.goto("http://www.testautomatio n.info/training-page/") # Print the page title browser.title() => "Calliope Training"
  • 9. Copyright © 2015 spriteCloud B.V. All rights reserved. Browser testing Finding elements on page using LL uses the .find / .find_all function. It allows you to do complex searches, but today we will focus on the basics. # Find the title # using the unique ID attribute browser.find("title").text() # or the longer syntax browser.find({:id => "title"}) # Number of links on a page # using the element browser.find_all(:a).length()
  • 10. Copyright © 2015 spriteCloud B.V. All rights reserved. Browser testing Sometimes elements don’t have an ID and you will have to use other attributes. # Number text fields on the page # using attributes browser.find_all({:like => { :element => "input", :attribute => "type", :include => "text"}} ).length() # or a short notation browser.find_all({ :like => ["input","type","text"] })
  • 11. Copyright © 2015 spriteCloud B.V. All rights reserved. Browser testing Website automation requires more interaction than loading pages and finding elements. Start by clicking the login button # Find the login button # and save it in a variable login = browser.find({ :id => "button-login" }) # Correct button? login.flash() # Click the button login.click()
  • 12. Copyright © 2015 spriteCloud B.V. All rights reserved. Browser testing To do a successful login we need to enter our credentials: # Username text field username = browser.find({ :id => "login-username" }) # Enter the username username.send_keys("test") # Repeat with password field # Do the login login.click() Username test Password test
  • 13. Copyright © 2015 spriteCloud B.V. All rights reserved. Browser testing What happens if you try to find an element that doesn’t exist on the page? # Search for not existing element browser.find({:id => "HIDDEN"}) => RuntimeError: Error in find - Cannot find elements with selectors: {:pick=>:first, :mode=>:match_one, :selectors=>[{:element=>"HIDDEN"}]} (http://www.spritecloud.com/)
  • 14. Copyright © 2015 spriteCloud B.V. All rights reserved. Browser testing The find functions allow you to set your own custom error message to helps non-technical users understand the issue. # Search for not existing element browser.find({ :id => “HIDDEN”, :message => “Could not find hidden element” }) => RuntimeError: Could not find hidden element - Cannot find elements with selectors: { … } (http://www.spritecloud.com/)
  • 15. Copyright © 2015 spriteCloud B.V. All rights reserved. Browser testing Now try it yourself: - Click the first todo item - Add a todo Or try out automating another website, like searching on Google.com
  • 16. Copyright © 2015 spriteCloud B.V. All rights reserved. Technology framework - BDD Language to describe tests - Test specification and execution - Tools to improve Watir for cucumber testing - Tools to improve WebDriver - Browser automation - Programming Language - Cucumber Software-as-a-Service by spriteCloud Lapis Lazuli Watir Selenium WebDriver Ruby Cucumber Gherkin Calliope
  • 17. Copyright © 2015 spriteCloud B.V. All rights reserved. Gherkin Gherkin is the language that Cucumber understands. It is a Business Readable, Domain Specific Language that lets you describe software's behaviour without detailing how that behaviour is implemented. Gherkin serves two purposes — documentation and automated tests. Feature: Some terse yet descriptive text of what is desired Scenario: Some situation Given some precondition And some other precondition When some action by the actor And some other action And yet another action Then some outcome is achieved And something else we can check
  • 18. Copyright © 2015 spriteCloud B.V. All rights reserved. Gherkin For the feature description, a three- line user story is ideal: ● In order to <achieve goal> ● As a <role> ● I want to <activity details> Feature: Todo Clicking In order to complete a todo As a test automation novice I want to click a todo Scenario: Regular numbers Given I am logged in When I click the fist todo Then 2 todos remain
  • 19. Copyright © 2015 spriteCloud B.V. All rights reserved. Cucumber Cucumber is a software tool that computer programmers use for testing other software. It runs automated acceptance tests written in a behavior-driven development (BDD) style. Given /I am logged in/ do browser.goto "http://www.testautomation.info/training-page/" end When /I click the first todo/ do browser.find("todo-item-0").click end Then /(d+) todos remain/ do |number| browser.find("todo-remaining") # … some extra code end
  • 20. Copyright © 2015 spriteCloud B.V. All rights reserved. Cucumber Given /I am logged in/ do browser.goto "http://www.testautomation.info/training-page/" end When /I click the first todo/ do browser.find("todo-item-0").click end Then /(d+) todos remain/ do |number| browser.find("todo-remaining") end Feature: Todo Clicking In order to complete a todo As a test automation novice I want to click a todo Scenario: Regular numbers Given I am logged in When I click the fist todo Then 2 todos remain
  • 21. Copyright © 2015 spriteCloud B.V. All rights reserved. Starting a new project To create a project type: $ lapis_lazuli create MyTaTraining The project already includes an example scenario, so lets run it: $ cd MyTaTraining/ $ cucumber MyTaTraining/ config/ config.yml cucumber.yml features/ example.feature step_definitions/ interaction_steps.rb validation_steps.rb support/ env.rb
  • 22. Copyright © 2015 spriteCloud B.V. All rights reserved. Cucumber result Let’s look at the cucumber output: Scenario: example01 - Google Search # example.feature:8 Given I navigate to Google in english # interaction_steps.rb:6 And I search for "spriteCloud" # interaction_steps.rb:16 Then I see "www.spriteCloud.com" on the page # validation_steps.rb:6 1 scenario (1 passed) 3 steps (3 passed) 0m9.976s
  • 23. Copyright © 2015 spriteCloud B.V. All rights reserved. Cucumber result Let’s look at the cucumber output: Scenario: example01 - Google Search #example.feature:8 Given I navigate to Google in english # interaction_steps.rb:6 And I search for "spriteCloud" # interaction_steps.rb:16 Then I see "www.spriteCloud.com" on the page # validation_steps.rb:6 1 scenario (1 passed) 3 steps (3 passed) 0m9.976s MyTaTraining/ config/ config.yml cucumber.yml features/ example.feature step_definitions/ interaction_steps.rb validation_steps.rb support/ env.rb
  • 24. Copyright © 2015 spriteCloud B.V. All rights reserved. Cucumber options By default Cucumber will run all feature files it can find, but it has multiple options for customized runs Advanced: To view all options $ cucumber --help # Using feature file $ cucumber features/test.feature # With line number $ cucumber features/test.feature:10 # Run a single tag $ cucumber --tags @example # Run two tags (logical OR) $ cucumber -t @example,@dev # Run scenario with both tags (AND) $ cucumber -t @example -t @dev # Excluding a tag $ cucumber -t ~@dev # Check which scenarios will run $ cucumber --dry-run
  • 25. Copyright © 2015 spriteCloud B.V. All rights reserved. TA Best practices 1. Don’t add ‘code’ to Gherkin 2. Validate if a step has been completed 3. Try to use XPath or the like and not RegExp 4. Don’t use hard timeouts 5. Work with the development team 6. Use shortest possible selector 7. Scenarios are independent 8. Keep your code clean and simple

Editor's Notes

  • #6: Orange : Website link
  • #7: Red highlight: .goto
  • #8: For colourblind Gijs: Blue : Class/Modules Dark Blue : Variables Green : Hardcoded values Red : Highlighting Orange : CMD Light Grey : Comment Very Light Grey : Brackets that can be removed Dark Grey : Output Brownish : Functions Black : Other Syntax
  • #9: Red highlight: .goto
  • #10: Red highlight: .find, .find_all
  • #11: Red highlight: .find, .find_all
  • #14: Red highlight: Error in find, URL
  • #15: Red highlight: Custom error message “Could not find doesnotexist”
  • #17: Dark Green : Gherkin Light Green : Cucumber Blue : Lapis Lazuli Light Blue : Watir Very Light Blue: Selenium WebDriver Red : Ruby Orange : Calliope
  • #18: Orange : Feature Blue : Scenario Red : Given Green : When Purple : Then Black : And
  • #19: Orange : Feature Blue : Scenario Red : Given Green : When Purple : Then Black : And
  • #20: Orange : Feature Blue : Scenario Dark Blue : Variables Red : Given Green : When Purple : Then
  • #21: Orange : Feature Blue : Scenario Dark Blue : Variables Red : Given Green : When Purple : Then
  • #22: Blue : config.yml => Lapis Lazuli Green : example.feature => Gherkin Light Green : cucumber.yml, *_steps.rb => Cucumber Red : env.rb => Ruby Purple : features/ => Most important folder for now
  • #23: Green : example.feature Light Green : *.rb
  • #24: Green : example.feature Light Green : *.rb Orange : Line numbers Editor walkthrough, show every file, explain parts like: example.feature what tags are new features are just plain files in features/ folder step definitions difference between interaction and validation steps interaction_steps.rb How do the steps work LL functions: has_env?, env, error, log validation_steps.rb browser.wait config files difference between configs config.yml how do environments work error strings cucumber.yml what are cucumber profiles env.rb require statements World(LapisLazuli)
  • #25: Orange : Cucumber commands
  • #26: Show slide at the end of the presentation