gherkin for test automation in agile
TRANSCRIPT
![Page 1: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/1.jpg)
GherkinAutomate your testing using Gherkin for
BDD
![Page 2: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/2.jpg)
About• This slide deck is about the Gherkin language which
is used to drive test automation.
![Page 3: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/3.jpg)
Aim• If you are doing Agile then it’s a no brainer to use
Gherkin to drive your automation efforts.
![Page 5: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/5.jpg)
In a nutshellFeature: Log in and out of the site.
In order to maintain an account
As a site visitor
I need to log in and out of the site.
@monsterlogin
Scenario: Logs in to the site
Given I am on "/"
When I follow "Sign In"
And I fill in "EmailAddress" with “[email protected]"
And I fill in "Password" with “MyPassword123"
And I press "Sign In"
Then I should see "Welcome Jonny"
And I should see "Jobs You Might Like"
![Page 6: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/6.jpg)
What is it?• Business readable domain specific language.
• It uses a very simple syntax.
• Tackles the business needs.
• Aims to automate the main business scenarios.
• Outside in design philosophy.
• Software practices – evolved.
• Compliments the Agile/SCRUM process.
• Starting point for test automation.
![Page 7: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/7.jpg)
What it isn’t?• It’s not a programming language.
• It’s not a unit testing tool.
• It’s got nothing to do with Kebabs
![Page 8: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/8.jpg)
What is BDD?• It stands for Behavior Driven Development.
• Think TDD – test driven development for
development driven by testing.
• Describe the behaviors and then develop to satisfy
those behaviors.
![Page 9: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/9.jpg)
BDD vs. Traditional• Test automation team usually trawl through
requirements documents and automate in similar
fashion to how developers develop. This introduces
ambiguity between how test and dev interpret
requirements.
• Usually automation is done after the developers.
• The Gherkin syntax ( acceptance criteria) is the
requirements which are deemed to be signed off
between dev, test and business.
![Page 10: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/10.jpg)
Benefits• Plain business text.
• Understood by business and developers
• Targets the business requirements.
• Significant proportion of the functional
specifications is written as user stories.
• Small command set to learn.
• Just enough living documentation
![Page 11: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/11.jpg)
Where to start?• BDD starts with a conversation between
stakeholders.
• Goal is to determine the features and derive the
acceptance criteria.
• Determine the Done.
![Page 12: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/12.jpg)
Syntax: FeatureFeature – The text acts as the high level information for
the test. Nothing gets processed.
Feature: Log in and out of the site.
In order to maintain an account
As a site visitor
I need to log in and out of the site.
![Page 13: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/13.jpg)
Syntax: BackgroundBackground – Executed before each scenario.
Background:
Given I am logged in
![Page 14: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/14.jpg)
Syntax: ScenarioScenario – Main part of the BDD feature file with test
steps.
Scenario: Logs in to the site
Given I am on "/"
When I follow "Sign In"
And I fill in "EmailAddress" with
And I fill in "Password" with “MyPassword123"
And I press "Sign In"
Then I should see "Welcome Jonny"
And I should see "Jobs You Might Like"
![Page 15: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/15.jpg)
Syntax: Scenario OutlineScenario Outline – use with examples syntax and executes the scenario multiple times.
@wip
Scenario Outline: Click through all the account pages and assert
present
Given I click on account "editProfile"
Then I should see "Contact Information"
And I follow "<account_link>"
Then I should see "<expected_text>"
Examples:
| account_link | expected_text |
| Photo | Choose a photo for your professional profile. |
| Education | Degree Level |
![Page 17: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/17.jpg)
Syntax: WhenWhen – a test step that defines the ‘action’ performed
When I follow "Sign In"
![Page 18: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/18.jpg)
Syntax: AndAnd – additional test step that defines the ‘action’
performed
And I fill in "EmailAddress" with
![Page 19: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/19.jpg)
Syntax: ThenThen – test step that defines the ‘outcome’
Then I should see "Welcome Jonny"
![Page 20: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/20.jpg)
Syntax: ButBut – additional test step that defines the ‘action’ or
‘outcome’
But I should see "Welcome Jonny"
![Page 21: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/21.jpg)
Test steps• Given , When, Then, And , But are test steps
• They can be used interchangeably. The interpreter
doesn’t care what is used however they may not
make ‘sense’ when read!
![Page 22: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/22.jpg)
TermsUser story – agile term used to describe an end to end
journey of a feature
Cucumber – term used to describe the interpreter
used to process Gherkin syntax
Tear Down – term used in automation to describe the
series of actions executed at the end of scenario
execution.
Setup – term used in automation to describe the series
of actions executed at the beginning of scenario
execution.
![Page 24: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/24.jpg)
Demo• Demo will show the Gherkin files come to life using
Behat and Mink on a PHP using Selenium Webdriver
• The files for this tutorial are stored on GITHUB
• https://github.com/VireshDoshi/behat3-mink-
website
![Page 25: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/25.jpg)
Behat and Mink• Behat is a PHP tool that interprets.
• Mink is a library that interfaces with Web Browsers.
• Mink Extensions is a library that contains useful
Gherkin steps especially designed for the web.
![Page 26: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/26.jpg)
Feature file• Out of the box, The following feature file requires minimum coding
Feature: Log in and out of the site.
In order to maintain an account
As a site visitor
I need to log in and out of the site.
@monsterlogin
Scenario: Logs in to the site
Given I am on "/"
When I follow "Sign In"
And I fill in "EmailAddress" with "[email protected]"
And I fill in "Password" with "12Xxxxxxxxx"
And I press "Sign In"
Then I should see "Welcome Simon"
And I should see "Jobs You Might Like"
![Page 27: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/27.jpg)
FeatureContext.php• This special Behat file contains the code that connects the Behat feature file to PHP code and Mink • <?php
• use Behat\Behat\Tester\Exception\PendingException;• use Behat\Behat\Context\Context;• use Behat\Behat\Context\SnippetAcceptingContext;• use Behat\Gherkin\Node\PyStringNode;• use Behat\Gherkin\Node\TableNode;• use Behat\MinkExtension\Context\MinkContext;
• /**• * Defines application features from the specific context.• */• class FeatureContext extends MinkContext implements SnippetAcceptingContext• {• /**• * Initializes context.• *• * Every scenario gets its own context instance.• * You can also pass arbitrary arguments to the• * context constructor through behat.yml.• */• public function __construct()• {• }• }
![Page 28: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/28.jpg)
Behat.yml• This special file contains setup details for Behatdefault:
extensions:
Behat\MinkExtension:
base_url: 'http://www.monster.co.uk'
browser_name: firefox
sessions:
default:
selenium2: ~
suites:
backend:
contexts:
- FeatureContext:
screen_shot_path: ./screenshot
![Page 29: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/29.jpg)
Custom stepAnd I fill in "EmailAddress" with a unique email [email protected]
/**
* @Then I fill in :arg1 with a unique email :arg2
*/
public function iFillInWithAUniqueEmail($in_field, $in_email)
{
$session = $this->getSession();
$page=$session->getPage();
$random_num=mt_rand();
$parts= explode('@',$in_email);
$user=$parts[0];
$domain=$parts[1];
$email_element=$page->find('css','#' . $in_field);
$random_email = $user . $random_num . '@' . $domain;
$email_element->setValue($random_email);
echo "generated random email = [" . $random_email . "]\n";
}
![Page 30: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/30.jpg)
Languages• All these languages are supported :
• PHP, Java, Ruby, Python, C Sharp
![Page 31: Gherkin for test automation in agile](https://reader033.vdocument.in/reader033/viewer/2022050614/58f261c61a28ab4b588b45f7/html5/thumbnails/31.jpg)
Conclusion• Technically, in 5 simple steps, BDD can be
introduced to your project.
• If you are doing Agile then it’s a no brainer to use
Gherkin to drive your automation efforts.