SlideShare a Scribd company logo
Local Touch – Global Reach
www.us.sogeti.com
The Art of Gherkin Scripting
Matthew Eakin, Manager
Managed Testing Practice
Sogeti, USA
Matthew.Eakin@us.sogeti.com
2www.us.sogeti.com
Local Touch – Global Reach
Agenda
Where did Gherkin Scripts come from?
• BDD
• The cucumber automation framework
What are Gherkin scripts?
• Given
• When
• Then
Expressive Scenarios
• Background
• Scenario Outline
• Data Tables
Gherkin script writing Tips
3www.us.sogeti.com
Local Touch – Global Reach
What is Behavior-Driven Development (BDD)?
• Dan North’s response to issue encountered teaching TDD.
– Where to start? What to test? How much to test? Tests are not tied to a business need.
• BDD is about implementing an application by describing its behavior from the
perspective of its stakeholders.
• BDD focuses on obtaining a clear understanding of desired software behavior
through discussion with stakeholders.
• A communication and collaboration framework for developers, QA, and non-
technical or business participants in a software project.
• Consists of 3 components:
– Test-Driven Development (TDD)
– Domain-Driven Design (DDD)
– Acceptance Test Driven Development(ATDD)
4www.us.sogeti.com
Local Touch – Global Reach
The Behavior-Driven Development (BDD) Timeline
5www.us.sogeti.com
Local Touch – Global Reach
The Cucumber Framework
An automated testing framework created by Aslak Hellesoy in 2008.
Based on Behavior-Driven Development.
Gherkin Scripting is used to describe the
users behavior.
Stakeholder readable–in the domain language.
6www.us.sogeti.com
Local Touch – Global Reach
What are Gherkin Scripts?
Gherkin Scripts: connects the human concept of cause and effect to the
software concept of input/process/output.
>Given – indicates something that we accept to be true in a scenario
>When – indicates the event in a scenario
>Then – indicates an expected outcome
Can also use “And” and “But” steps to help make a Given, When, or Then
more descriptive
In the “language of the domain” – scripts are written using the language, terms
and definitions of the domain.
It is “stakeholder readable” – if a script is written for business acceptance it
should be written so the business users can understand it and follow what is
happening. If a script is written for an Integration Test of a Web Service it
should be written so the developers and testers of the Web Service can
understand it and follow what is happening.
7www.us.sogeti.com
Local Touch – Global Reach
Given
The purpose of Given steps is to put the system in a known state before the user (or
external system) starts interacting with the system (in the When steps)
Indicates something that we accept to be true in a scenario
Sometimes know as preconditions
GREAT place to set-up test data
Hint: no functionality should be changing in the Given step. So…you should rarely have
an error in the Given steps.
>Examples:
Given the BadPasswordUser logs into Online Banking
And navigates to the Account History page
And selects a Premier Checking account
Given I am entitled to Initiate Payment And Payee Maintenance
And I have 1 Bill Pay account
And I have accounts entitled to Bill Pay
And I have a funding account
8www.us.sogeti.com
Local Touch – Global Reach
When
The purpose of When steps is to describe the key action the user
performs
It is what the business is requesting
It is what the developers are developing
It is what the testers are testing
The MONEY step: it is what everyone is being paid
to build & test
>Examples:
When the user Logs in
When I view the Pay Bills tab
When I select a Bill Pay account
9www.us.sogeti.com
Local Touch – Global Reach
Then
The purpose of Then steps is to observe outcomes
• The expected results of the When statement
The observations should be related to the business value/benefit in your feature
description
The observations should also be on some kind of output – that is something that
comes out of the system (report, user interface, message) and not something
that is deeply buried inside it (that has no business value)
> Examples:
Then I will see a highlighted Pay Bills tab
And I will see a header that reads "Enter Payment Criteria“
And I will see a table containing payment method icons to the left of each transaction
Then the too many characters error message appears
10www.us.sogeti.com
Local Touch – Global Reach
There is no After step
Unfortunately Gherkin scripting does not provide an elegant way to clean-up test data
or exit out of an application.
There is no “After” step.
Instead use “And…”
11www.us.sogeti.com
Local Touch – Global Reach
Backgrounds
Allow you to write part of a script to be executed before each Scenario in the
Feature File
• Allows readers to focus on what is important in the Scenario
• Can be very useful if multiple Scenarios in a Feature have same “Given” steps
Syntax:
Background: <name>
Given <action> #will be executed before each Scenario
Scenario: <name1>
When …
Then …
Scenario: <name2>
When …
Then …
12www.us.sogeti.com
Local Touch – Global Reach
Background Example
Scripts that looked like this… Becomes this…
Scenario: Wait State Message displayed for
Reference Search
Given I am logged in as a BOL user
When I view the Pay Bills tab
Then I will see a highlighted Pay Bills tab
Scenario: Wait State Message displayed for
Reaction Search
Given I am logged in as a BOL user
When I select a Bill Pay account
Then I will see a header that reads "Enter Payment
Criteria"
Background: logging in as a BOL user
Given I am logged in as a BOL user
Scenario: Wait State Message displayed for
Reference Search
When I view the Pay Bills tab
Then I will see a highlighted Pay Bills tab
Scenario: Wait State Message displayed for
Reaction Search
When I select a Bill Pay account
Then I will see a header that reads "Enter Payment
Criteria"
13www.us.sogeti.com
Local Touch – Global Reach
Scenario Outlines
Cucumber allows you to write one Gherkin Script but execute it multiple times
Use keywords to tie to an example table
Great if you have several TestCases where only variables change
Sample Code:
Scenario Outline: submit guess
Given the secret code is "<code>"
When I guess "<guess>"
Then the mark should be "<mark>"
Example:
| code | guess | mark |
| 1234 | 1234 | ++++ |
| 1234 | 1243 | ++-- |
| 1234 | 1423 | +--- |
| 1234 | 4321 | ---- |
14www.us.sogeti.com
Local Touch – Global Reach
Scenario Outline Example…
Scripts that looked like this… Becomes this…
Scenario: all numbers correct and in order
Given the secret code is “1234"
When I guess “1234"
Then the mark should be “++++"
Scenario: all numbers correct 2 in order
Given the secret code is “1234"
When I guess “1243"
Then the mark should be “++--"
Scenario: all numbers correct one in order
Given the secret code is “1234"
When I guess “1423"
Then the mark should be “+---"
Scenario: all numbers correct none in order
Given the secret code is “1234"
When I guess “4321"
Then the mark should be “----”
Scenario Outline: submit guess
Given the secret code is "<code>"
When I guess "<guess>"
Then the mark should be "<mark>"
Example: all numbers correct
| code | guess | mark |
| 1234 | 1234 | ++++ |
| 1234 | 1243 | ++-- |
| 1234 | 1423 | +--- |
| 1234 | 4321 | ---- |
15www.us.sogeti.com
Local Touch – Global Reach
Data Tables in Gherkin Scripts
Cucumber allows you to put tables directly in your Gherkin Scripts
Use a pipe “|” to separate columns in the table
Use ctrl+alt+l (lowercase letter L) to align tables in cucumber
For example:
Given I ran the Boston Marathon in 3:45
And I ran the Columbus Marathon in 3:29
And I ran the New York Marathon in 4:10
Can become:
Given I ran:
| race | time |
| Boston Marathon | 3:45 |
| Columbus Marathon | 3:29 |
| New York Marathon | 4:10 |
The Scenario becomes much clearer!!
16www.us.sogeti.com
Local Touch – Global Reach
Other ways of writing tables
Cucumber gives you the flexibility to put the table headers on the left
side…
Given I have a vehicle with the following description:
| Wheels | 2 |
| Max Speed | 60 mph |
| Accessories | lights, shopping basket |
You can also just specify a list…
Given my wife gave me the following shopping list:
| onions |
| tomatoes |
| milk |
| Fruity Pebbles |
17www.us.sogeti.com
Local Touch – Global Reach
Tips for Writing Good Gherkin Scripts
1) Start with the WHEN
2) One WHEN per scenario – single responsibility principle
3) One action per step
4) Brian Marick’s Agile Testing Quadrants/Mike Cohn’s Test
Automation Pyramid
5) Tags – a great way to organize your scripts
6) Don’t mix domains
7) Maintainability of Scripts (and Code)
8) Are any steps re-usable?
9) Do or do not, there is no try
10) Start with the conversation
11) Gherkin Scripts make great Acceptance Criteria but not a
good User Story
18www.us.sogeti.com
Local Touch – Global Reach
Tip #1: Start with the WHEN
Key question to ask: What are you trying to build/test in this scenario?
• What is the MAGIC??
• Should be stated in the Scenario Name
This becomes your WHEN step
Once you know the action, step #2 is the result (the THEN)
Last step is to figure out how to get to the WHEN
This is the functionality the business is requesting
This is what the Programmers are building
This is what the Testers are testing
19www.us.sogeti.com
Local Touch – Global Reach
Begin with the WHEN, an example…
Epic/Project: A college sports web site where you can find out all kinds of facts about
any colligate sports team.
Requirement 4: A search page for college basketball teams rosters. To display a
teams roster select the team. Columns visible are:
• Player Jersey Number
• Player Name
• Position
• Height
• Weight
• Year (Fr., Soph., Jr., Sr.)
• Hometown (Previous School)
What is the WHEN (the action)?
20www.us.sogeti.com
Local Touch – Global Reach
Example, ctd…
Test Case: Select the team and their roster will be displayed.
Gherkin Script:
Given I navigate to the web page
When I select “The Ohio State University Men’s Basketball” Team
Then I will see the following players:
| No. | Name | Pos. | Ht. | Wt. | Yr. | Hometown (Prev School)
| 0 | D'Angelo Russell | Guard | 6-5 | 180 | FR | Louisville, Ky. (Montverde Academy)
| 1 | Jae'Sean Tate | Forward | 6-4 | 190 |FR | Pickerington, Ohio (Pickerington Central)
| 2 | Marc Loving | Forward | 6-72 | 15 | SO | Toledo, Ohio (St. John Jesuit)
| 3 | Shannon Scott | Guard | 6-1 | 185 | SR | Alpharetta, Ga. (Milton)
| 10 | David Bell | Center | 6-10 | 225 | FR | Garfield Heights, Ohio (Garfield Heights)
| 12 | Sam Thompson | Forward | 6-7 | 200 | SR | Chicago, Ill. (Whitney Young)
| 15 | Kam Williams | Guard | 6-2 | 175 | RS | FR | Baltimore, Md. (Mount St. Joseph's)
| 23 | Amir Williams | Center | 6-11 | 250 | SR | Detroit, Mich. (Detroit Country Day)
21www.us.sogeti.com
Local Touch – Global Reach
Tip #2: One WHEN per Scenario
Only one WHEN per Scenario
Key testing concept: you only want to test one piece of functionality per script
• Isolate the functionality
• Isolate the issue (if any are found)
Exceptions:
• End-to-End tests
• Regression scripts
22www.us.sogeti.com
Local Touch – Global Reach
Tip #3: One action per step
You want to make sure each step does only one action.
This makes the code more maintainable & re-usable.
Problem step:
• When I enter “abc” in the username and “123” in the password and click the login
button
Better steps:
• When I enter “abc” in the username
• And I enter “123” in the password
• And I click the login button
23www.us.sogeti.com
Local Touch – Global Reach
Technology-Facing
Tip #4: Brian Marick’s Testing Quadrants
Functional/
Integration
Tests
UAT
Exploratory
Usability
Unit Tests
Component
Tests
Performance
Load
Security
Q2 Q3
Q1 Q4
SupportingTheTeam
CritiqueProduct
Business-Facing
Automated &
Manual
Automated &
Manual
Automated Tools
Rarely Use
Gherkin
Scripts
Gherkin
Acceptance
Scripts
Gherkin
Integration
Scripts
24www.us.sogeti.com
Local Touch – Global Reach
The Automation Testing Pyramid
Created by Mike Cohn in Succeeding with Agile
Essential points:
1. Unit Tests form the base of your testing strategy.
2. You should have more Unit Tests than any other kind of test.
3. There is no direct relationship between Unit and GUI tests.
25www.us.sogeti.com
Local Touch – Global Reach
Example of a UAT (Quadrant 3) Test
User Story:
As a sports fan
I need to see a roster of players on a team
So I can
Acceptance Criteria: select a team will display a roster of that team
Information: A search page for college basketball teams rosters. To display a teams roster select the
team. Columns visible are:
• Player Jersey Number
• Player Name
• Position
• Height
• Weight
• Year (Fr., Soph., Jr., Sr.)
• Hometown (Previous School)
Scenario: Select the team and their roster will be displayed.
Gherkin Acceptance Script:
Given I navigate to the web page
When I select a Team
Then I will see a roster of players
26www.us.sogeti.com
Local Touch – Global Reach
Example of an Integration (Quadrant 2) Test
Gherkin Integration Script:
Given I navigate to the web page
When I select “The Ohio State University Men’s Basketball” Team
Then I will see the following players:
| No. | Name | Pos. | Ht. | Wt. | Yr. | Hometown (Prev School)
| 0 | D'Angelo Russell | Guard | 6-5 | 180 | FR | Louisville, Ky. (Montverde Academy)
| 1 | Jae'Sean Tate | Forward | 6-4 | 190 |FR | Pickerington, Ohio (Pickerington Central)
| 2 | Marc Loving | Forward | 6-72 | 15 | SO | Toledo, Ohio (St. John Jesuit)
| 3 | Shannon Scott | Guard | 6-1 | 185 | SR | Alpharetta, Ga. (Milton)
| 10 | David Bell | Center | 6-10 | 225 | FR | Garfield Heights, Ohio (Garfield Heights)
| 12 | Sam Thompson | Forward | 6-7 | 200 | SR | Chicago, Ill. (Whitney Young)
| 15 | Kam Williams | Guard | 6-2 | 175 | RS | FR | Baltimore, Md. (Mount St. Joseph's)
| 23 | Amir Williams | Center | 6-11 | 250 | SR | Detroit, Mich. (Detroit Country Day)
27www.us.sogeti.com
Local Touch – Global Reach
Tip #5: Tags
A great way to organize your scripts
Syntax: @<text>
Example:
@acceptance @roster_display
Scenario: Team roster displayed
Given I navigate to the web page
When I select a Team
Then I will see a roster of players
@integration @roster_display
Scenario: Team roster displayed
Given I navigate to the web page
When I select “The Ohio State University Men’s Basketball” Team
Then I will see the following players:
| No. | Name | Pos. | Ht. | Wt. | Yr. | Hometown (Prev School)
| 0 | D'Angelo Russell | Guard | 6-5 | 180 | FR | Louisville, Ky. (Montverde Academy)
| 1 | Jae'Sean Tate | Forward | 6-4 | 190 |FR | Pickerington, Ohio (Pickerington Central)
| 2 | Marc Loving | Forward | 6-72 | 15 | SO | Toledo, Ohio (St. John Jesuit)
| 3 | Shannon Scott | Guard | 6-1 | 185 | SR | Alpharetta, Ga. (Milton)
| 10 | David Bell | Center | 6-10 | 225 | FR | Garfield Heights, Ohio (Garfield Heights)
| 12 | Sam Thompson | Forward | 6-7 | 200 | SR | Chicago, Ill. (Whitney Young)
| 15 | Kam Williams | Guard | 6-2 | 175 | RS | FR | Baltimore, Md. (Mount St. Joseph's)
| 23 | Amir Williams | Center | 6-11 | 250 | SR | Detroit, Mich. (Detroit Country Day)
28www.us.sogeti.com
Local Touch – Global Reach
Tip #6: Don’t mix domains
Adapted from Markus Gärtner’s Principles of ATDD blog
http://www.shino.de/2014/05/28/principles-of-atdd-single-responsibility-
principle/#more-3181
Question: What is wrong with this script?
Scenario: A simple Google search scenario
Given I am on the main Google search page
When I fill in “q” with “ATDD by example”
And I click “gbqfb” button
Then I should see “ATDD by Example: A Practical Guide to Acceptance Test-Driven
Development (Addison-Wesley Signature Series (Beck))”
Answer: The domains are mixed.
29www.us.sogeti.com
Local Touch – Global Reach
Solution…
Scenario: A simple Google search scenario
Given I am on the main Google search page
When I fill in the Search field with “ATDD by example”
Then I should see “ATDD by Example: A Practical Guide to Acceptance Test-Driven
Development (Addison-Wesley Signature Series (Beck))”
30www.us.sogeti.com
Local Touch – Global Reach
Tip #7: Is the Script (and supporting code) maintainable?
Maintainable scripts are ones that do not need to be changed if the
system changes
Goal: In the GIVEN, push the brittleness into the code and out of
your scripts so you rarely have to change it
Example of brittle Gherkin code (this is used in all 527 scripts):
Given I navigate to mattsbank.com
And I enter “matt” in the UserName field
And I enter “abc123” in the Password field
And I click the “LogIn” button
And I land on my account information page
How to make it more maintainable
Given I navigate to Online Banking
And I log in as a ValidPasswordUser
And I land on my account information page
Hardcoded URL
Hardcoded Login Information
“Soft” URL
“Soft” Login
31www.us.sogeti.com
Local Touch – Global Reach
Why is the script more maintainable?
Back-End
Apps
Objects
Step Definitions
(cucumber)
Gherkin Given a ValidPasswordUser logs into
Online Banking
Given /^…
user = User.new
on(LoginPage).login(user.valid_password)
End
Login Page
User
Information
Database
User
Password
Database
User Class
Object
PushBrittlenessDown
32www.us.sogeti.com
Local Touch – Global Reach
Tip #8: Re-Usability of Steps
Often steps will say different things but do the same thing
The fewer cucumber steps you have, the more clean your code is
• Easier to maintain
• Easier to debug
• Easier to understand
Automation can significantly help re-usability
Refactoring is a key development concept
• You want to refactor your Gherkin scripts
33www.us.sogeti.com
Local Touch – Global Reach
Tip #9: Master Yoda says…
Either a step works or it doesn’t, there is no might or should
Was: Then I should see the Wrong Account Number error message
Becomes: Then the Wrong Account Number error message is displayed
34www.us.sogeti.com
Local Touch – Global Reach
Tip #10: Start with a Conversation
There is no better way to get the language of the domain than to actually hear a
business person talk through it.
When you first talk with the business owner about a User Story/Requirement let
them talk about.
• Take good notes.
• Are there any special data or environment requirements needed? The
Given…
• What is the action they are requesting you build? The When…
• What is the result of the action? The Then…
Take these notes back and write your Gherkin scripts.
• Use as much of the actual conversation as you can.
35www.us.sogeti.com
Local Touch – Global Reach
Tip #11: Gherkin Scripts make Bad User Stories
When you write a User Story as a Gherkin script you will still have…
• I need…directly ties to the When steps in a Gherkin Script. Tells the team what
functionality needs to be built/tested.
But you will lose…
• As a…there is no place in a Gherkin Script to tell the team what persona is using
the application.
• So I can…there is no place in a Gherkin script to tell the team why this particular
change is needed. What is the business or user need? You still don’t know the
answer.
36www.us.sogeti.com
Local Touch – Global Reach
Tip #11b: Gherkin Scripts Make Great Acceptance Criteria
When you write an Acceptance Criteria as a Gherkin script you will gain…
• A clear definition of “done”…this is what the business is telling you it expects.
• A “happy path” script of what the business wants…you will now have most of
your first test script handed to you by the business.
• A solid basis for additional test cases/objectives…with a “happy path” script
already created by the business, creating test cases/objects around it becomes
much easier.
• Example:
– When I select a team
Then I will see the teams roster
www.us.sogeti.com
Local Touch – Global Reach
Thank you

More Related Content

What's hot (20)

PPSX
Quan tri Gia - Quan tri Marketing
jangvi
 
DOCX
Tiểu Luận Phân Tích Các Nhân Tố Ảnh Hưởng Đến Ngành Dệt May
Nhận Viết Đề Tài Thuê trangluanvan.com
 
PDF
MẪU LẬP DỰ ÁN NHÀ MÁY XỬ LÝ RÁC THẢI
Công ty Cổ phần Tư vấn Đầu tư Thảo Nguyên Xanh
 
DOC
Tai lieu valve by product plant
Nam Lê Thanh
 
DOC
Biện pháp đẩy mạnh tiêu thụ sản phẩm tại cty sơn tổng hợp HN
Thanh Vũ
 
DOCX
Đề Tài Tốt Nghiệp Phân Tích Khả Năng Sinh Lợi Của Công Ty
Nhận Viết Thuê Đề Tài Zalo: 0934.573.149
 
DOC
Hoàn thiện chiến lược phát triển sản phẩm mới của Công ty Bia Huế
luanvantrust
 
PDF
NGHIÊN CỨU NĂNG LỰC CẠNH TRANH CỦA TỔNG CÔNG TY BIA – RƯỢU – NƯỚC GIẢI KHÁT H...
nataliej4
 
PDF
Đề tài: Giải pháp nâng cao năng lực cạnh tranh của công ty, HAY
Dịch vụ viết bài trọn gói ZALO 0917193864
 
DOCX
XÂY DỰNG KẾ HOẠCH KINH DOANH SẢN PHẨM NATURAL SOAP ĐẾN NĂM 2023
hieu anh
 
PDF
34 kế sách kinh doanh làm giàu
Khiet Nguyen
 
DOCX
Marketing hỗn hợp tại Công ty Cổ phần Eurowindow
luanvantrust
 
DOCX
Máy chuẩn đoán
thaihoc0712
 
PDF
Đề tài: Nâng cao hiệu quả kinh doanh tại công ty thực phẩm, 9đ
Dịch Vụ Viết Bài Trọn Gói ZALO 0917193864
 
DOCX
Một Số Giải Pháp Nhằm Hoàn Thiện Công Tác Marketing Tại Công Ty
Nhận Viết Thuê Đề Tài Baocaothuctap.net/ Zalo : 0909.232.620
 
PDF
Luận văn: Dự án đầu tư xây dựng trang trại chăn nuôi lợn, HOT
Dịch vụ viết bài trọn gói ZALO: 0909232620
 
DOC
NGHIÊN CỨU SỰ TÁC ĐỘNG CỦA HỆ THỐNG ERP ĐẾN TỔ CHỨC KẾ TOÁN QUẢN TRỊ TRONG DO...
lamluanvan.net Viết thuê luận văn
 
PPT
Marketing Management - Part 4 - Consumer Behaviour
Nguyen Tung
 
DOCX
Khóa Luận Đánh Giá Kết Quả Sản Xuất Kinh Doanh Của Công Ty Gỗ.docx
Dịch vụ viết đề tài trọn gói Zalo/Tele: 0917.193.864
 
PDF
GIẢI PHÁP NÂNG CAO HIỆU QUẢ HOẠT ĐỘNG CHĂM SÓC KHÁCH HÀNG CỦA CÔNG TY TNHH TH...
Dịch vụ viết bài trọn gói ZALO 0917193864
 
Quan tri Gia - Quan tri Marketing
jangvi
 
Tiểu Luận Phân Tích Các Nhân Tố Ảnh Hưởng Đến Ngành Dệt May
Nhận Viết Đề Tài Thuê trangluanvan.com
 
MẪU LẬP DỰ ÁN NHÀ MÁY XỬ LÝ RÁC THẢI
Công ty Cổ phần Tư vấn Đầu tư Thảo Nguyên Xanh
 
Tai lieu valve by product plant
Nam Lê Thanh
 
Biện pháp đẩy mạnh tiêu thụ sản phẩm tại cty sơn tổng hợp HN
Thanh Vũ
 
Đề Tài Tốt Nghiệp Phân Tích Khả Năng Sinh Lợi Của Công Ty
Nhận Viết Thuê Đề Tài Zalo: 0934.573.149
 
Hoàn thiện chiến lược phát triển sản phẩm mới của Công ty Bia Huế
luanvantrust
 
NGHIÊN CỨU NĂNG LỰC CẠNH TRANH CỦA TỔNG CÔNG TY BIA – RƯỢU – NƯỚC GIẢI KHÁT H...
nataliej4
 
Đề tài: Giải pháp nâng cao năng lực cạnh tranh của công ty, HAY
Dịch vụ viết bài trọn gói ZALO 0917193864
 
XÂY DỰNG KẾ HOẠCH KINH DOANH SẢN PHẨM NATURAL SOAP ĐẾN NĂM 2023
hieu anh
 
34 kế sách kinh doanh làm giàu
Khiet Nguyen
 
Marketing hỗn hợp tại Công ty Cổ phần Eurowindow
luanvantrust
 
Máy chuẩn đoán
thaihoc0712
 
Đề tài: Nâng cao hiệu quả kinh doanh tại công ty thực phẩm, 9đ
Dịch Vụ Viết Bài Trọn Gói ZALO 0917193864
 
Một Số Giải Pháp Nhằm Hoàn Thiện Công Tác Marketing Tại Công Ty
Nhận Viết Thuê Đề Tài Baocaothuctap.net/ Zalo : 0909.232.620
 
Luận văn: Dự án đầu tư xây dựng trang trại chăn nuôi lợn, HOT
Dịch vụ viết bài trọn gói ZALO: 0909232620
 
NGHIÊN CỨU SỰ TÁC ĐỘNG CỦA HỆ THỐNG ERP ĐẾN TỔ CHỨC KẾ TOÁN QUẢN TRỊ TRONG DO...
lamluanvan.net Viết thuê luận văn
 
Marketing Management - Part 4 - Consumer Behaviour
Nguyen Tung
 
Khóa Luận Đánh Giá Kết Quả Sản Xuất Kinh Doanh Của Công Ty Gỗ.docx
Dịch vụ viết đề tài trọn gói Zalo/Tele: 0917.193.864
 
GIẢI PHÁP NÂNG CAO HIỆU QUẢ HOẠT ĐỘNG CHĂM SÓC KHÁCH HÀNG CỦA CÔNG TY TNHH TH...
Dịch vụ viết bài trọn gói ZALO 0917193864
 

Viewers also liked (16)

PDF
WE are Doing it Wrong - Dmitry Sharkov
QA or the Highway
 
PDF
Combinatorial software test design beyond pairwise testing
Justin Hunter
 
PPTX
The Risky Business of Testing by Shaminder Rai and Dave Patel
QA or the Highway
 
PDF
Bad metric, bad! - Joseph Ours
QA or the Highway
 
PDF
Improv(e) your testing! - Damian Synadinos
QA or the Highway
 
PPTX
STOP! You're Testing Too Much - Shawn Wallace
QA or the Highway
 
PDF
Training for Automated Testing - Kelsey Shannahan
QA or the Highway
 
PDF
Ready, set, go! - Anna Royzman
QA or the Highway
 
PDF
Feedback and its importance in delivering high quality software - Ken De Souza
QA or the Highway
 
PPTX
Cucumber From the Ground Up - Joseph Beale
QA or the Highway
 
PDF
When Cultures Collide – A tester’s story by Raj Subramanian
QA or the Highway
 
PPTX
How to bake in quality in agile scrum projects
Santanu Bhattacharya
 
PPTX
Challenging Your Project’s Testing Mindsets - Joe DeMeyer
QA or the Highway
 
PPTX
UNIT TESTING PPT
suhasreddy1
 
PPTX
Unit Testing Concepts and Best Practices
Derek Smith
 
PDF
Testing Microservices
Nathan Jones
 
WE are Doing it Wrong - Dmitry Sharkov
QA or the Highway
 
Combinatorial software test design beyond pairwise testing
Justin Hunter
 
The Risky Business of Testing by Shaminder Rai and Dave Patel
QA or the Highway
 
Bad metric, bad! - Joseph Ours
QA or the Highway
 
Improv(e) your testing! - Damian Synadinos
QA or the Highway
 
STOP! You're Testing Too Much - Shawn Wallace
QA or the Highway
 
Training for Automated Testing - Kelsey Shannahan
QA or the Highway
 
Ready, set, go! - Anna Royzman
QA or the Highway
 
Feedback and its importance in delivering high quality software - Ken De Souza
QA or the Highway
 
Cucumber From the Ground Up - Joseph Beale
QA or the Highway
 
When Cultures Collide – A tester’s story by Raj Subramanian
QA or the Highway
 
How to bake in quality in agile scrum projects
Santanu Bhattacharya
 
Challenging Your Project’s Testing Mindsets - Joe DeMeyer
QA or the Highway
 
UNIT TESTING PPT
suhasreddy1
 
Unit Testing Concepts and Best Practices
Derek Smith
 
Testing Microservices
Nathan Jones
 
Ad

Similar to The Art of Gherkin Scripting - Matt Eakin (20)

PPTX
Code instrumentation
Mennan Tekbir
 
PDF
You Put *What* in Your Stream?! Patterns and Practices for Event Design with ...
HostedbyConfluent
 
PPTX
Bdd with Cucumber and Mocha
Atish Narlawar
 
PDF
Webinar-From user stories to automated acceptance tests with BDD-Eduardo Riol
atSistemas
 
PDF
Expo qa from user stories to automated acceptance tests with bdd
Eduardo Riol
 
PDF
When Data Visualizations and Data Imports Just Don’t Work
Jim Kaplan CIA CFE
 
PDF
Acceptance tests
Dragan Tomic
 
PDF
The Art of Software Development
Arthit Hongchintakul
 
PPT
JavaScript and DOM Pattern Implementation
davejohnson
 
PDF
Moving away from legacy code with BDD
Konstantin Kudryashov
 
PPTX
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB
 
PPTX
Double Loop
Jessica Mauerhan
 
PDF
CamundaCon NYC 2023 Keynote - Shifting into overdrive with process orchestration
Bernd Ruecker
 
PPTX
MongoDB.local Dallas 2019: MongoDB Stitch Tutorial
MongoDB
 
PPTX
Xamariners - BDD + Mobile
Xamariners
 
PPTX
Bootstrapping an App for Launch
Craig Phares
 
PPTX
Behaviour driven development aka bdd
Prince Gupta
 
PDF
5/ GitHub Inner Source @ OPEN'16
Kangaroot
 
PDF
Design Patterns Every ISV Needs to Know (October 15, 2014)
Salesforce Partners
 
PDF
When e-commerce meets Symfony
Marc Morera
 
Code instrumentation
Mennan Tekbir
 
You Put *What* in Your Stream?! Patterns and Practices for Event Design with ...
HostedbyConfluent
 
Bdd with Cucumber and Mocha
Atish Narlawar
 
Webinar-From user stories to automated acceptance tests with BDD-Eduardo Riol
atSistemas
 
Expo qa from user stories to automated acceptance tests with bdd
Eduardo Riol
 
When Data Visualizations and Data Imports Just Don’t Work
Jim Kaplan CIA CFE
 
Acceptance tests
Dragan Tomic
 
The Art of Software Development
Arthit Hongchintakul
 
JavaScript and DOM Pattern Implementation
davejohnson
 
Moving away from legacy code with BDD
Konstantin Kudryashov
 
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB
 
Double Loop
Jessica Mauerhan
 
CamundaCon NYC 2023 Keynote - Shifting into overdrive with process orchestration
Bernd Ruecker
 
MongoDB.local Dallas 2019: MongoDB Stitch Tutorial
MongoDB
 
Xamariners - BDD + Mobile
Xamariners
 
Bootstrapping an App for Launch
Craig Phares
 
Behaviour driven development aka bdd
Prince Gupta
 
5/ GitHub Inner Source @ OPEN'16
Kangaroot
 
Design Patterns Every ISV Needs to Know (October 15, 2014)
Salesforce Partners
 
When e-commerce meets Symfony
Marc Morera
 
Ad

More from QA or the Highway (20)

PDF
KrishnaToolComparisionPPT.pdf
QA or the Highway
 
PPTX
Ravi Lakkavalli - World Quality Report.pptx
QA or the Highway
 
PPTX
Caleb Crandall - Testing Between the Buckets.pptx
QA or the Highway
 
PDF
Thomas Haver - Mobile Testing.pdf
QA or the Highway
 
PDF
Thomas Haver - Example Mapping.pdf
QA or the Highway
 
PDF
Joe Colantonio - Actionable Automation Awesomeness in Testing Farm.pdf
QA or the Highway
 
PDF
Sarah Geisinger - Continious Testing Metrics That Matter.pdf
QA or the Highway
 
PDF
Jeff Sing - Quarterly Service Delivery Reviews.pdf
QA or the Highway
 
PDF
Leandro Melendez - Chihuahua Load Tests.pdf
QA or the Highway
 
PDF
Rick Clymer - Incident Management.pdf
QA or the Highway
 
PPTX
Robert Fornal - ChatGPT as a Testing Tool.pptx
QA or the Highway
 
PDF
Federico Toledo - Extra-functional testing.pdf
QA or the Highway
 
PPTX
Andrew Knight - Managing the Test Data Nightmare.pptx
QA or the Highway
 
PDF
Melissa Tondi - Automation We_re Doing it Wrong.pdf
QA or the Highway
 
PDF
Jeff Van Fleet and John Townsend - Transition from Testing to Leadership.pdf
QA or the Highway
 
PPTX
DesiradhaRam Gadde - Testers _ Testing in ChatGPT-AI world.pptx
QA or the Highway
 
PDF
Damian Synadinos - Word Smatter.pdf
QA or the Highway
 
PDF
Lee Barnes - What Successful Test Automation is.pdf
QA or the Highway
 
PPTX
Jordan Powell - API Testing with Cypress.pptx
QA or the Highway
 
PPTX
Carlos Kidman - Exploring AI Applications in Testing.pptx
QA or the Highway
 
KrishnaToolComparisionPPT.pdf
QA or the Highway
 
Ravi Lakkavalli - World Quality Report.pptx
QA or the Highway
 
Caleb Crandall - Testing Between the Buckets.pptx
QA or the Highway
 
Thomas Haver - Mobile Testing.pdf
QA or the Highway
 
Thomas Haver - Example Mapping.pdf
QA or the Highway
 
Joe Colantonio - Actionable Automation Awesomeness in Testing Farm.pdf
QA or the Highway
 
Sarah Geisinger - Continious Testing Metrics That Matter.pdf
QA or the Highway
 
Jeff Sing - Quarterly Service Delivery Reviews.pdf
QA or the Highway
 
Leandro Melendez - Chihuahua Load Tests.pdf
QA or the Highway
 
Rick Clymer - Incident Management.pdf
QA or the Highway
 
Robert Fornal - ChatGPT as a Testing Tool.pptx
QA or the Highway
 
Federico Toledo - Extra-functional testing.pdf
QA or the Highway
 
Andrew Knight - Managing the Test Data Nightmare.pptx
QA or the Highway
 
Melissa Tondi - Automation We_re Doing it Wrong.pdf
QA or the Highway
 
Jeff Van Fleet and John Townsend - Transition from Testing to Leadership.pdf
QA or the Highway
 
DesiradhaRam Gadde - Testers _ Testing in ChatGPT-AI world.pptx
QA or the Highway
 
Damian Synadinos - Word Smatter.pdf
QA or the Highway
 
Lee Barnes - What Successful Test Automation is.pdf
QA or the Highway
 
Jordan Powell - API Testing with Cypress.pptx
QA or the Highway
 
Carlos Kidman - Exploring AI Applications in Testing.pptx
QA or the Highway
 

Recently uploaded (20)

PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
introduction to computer hardware and sofeware
chauhanshraddha2007
 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PPTX
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
introduction to computer hardware and sofeware
chauhanshraddha2007
 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
The Future of Artificial Intelligence (AI)
Mukul
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 

The Art of Gherkin Scripting - Matt Eakin

  • 1. Local Touch – Global Reach www.us.sogeti.com The Art of Gherkin Scripting Matthew Eakin, Manager Managed Testing Practice Sogeti, USA [email protected]
  • 2. 2www.us.sogeti.com Local Touch – Global Reach Agenda Where did Gherkin Scripts come from? • BDD • The cucumber automation framework What are Gherkin scripts? • Given • When • Then Expressive Scenarios • Background • Scenario Outline • Data Tables Gherkin script writing Tips
  • 3. 3www.us.sogeti.com Local Touch – Global Reach What is Behavior-Driven Development (BDD)? • Dan North’s response to issue encountered teaching TDD. – Where to start? What to test? How much to test? Tests are not tied to a business need. • BDD is about implementing an application by describing its behavior from the perspective of its stakeholders. • BDD focuses on obtaining a clear understanding of desired software behavior through discussion with stakeholders. • A communication and collaboration framework for developers, QA, and non- technical or business participants in a software project. • Consists of 3 components: – Test-Driven Development (TDD) – Domain-Driven Design (DDD) – Acceptance Test Driven Development(ATDD)
  • 4. 4www.us.sogeti.com Local Touch – Global Reach The Behavior-Driven Development (BDD) Timeline
  • 5. 5www.us.sogeti.com Local Touch – Global Reach The Cucumber Framework An automated testing framework created by Aslak Hellesoy in 2008. Based on Behavior-Driven Development. Gherkin Scripting is used to describe the users behavior. Stakeholder readable–in the domain language.
  • 6. 6www.us.sogeti.com Local Touch – Global Reach What are Gherkin Scripts? Gherkin Scripts: connects the human concept of cause and effect to the software concept of input/process/output. >Given – indicates something that we accept to be true in a scenario >When – indicates the event in a scenario >Then – indicates an expected outcome Can also use “And” and “But” steps to help make a Given, When, or Then more descriptive In the “language of the domain” – scripts are written using the language, terms and definitions of the domain. It is “stakeholder readable” – if a script is written for business acceptance it should be written so the business users can understand it and follow what is happening. If a script is written for an Integration Test of a Web Service it should be written so the developers and testers of the Web Service can understand it and follow what is happening.
  • 7. 7www.us.sogeti.com Local Touch – Global Reach Given The purpose of Given steps is to put the system in a known state before the user (or external system) starts interacting with the system (in the When steps) Indicates something that we accept to be true in a scenario Sometimes know as preconditions GREAT place to set-up test data Hint: no functionality should be changing in the Given step. So…you should rarely have an error in the Given steps. >Examples: Given the BadPasswordUser logs into Online Banking And navigates to the Account History page And selects a Premier Checking account Given I am entitled to Initiate Payment And Payee Maintenance And I have 1 Bill Pay account And I have accounts entitled to Bill Pay And I have a funding account
  • 8. 8www.us.sogeti.com Local Touch – Global Reach When The purpose of When steps is to describe the key action the user performs It is what the business is requesting It is what the developers are developing It is what the testers are testing The MONEY step: it is what everyone is being paid to build & test >Examples: When the user Logs in When I view the Pay Bills tab When I select a Bill Pay account
  • 9. 9www.us.sogeti.com Local Touch – Global Reach Then The purpose of Then steps is to observe outcomes • The expected results of the When statement The observations should be related to the business value/benefit in your feature description The observations should also be on some kind of output – that is something that comes out of the system (report, user interface, message) and not something that is deeply buried inside it (that has no business value) > Examples: Then I will see a highlighted Pay Bills tab And I will see a header that reads "Enter Payment Criteria“ And I will see a table containing payment method icons to the left of each transaction Then the too many characters error message appears
  • 10. 10www.us.sogeti.com Local Touch – Global Reach There is no After step Unfortunately Gherkin scripting does not provide an elegant way to clean-up test data or exit out of an application. There is no “After” step. Instead use “And…”
  • 11. 11www.us.sogeti.com Local Touch – Global Reach Backgrounds Allow you to write part of a script to be executed before each Scenario in the Feature File • Allows readers to focus on what is important in the Scenario • Can be very useful if multiple Scenarios in a Feature have same “Given” steps Syntax: Background: <name> Given <action> #will be executed before each Scenario Scenario: <name1> When … Then … Scenario: <name2> When … Then …
  • 12. 12www.us.sogeti.com Local Touch – Global Reach Background Example Scripts that looked like this… Becomes this… Scenario: Wait State Message displayed for Reference Search Given I am logged in as a BOL user When I view the Pay Bills tab Then I will see a highlighted Pay Bills tab Scenario: Wait State Message displayed for Reaction Search Given I am logged in as a BOL user When I select a Bill Pay account Then I will see a header that reads "Enter Payment Criteria" Background: logging in as a BOL user Given I am logged in as a BOL user Scenario: Wait State Message displayed for Reference Search When I view the Pay Bills tab Then I will see a highlighted Pay Bills tab Scenario: Wait State Message displayed for Reaction Search When I select a Bill Pay account Then I will see a header that reads "Enter Payment Criteria"
  • 13. 13www.us.sogeti.com Local Touch – Global Reach Scenario Outlines Cucumber allows you to write one Gherkin Script but execute it multiple times Use keywords to tie to an example table Great if you have several TestCases where only variables change Sample Code: Scenario Outline: submit guess Given the secret code is "<code>" When I guess "<guess>" Then the mark should be "<mark>" Example: | code | guess | mark | | 1234 | 1234 | ++++ | | 1234 | 1243 | ++-- | | 1234 | 1423 | +--- | | 1234 | 4321 | ---- |
  • 14. 14www.us.sogeti.com Local Touch – Global Reach Scenario Outline Example… Scripts that looked like this… Becomes this… Scenario: all numbers correct and in order Given the secret code is “1234" When I guess “1234" Then the mark should be “++++" Scenario: all numbers correct 2 in order Given the secret code is “1234" When I guess “1243" Then the mark should be “++--" Scenario: all numbers correct one in order Given the secret code is “1234" When I guess “1423" Then the mark should be “+---" Scenario: all numbers correct none in order Given the secret code is “1234" When I guess “4321" Then the mark should be “----” Scenario Outline: submit guess Given the secret code is "<code>" When I guess "<guess>" Then the mark should be "<mark>" Example: all numbers correct | code | guess | mark | | 1234 | 1234 | ++++ | | 1234 | 1243 | ++-- | | 1234 | 1423 | +--- | | 1234 | 4321 | ---- |
  • 15. 15www.us.sogeti.com Local Touch – Global Reach Data Tables in Gherkin Scripts Cucumber allows you to put tables directly in your Gherkin Scripts Use a pipe “|” to separate columns in the table Use ctrl+alt+l (lowercase letter L) to align tables in cucumber For example: Given I ran the Boston Marathon in 3:45 And I ran the Columbus Marathon in 3:29 And I ran the New York Marathon in 4:10 Can become: Given I ran: | race | time | | Boston Marathon | 3:45 | | Columbus Marathon | 3:29 | | New York Marathon | 4:10 | The Scenario becomes much clearer!!
  • 16. 16www.us.sogeti.com Local Touch – Global Reach Other ways of writing tables Cucumber gives you the flexibility to put the table headers on the left side… Given I have a vehicle with the following description: | Wheels | 2 | | Max Speed | 60 mph | | Accessories | lights, shopping basket | You can also just specify a list… Given my wife gave me the following shopping list: | onions | | tomatoes | | milk | | Fruity Pebbles |
  • 17. 17www.us.sogeti.com Local Touch – Global Reach Tips for Writing Good Gherkin Scripts 1) Start with the WHEN 2) One WHEN per scenario – single responsibility principle 3) One action per step 4) Brian Marick’s Agile Testing Quadrants/Mike Cohn’s Test Automation Pyramid 5) Tags – a great way to organize your scripts 6) Don’t mix domains 7) Maintainability of Scripts (and Code) 8) Are any steps re-usable? 9) Do or do not, there is no try 10) Start with the conversation 11) Gherkin Scripts make great Acceptance Criteria but not a good User Story
  • 18. 18www.us.sogeti.com Local Touch – Global Reach Tip #1: Start with the WHEN Key question to ask: What are you trying to build/test in this scenario? • What is the MAGIC?? • Should be stated in the Scenario Name This becomes your WHEN step Once you know the action, step #2 is the result (the THEN) Last step is to figure out how to get to the WHEN This is the functionality the business is requesting This is what the Programmers are building This is what the Testers are testing
  • 19. 19www.us.sogeti.com Local Touch – Global Reach Begin with the WHEN, an example… Epic/Project: A college sports web site where you can find out all kinds of facts about any colligate sports team. Requirement 4: A search page for college basketball teams rosters. To display a teams roster select the team. Columns visible are: • Player Jersey Number • Player Name • Position • Height • Weight • Year (Fr., Soph., Jr., Sr.) • Hometown (Previous School) What is the WHEN (the action)?
  • 20. 20www.us.sogeti.com Local Touch – Global Reach Example, ctd… Test Case: Select the team and their roster will be displayed. Gherkin Script: Given I navigate to the web page When I select “The Ohio State University Men’s Basketball” Team Then I will see the following players: | No. | Name | Pos. | Ht. | Wt. | Yr. | Hometown (Prev School) | 0 | D'Angelo Russell | Guard | 6-5 | 180 | FR | Louisville, Ky. (Montverde Academy) | 1 | Jae'Sean Tate | Forward | 6-4 | 190 |FR | Pickerington, Ohio (Pickerington Central) | 2 | Marc Loving | Forward | 6-72 | 15 | SO | Toledo, Ohio (St. John Jesuit) | 3 | Shannon Scott | Guard | 6-1 | 185 | SR | Alpharetta, Ga. (Milton) | 10 | David Bell | Center | 6-10 | 225 | FR | Garfield Heights, Ohio (Garfield Heights) | 12 | Sam Thompson | Forward | 6-7 | 200 | SR | Chicago, Ill. (Whitney Young) | 15 | Kam Williams | Guard | 6-2 | 175 | RS | FR | Baltimore, Md. (Mount St. Joseph's) | 23 | Amir Williams | Center | 6-11 | 250 | SR | Detroit, Mich. (Detroit Country Day)
  • 21. 21www.us.sogeti.com Local Touch – Global Reach Tip #2: One WHEN per Scenario Only one WHEN per Scenario Key testing concept: you only want to test one piece of functionality per script • Isolate the functionality • Isolate the issue (if any are found) Exceptions: • End-to-End tests • Regression scripts
  • 22. 22www.us.sogeti.com Local Touch – Global Reach Tip #3: One action per step You want to make sure each step does only one action. This makes the code more maintainable & re-usable. Problem step: • When I enter “abc” in the username and “123” in the password and click the login button Better steps: • When I enter “abc” in the username • And I enter “123” in the password • And I click the login button
  • 23. 23www.us.sogeti.com Local Touch – Global Reach Technology-Facing Tip #4: Brian Marick’s Testing Quadrants Functional/ Integration Tests UAT Exploratory Usability Unit Tests Component Tests Performance Load Security Q2 Q3 Q1 Q4 SupportingTheTeam CritiqueProduct Business-Facing Automated & Manual Automated & Manual Automated Tools Rarely Use Gherkin Scripts Gherkin Acceptance Scripts Gherkin Integration Scripts
  • 24. 24www.us.sogeti.com Local Touch – Global Reach The Automation Testing Pyramid Created by Mike Cohn in Succeeding with Agile Essential points: 1. Unit Tests form the base of your testing strategy. 2. You should have more Unit Tests than any other kind of test. 3. There is no direct relationship between Unit and GUI tests.
  • 25. 25www.us.sogeti.com Local Touch – Global Reach Example of a UAT (Quadrant 3) Test User Story: As a sports fan I need to see a roster of players on a team So I can Acceptance Criteria: select a team will display a roster of that team Information: A search page for college basketball teams rosters. To display a teams roster select the team. Columns visible are: • Player Jersey Number • Player Name • Position • Height • Weight • Year (Fr., Soph., Jr., Sr.) • Hometown (Previous School) Scenario: Select the team and their roster will be displayed. Gherkin Acceptance Script: Given I navigate to the web page When I select a Team Then I will see a roster of players
  • 26. 26www.us.sogeti.com Local Touch – Global Reach Example of an Integration (Quadrant 2) Test Gherkin Integration Script: Given I navigate to the web page When I select “The Ohio State University Men’s Basketball” Team Then I will see the following players: | No. | Name | Pos. | Ht. | Wt. | Yr. | Hometown (Prev School) | 0 | D'Angelo Russell | Guard | 6-5 | 180 | FR | Louisville, Ky. (Montverde Academy) | 1 | Jae'Sean Tate | Forward | 6-4 | 190 |FR | Pickerington, Ohio (Pickerington Central) | 2 | Marc Loving | Forward | 6-72 | 15 | SO | Toledo, Ohio (St. John Jesuit) | 3 | Shannon Scott | Guard | 6-1 | 185 | SR | Alpharetta, Ga. (Milton) | 10 | David Bell | Center | 6-10 | 225 | FR | Garfield Heights, Ohio (Garfield Heights) | 12 | Sam Thompson | Forward | 6-7 | 200 | SR | Chicago, Ill. (Whitney Young) | 15 | Kam Williams | Guard | 6-2 | 175 | RS | FR | Baltimore, Md. (Mount St. Joseph's) | 23 | Amir Williams | Center | 6-11 | 250 | SR | Detroit, Mich. (Detroit Country Day)
  • 27. 27www.us.sogeti.com Local Touch – Global Reach Tip #5: Tags A great way to organize your scripts Syntax: @<text> Example: @acceptance @roster_display Scenario: Team roster displayed Given I navigate to the web page When I select a Team Then I will see a roster of players @integration @roster_display Scenario: Team roster displayed Given I navigate to the web page When I select “The Ohio State University Men’s Basketball” Team Then I will see the following players: | No. | Name | Pos. | Ht. | Wt. | Yr. | Hometown (Prev School) | 0 | D'Angelo Russell | Guard | 6-5 | 180 | FR | Louisville, Ky. (Montverde Academy) | 1 | Jae'Sean Tate | Forward | 6-4 | 190 |FR | Pickerington, Ohio (Pickerington Central) | 2 | Marc Loving | Forward | 6-72 | 15 | SO | Toledo, Ohio (St. John Jesuit) | 3 | Shannon Scott | Guard | 6-1 | 185 | SR | Alpharetta, Ga. (Milton) | 10 | David Bell | Center | 6-10 | 225 | FR | Garfield Heights, Ohio (Garfield Heights) | 12 | Sam Thompson | Forward | 6-7 | 200 | SR | Chicago, Ill. (Whitney Young) | 15 | Kam Williams | Guard | 6-2 | 175 | RS | FR | Baltimore, Md. (Mount St. Joseph's) | 23 | Amir Williams | Center | 6-11 | 250 | SR | Detroit, Mich. (Detroit Country Day)
  • 28. 28www.us.sogeti.com Local Touch – Global Reach Tip #6: Don’t mix domains Adapted from Markus Gärtner’s Principles of ATDD blog http://www.shino.de/2014/05/28/principles-of-atdd-single-responsibility- principle/#more-3181 Question: What is wrong with this script? Scenario: A simple Google search scenario Given I am on the main Google search page When I fill in “q” with “ATDD by example” And I click “gbqfb” button Then I should see “ATDD by Example: A Practical Guide to Acceptance Test-Driven Development (Addison-Wesley Signature Series (Beck))” Answer: The domains are mixed.
  • 29. 29www.us.sogeti.com Local Touch – Global Reach Solution… Scenario: A simple Google search scenario Given I am on the main Google search page When I fill in the Search field with “ATDD by example” Then I should see “ATDD by Example: A Practical Guide to Acceptance Test-Driven Development (Addison-Wesley Signature Series (Beck))”
  • 30. 30www.us.sogeti.com Local Touch – Global Reach Tip #7: Is the Script (and supporting code) maintainable? Maintainable scripts are ones that do not need to be changed if the system changes Goal: In the GIVEN, push the brittleness into the code and out of your scripts so you rarely have to change it Example of brittle Gherkin code (this is used in all 527 scripts): Given I navigate to mattsbank.com And I enter “matt” in the UserName field And I enter “abc123” in the Password field And I click the “LogIn” button And I land on my account information page How to make it more maintainable Given I navigate to Online Banking And I log in as a ValidPasswordUser And I land on my account information page Hardcoded URL Hardcoded Login Information “Soft” URL “Soft” Login
  • 31. 31www.us.sogeti.com Local Touch – Global Reach Why is the script more maintainable? Back-End Apps Objects Step Definitions (cucumber) Gherkin Given a ValidPasswordUser logs into Online Banking Given /^… user = User.new on(LoginPage).login(user.valid_password) End Login Page User Information Database User Password Database User Class Object PushBrittlenessDown
  • 32. 32www.us.sogeti.com Local Touch – Global Reach Tip #8: Re-Usability of Steps Often steps will say different things but do the same thing The fewer cucumber steps you have, the more clean your code is • Easier to maintain • Easier to debug • Easier to understand Automation can significantly help re-usability Refactoring is a key development concept • You want to refactor your Gherkin scripts
  • 33. 33www.us.sogeti.com Local Touch – Global Reach Tip #9: Master Yoda says… Either a step works or it doesn’t, there is no might or should Was: Then I should see the Wrong Account Number error message Becomes: Then the Wrong Account Number error message is displayed
  • 34. 34www.us.sogeti.com Local Touch – Global Reach Tip #10: Start with a Conversation There is no better way to get the language of the domain than to actually hear a business person talk through it. When you first talk with the business owner about a User Story/Requirement let them talk about. • Take good notes. • Are there any special data or environment requirements needed? The Given… • What is the action they are requesting you build? The When… • What is the result of the action? The Then… Take these notes back and write your Gherkin scripts. • Use as much of the actual conversation as you can.
  • 35. 35www.us.sogeti.com Local Touch – Global Reach Tip #11: Gherkin Scripts make Bad User Stories When you write a User Story as a Gherkin script you will still have… • I need…directly ties to the When steps in a Gherkin Script. Tells the team what functionality needs to be built/tested. But you will lose… • As a…there is no place in a Gherkin Script to tell the team what persona is using the application. • So I can…there is no place in a Gherkin script to tell the team why this particular change is needed. What is the business or user need? You still don’t know the answer.
  • 36. 36www.us.sogeti.com Local Touch – Global Reach Tip #11b: Gherkin Scripts Make Great Acceptance Criteria When you write an Acceptance Criteria as a Gherkin script you will gain… • A clear definition of “done”…this is what the business is telling you it expects. • A “happy path” script of what the business wants…you will now have most of your first test script handed to you by the business. • A solid basis for additional test cases/objectives…with a “happy path” script already created by the business, creating test cases/objects around it becomes much easier. • Example: – When I select a team Then I will see the teams roster
  • 37. www.us.sogeti.com Local Touch – Global Reach Thank you