SlideShare a Scribd company logo
Behaviour Driven Development
using Behat
Isn’t it obvious…???
○

What test should I write next?


○

How do I know when I’ve written the last test?


○

Am I writing the right code?
BDD using behat
“

If you can't explain it simply, you
don't understand it well enough


!

Albert Einstein

”
Why BDD?
○

Write Human-readable stories that describe the behaviour of your application


○

Focuses the communication between the business and the developers


○

Code is self documenting


○

Code is easier to maintain
BEHAT
INSTALL
○

Composer


○

PHAR


○

GIT

INIT
○

mkdir Calculator

○

cd Calculator

○

behat --init

./features

/bootstrap

FeatureContext.php
Gherkins
The Basics
Feature - Gherkins
# features/BananaCalculator.features

# Describe the business value of this feature

Feature: Banana Calculator

As Bob the Banana merchant,

I want a calculator that can add the amount of bananas

so that I can know how many bananas I currently have
Scenario - Gherkins
# features/BananaCalculator.features

# Describe the business rules with scenarios

Scenario: Will add 2 banana amounts
Steps - Gherkins
# features/BananaCalculator.features

# Describe the steps

Given I have 3 Bananas

When I add 5 Bananas

Then I should have 8 Banana
Example
Feature: Banana Calculator

As Bob the Banana merchant,

I want a calculator that can add the amount of bananas

so that I can know how many bananas I currently have

Scenario: Will add 2 banana amounts

Given I have 3 Bananas

When I add 5 Bananas

Then I should have 8 Banana
BDD using behat
BDD using behat
BDD using behat
Scenario Outline
Passing Parameters and Tagging
@BeforeSuite
Managing Sub-Context
○

Context files can get really big really fast


○

Certain steps are repeated across multiple Feature files
Mink
test in browser
Mink
In order to test, that our web application behaves correctly, we need a way to simulate this
interaction between browser and web application in our tests

Mink is an open source acceptance test framework for web applications
BDD using behat
Goutte
○

Headless Browser


○

No JS support


○

Good for testing REST API
Selenium
○

JS Support

○

Can run multiple browser

○

Need to start Selenium RC

○

Not Headless

○

Need to load Drivers for different browsers

○

Doesn’t play nice at times

java -jar selenium-serverstandalone.jar

java -jar selenium-serverstandalone.jar Dwebdriver.chrome.driver=

"/usr/local/bin/chromedriver"
Sahi
○

JS Support (kinda)


○

Can run Multiple browsers


○

Need to setup localhost proxy
in browser


○

Not headless


○

Issues with Ajax Request
PhantomJS
○

JS Support


○

Headless browser


○

Pure Awesomeness


!
phantomjs --webdriver=8643
BDD using behat
DEMO
BDD Anti-Patterns
just don’t
When i fill in 'input.flooble-widgets[:first]' with 'FooBar'
○

Write BDD in the domain language


○

You should never see any DOM elements
Anti-pattern
When I subscribe to the newsletter
rather than
And I set the value of 'input#newsletter-signup-checkbox' to '1'
and
When I search for articles containing the words 'rockets'
rather than
When I fill in 'input#search-terms' with 'rockets'
And I click 'button#search-button'
And I wait 10 seconds
○

This is not a requirement


○

Roll up the execution into the page element
Try this
public function search($keywords)

{

$searchForm = $this->find('css', 'form#search');



if (!$searchForm) {

throw new ElementNotFoundException($this->getSession(), 'form', 'css', 'form#search');

}



$searchForm->fillField('q', $keywords);

$searchForm->pressButton('Google Search');



return $this->getPage('Search results');

}
IN CONCLUSION
BDD using behat
BDD & TDD = BFF
Thank you

More Related Content

PPTX
Introduce cucumber
PDF
Front-End Tooling
PPTX
Blazor - C# for the web
PPTX
Cucumber
PDF
Slim PHP when you don't need the kitchen sink
PDF
JSCS - How to Style your JavaScript Code
PDF
Magento 2 Front-end performance tips & tricks - Meet Magento Romania 2017
PPTX
Creating better behat features
Introduce cucumber
Front-End Tooling
Blazor - C# for the web
Cucumber
Slim PHP when you don't need the kitchen sink
JSCS - How to Style your JavaScript Code
Magento 2 Front-end performance tips & tricks - Meet Magento Romania 2017
Creating better behat features

What's hot (20)

PPTX
Parcel – your next web application bundler? by Janis Koselevs at FrontCon 2019
PPTX
CodePreneur Week3 - Introduction to JavaScript
PDF
Jenkins automation
PDF
Why do you use java script
PPT
Coffee script final
PPTX
PDF
Javascript testing should be awesome
PDF
Testiranje s capybaro
PDF
Unobtrusive Javascript - SD.rb 2007
PPTX
Building Responsible Wordpress Sites
DOC
Writer's quest
PDF
Mobile app real-time content modifications using websockets
PPTX
Nikhil
PPTX
Web development
PDF
Introduction to saucelabs
PDF
Chrome Dev Summit 2018 - Personal Take Aways
PPT
Lecture 6 Footnotes& Answers
PPTX
Async ... Await – concurrency in java script
PDF
Hello world web
PDF
Gulp.js & webpack
Parcel – your next web application bundler? by Janis Koselevs at FrontCon 2019
CodePreneur Week3 - Introduction to JavaScript
Jenkins automation
Why do you use java script
Coffee script final
Javascript testing should be awesome
Testiranje s capybaro
Unobtrusive Javascript - SD.rb 2007
Building Responsible Wordpress Sites
Writer's quest
Mobile app real-time content modifications using websockets
Nikhil
Web development
Introduction to saucelabs
Chrome Dev Summit 2018 - Personal Take Aways
Lecture 6 Footnotes& Answers
Async ... Await – concurrency in java script
Hello world web
Gulp.js & webpack
Ad

Viewers also liked (6)

PDF
Clean code & design patterns
PDF
Test driven development - Zombie proof your code
PDF
Domain Driven Design
PDF
Visual Design with Data
PDF
3 Things Every Sales Team Needs to Be Thinking About in 2017
PDF
How to Become a Thought Leader in Your Niche
Clean code & design patterns
Test driven development - Zombie proof your code
Domain Driven Design
Visual Design with Data
3 Things Every Sales Team Needs to Be Thinking About in 2017
How to Become a Thought Leader in Your Niche
Ad

Similar to BDD using behat (20)

PPTX
Behavioral tests with behat for qa
PPTX
Automation in Drupal
PDF
Functional testing with behat
ODP
Behat Workshop at WeLovePHP
PPTX
QA Challange Accepted - How and why we should use Behat?
PPTX
Zend con 2016 bdd with behat for beginners
PPTX
PHPConf.asia 2016 - BDD with Behat for Beginners
PPTX
BDD, Behat & Drupal
PPT
Behat sauce
PPTX
A step-by-step guide to behavior-driven development
PDF
Behat internals for advanced usage. Symfony Camp 2016
PDF
Behavioral driven development with Behat
PDF
Behat bdd training (php) course slides pdf
PDF
Behavioural Driven Development in Zf2
PPTX
Behat - human-readable automated testing
PPTX
Php[tek] 2016 - BDD with Behat for Beginners
PDF
Behavior driven development. Testing drupal using behat
PPTX
BDD in my team: how we do it
ODP
BDD with Behat
PPTX
Automate testing with behat, selenium, phantom js and nightwatch.js (5)
Behavioral tests with behat for qa
Automation in Drupal
Functional testing with behat
Behat Workshop at WeLovePHP
QA Challange Accepted - How and why we should use Behat?
Zend con 2016 bdd with behat for beginners
PHPConf.asia 2016 - BDD with Behat for Beginners
BDD, Behat & Drupal
Behat sauce
A step-by-step guide to behavior-driven development
Behat internals for advanced usage. Symfony Camp 2016
Behavioral driven development with Behat
Behat bdd training (php) course slides pdf
Behavioural Driven Development in Zf2
Behat - human-readable automated testing
Php[tek] 2016 - BDD with Behat for Beginners
Behavior driven development. Testing drupal using behat
BDD in my team: how we do it
BDD with Behat
Automate testing with behat, selenium, phantom js and nightwatch.js (5)

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Encapsulation theory and applications.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Big Data Technologies - Introduction.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Modernizing your data center with Dell and AMD
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Understanding_Digital_Forensics_Presentation.pptx
cuic standard and advanced reporting.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Encapsulation theory and applications.pdf
Machine learning based COVID-19 study performance prediction
Big Data Technologies - Introduction.pptx
The AUB Centre for AI in Media Proposal.docx
Review of recent advances in non-invasive hemoglobin estimation
20250228 LYD VKU AI Blended-Learning.pptx
NewMind AI Monthly Chronicles - July 2025
Modernizing your data center with Dell and AMD
Spectral efficient network and resource selection model in 5G networks
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Unlocking AI with Model Context Protocol (MCP)

BDD using behat