Php[tek] 2016 - BDD with Behat for Beginners

Adam Englander
Adam EnglanderDeveloper, speaker, author, IoT enthusiast and lover of all things community at ZettaFi
Php[tek] 2016 - BDD with Behat for Beginners
https://launchkey.com
W elcom e t o
p h p [ t ek ] 2 0 1 6
R a t e Ta lk s:
https://joind.in/event/phptek-2016
Tw it t er :
#phptek
W ifi :
Sheraton Meetings
https://launchkey.com
Session Breakdown
Preface (this)
Intro to BDD
Intro to Behat
Build some Tests
Selenium Server/Grid*
Sauce Labs*
Evolution of A Feature*
* Time permitting
https://launchkey.com
Who Are You?
What is your role in the development lifecycle?
What is your experience level with PHP, Behat,
and BDD?
https://launchkey.com
Pre-Run Checklist
Make sure you have:
PHP 5.5+
Composer
A browser with the Selenium driver
Selenium Server Standalone (Optional)
https://launchkey.com
Create a Project
Make a project directory
Run “composer init”
Follow the prompts
For the requirements...
https://launchkey.com
Add Your Requirements
1. Add the following
packages to your
project:
behat/behat
behat/mink-extension
behat/mink-goutte-driver
behat/mink-selenium2-
driver
2. Run “composer
install”
https://launchkey.com
Verify Your Install
Run “vendor/bin/behat -h”
You should see the help text
https://launchkey.com
Initialize Behat
Run “vendor/bin/behat --init”
Behat is initialized
Verify by running “vendor/bin/behat”
https://launchkey.com
Php[tek] 2016 - BDD with Behat for Beginners
What is BDD?
BDD is business driven, user focused, and test first.
It focuses on delivering business value as effectively
and efficiently as possible while maintaining
consistent quality throughout the entire application.
BDD is a methodology built around the principles of
lean development, extreme programming, test driven
development, and domain driven design.
https://launchkey.com
What BDD Provides
Better understanding of the business requirement for
development and QA
Better understanding of existing features for the
business
Better communication via a ubiquitous language
Real insight into the business effect of a defect
https://launchkey.com
What It Doesn’t Provide
The answer to all your problems
A replacement for unit testing
A replacement for manual testing
Super easy to implement everywhere right this second
A measure of code quality
https://launchkey.com
Failed to Assert False is True
or
How I learned to love BDD
https://launchkey.com
Php[tek] 2016 - BDD with Behat for Beginners
Stay Focused
It is crucial to the success of BDD to focus on what
value a feature provides to the business.
Always understand the the role of the user and
their relationship to the feature.
Do not get distracted by the technical aspects of
the implementation.
https://launchkey.com
Story BDD Hierarchy
Feature
Background
Scenario
Step Step
Scenario
Step Step
https://launchkey.com
Writing Features
Applications are comprised of features
BDD discretely separates each feature
Each feature contains a narrative and a scenario
Feature may also contain a background to set the
stage for the feature scenarios
https://launchkey.com
Narrative
Feature narratives are written similarly to Agile/Scrum
stories and must answer these questions:
What is the business benefit?
Who is the beneficiary?
What is the action performed?
https://launchkey.com
Background
A background should contain steps common to all, or
at least most, scenarios to prepare the application
environment for the scenarios.
Background steps should be tested elsewhere as part
of another feature.
Steps failing in the background steps will identify that
the failure is not related to the feature.
https://launchkey.com
Scenario
A scenarios should contain a narrative
Scenarios work in a manner similar to unit tests by arranging
the environment necessary to begin the test, perform
actions, and then assert that the expected results have been
attained
Scenarios should not test multiple features. Do not perform
actions after assertions.
https://launchkey.com
Scenario Outline
Scenario outlines use a common set of steps with
placeholders for data provided in a data table.
They are a replacement for multiple scenarios in which
data is the only differentiator and does not define the
feature. Adding sales tax would be an example of a
feature in which the data in the action and assertion
would be different.
https://launchkey.com
Step
Steps do one of the following:
Arrange the environment
Perform an action
Assert a result of the previous actions
Steps should be reasonably reusable
Steps should be aggregated for simplification when
arranging the environment
https://launchkey.com
Php[tek] 2016 - BDD with Behat for Beginners
What is Behat?
Open source Behavior Driven Development
framework for PHP
Official PHP implementation of Cucumber
One of the easiest Cucumber implementations to
get up and running quickly
Good documentation: http://docs.behat.org
https://launchkey.com
Installation
PHAR installation
Single global install
One version for feature contexts
Project Installation
Composer based install as dependency
Version and dependencies tied to project
https://launchkey.com
Components
Command line executable – behat
Configuration file – behat.yml
Feature context(s)
Feature Files
https://launchkey.com
CLI Executable
Allows for initializing the environment
Running features
Features and scenarios filterable by tags
Chooses environment
Listing step definitions
https://launchkey.com
Configuration File
Split up into profiles
(inherit from default)
Configures custom
autoloader path
Defines global tag filters
Defines output
formatters
Defines feature suites
Configures extensions
https://launchkey.com
Feature Context
Defines steps
May extend other contexts
May access other contexts
May add hooks for pre/post tag, step, scenario,
feature, and suite execution.
https://launchkey.com
Gherkin
Gherkin is a Domain Specific Language (DSL)
utilized to write Features in Behat. It uses key words
to identify the type of step:
Given – Arrange
When – Act
Then - Assert
https://launchkey.com
Example Gherkin
Feature: Home Page
Scenario: Login Link
Given I am on the homepage
When I click " Login"
Then I will be on the "LaunchKey | Log in" page
https://launchkey.com
Step Backing Code
Method on a feature context
Contains doc block annotated (@) matchers
Support defined in context. Defaults to Turnip
Supports Turnip and regular expressions
Can contain examples doc block
Can contain descript in the doc block
https://launchkey.com
Example Step
/**
* Opens homepage
* Example: Given I am on "/"
* Example: When I go to "/"
* Example: And I go to "/”
* @Given (I )am on :path
* @When (I )go to :path
*/
public function visitPath($path)
{
$this->browser->open($path);
}
https://launchkey.com
Let’s Get Coding!
Make sure you have:
PHP 5.5+
Composer
A browser with the Selenium driver
Selenium Server Standalone
https://launchkey.com
Create a Project
Make a project directory
Run “composer init”
Follow the prompts
For the requirements...
https://launchkey.com
Add Requirements
1. Add the following
packages to your project:
behat/behat
behat/mink-extension
behat/mink-goutte-driver
behat/mink-selenium2-
driver
2. Run “composer install”
https://launchkey.com
Verify Your Install
Run “vendor/bin/behat –h”
You should see the help text
https://launchkey.com
Initialize Behat
Run “vendor/bin/behat --init”
Behat is initialized
Verify by running “vendor/bin/behat”
https://launchkey.com
Configure Mink
default:
extensions:
BehatMinkExtension:
base_url: http://adam-bdd-with-behat.ngrok.io
goutte: ~
selenium2: ~
https://launchkey.com
Add Contexts
default:
suites:
default:
contexts:
- BehatMinkExtensionContextMinkContext
- FeatureContext
https://launchkey.com
Verify Configuration
Run “vendor/bin/behat –dl”
You should see a LOT of steps
Run “vendor/bin/behat –di”
You should see additional information for the
steps
https://launchkey.com
Lets Write A Feature
Requirement:
In order to use the site
As a site visitor
I can access the website
https://launchkey.com
Let’s Check Your Work
How did you word your narrative?
How did you word your scenario?
Did you use existing steps or do you need new
steps?
https://launchkey.com
Let’s Make Another
Requirement:
In order to be a user
As a visitor
I can register for a user account
https://launchkey.com
Add Requirements
E-Mail Address is the user identifier and must be
unique among all users
Name is required and captures the users name
Password is required and must utilize a verification
field to ensure correct password entry
https://launchkey.com
Let’s Check Your Work
How did you word your narrative?
How did you word your scenarios?
Did you use existing steps or do you need new
steps?
Did you clean up after yourself.
https://launchkey.com
Finish Up Labs
Server and Behat features found in GitHub:
https://github.com/aenglander/bdd-with-behat-for-
beginners
Master branch is Behat
Master is tagged to go step by step
Server branch is server
https://launchkey.com
Selenium
Industry standard
Server with remote API
Direct integration with Behat/Mink via Selenium
Driver
Can be used headless with PhantomJS via
GhostDriver implementation
https://launchkey.com
Using Selenium Server
Add config to bahat.yml and specify browser
BehatMinkExtension:
browser_name: chrome
goutte: ~
selenium2: ~
Apply @javascript tag to scenarios or a feature
Start Selenium Standalone Server
Run “vendor/bin/behat”
https://launchkey.com
Selenium Review
Were you able to get your server running?
Did your tests pass?
Any questions regarding Selenium Server?
https://launchkey.com
Selenium Grid
Allows for multiple simultaneous test runs, multiple
browser versions, and multiple operating systems
One Hub and Multiple Nodes
Uses same app as Standalone Server
Can be flakey and hard to manage
https://launchkey.com
Selenium Grid Example
Start hub:
selenium-server-standalone –role hub
Start nodes
selenium-server-standalone –role node –hub URL
Set the wd_host under selenium2 in behat.yml
https://launchkey.com
Hosted Selenium
Special Drivers for Sauce Labs and
BrowserStack
Not well documented but work very well
Allow for a “Grid” style environment without
managing the Grid
https://launchkey.com
Configuring Mink Driver
Poorly documented
Easy to figure out the settings by looking at the
driver factories. See:
vendor/behat/mink-
extension/src/Behat/MinkExtension/ServiceContainer
/Driver
https://launchkey.com
Best Practices
Feature files contain one Feature
Features should be more business than technical focused
Use the three A’s
Arrange – Background – Given
Act – When
Assert - Then
https://launchkey.com
Best Practices (cont.)
Make steps visually verifiable. Feature files
should be able to serve as documentation
Clean up after yourself
Scenarios should be idempotent
Spend the time to do it the right way
https://launchkey.com
Php[tek] 2016 - BDD with Behat for Beginners
Evolution of a Feature
https://launchkey.com
Business Owner
Brings a very general idea as a requirement.
Hopefully they have an idea of business priority
and impact.
This general idea is represented as a product
backlog item
https://launchkey.com
From: Big Boss
To: Project Manager
Proj,
We need a TODO list ASAP! This is top priority. Could
mean billions in revenue. Get me an estimate tomorrow!
Big
https://launchkey.com
Scrum Master/BSA
Works with the business owner to flesh out
requirements.
Requirements are very general and generic.
They are only used to determine scope and
assist with sizing during sprint planning.
https://launchkey.com
TODO list
In order to keep on track with tasks, as a user, I can
manage my tasks in a TODO list. This will be
accomplished by adding tasks to a task list and being
able to update the completion status of those tasks.
https://launchkey.com
Developer
Defines the actual user experience
Takes the very generic business requirements
and creates very specific scenarios for each
feature
Scenarios are analogous to use cases
https://launchkey.com
Feature: Task List
As an application user, in order to see my tasks, I will be presented a
ask list.
Scenario: No pre-existing tasks
As a user with no existing tasks, I will see an input field with a
placeholder value of “What needs to be done”. The footer will not be
visible.
Scenario: Pre-existing tasks
As a user with pre-existing tasks, I will see the task input fields and
below it a list of tasks in the order in which they were entered.
https://launchkey.com
Test Automation
Takes the User Experience requirements and
builds “feature” files utilizing Gherkin, the
Cucumber DSL for writing test scenarios
Scenarios will be standardized to promote
ubiquitous language conformity and step definition
re-use
Missing step definitions identified
https://launchkey.com
Feature: Task List
As an application user, in order to see my tasks, I will be presented a task
list.
Background:
Given I am on the homepage
Scenario: Pre-existing tasks shows list
Given the “Do first” task exists
And the “Do next” task exists
Then the “Do first” task is the first item in the task list
And the “Do next” task is the second item in the task list
https://launchkey.com
Feature Acceptance
The Feature files with their scenarios act as acceptance
criteria for development
Once the tests pass, the story is considered complete and
ready for demo to the product owner.
Any features/scenarios that cannot be immediately tested in
automation are tagged as such but are added regardless.
https://launchkey.com
Please Rate This Talk
https://joind.in/talk/834ba
https://launchkey.com
adam@launchkey.com
adam_englander on Twitter
#aenglander on Freenode
aenglander on GitHub
https://github.com/aenglander/bdd-with-behat-for-
beginners
https://joind.in/talk/834ba
https://launchkey.com
1 of 71

Recommended

BDD in PHP - Behat by
BDD in PHP - BehatBDD in PHP - Behat
BDD in PHP - BehatŁukasz Kużyński
4.2K views21 slides
Behat - human-readable automated testing by
Behat - human-readable automated testingBehat - human-readable automated testing
Behat - human-readable automated testingnyccamp
2K views44 slides
BDD with Behat by
BDD with BehatBDD with Behat
BDD with BehatRichard Shank
3.3K views44 slides
It's all about behaviour, also in php - phpspec by
It's all about behaviour, also in php - phpspecIt's all about behaviour, also in php - phpspec
It's all about behaviour, also in php - phpspecGiulio De Donato
5K views20 slides
BDD and Behave by
BDD and BehaveBDD and Behave
BDD and BehaveAdam Englander
1.4K views10 slides
Test Driven Development in CQ5/AEM by
Test Driven Development in CQ5/AEMTest Driven Development in CQ5/AEM
Test Driven Development in CQ5/AEMSagar Sane
2.5K views22 slides

More Related Content

What's hot

What Is Cucumber? by
What Is Cucumber?What Is Cucumber?
What Is Cucumber?QATestLab
565 views8 slides
Test your user interface using BDD (Swedish) by
Test your user interface using BDD (Swedish)Test your user interface using BDD (Swedish)
Test your user interface using BDD (Swedish)Evolve
153 views46 slides
Letter to a Junior Developer: The Engineering Side of Programming by
Letter to a Junior Developer: The Engineering Side of ProgrammingLetter to a Junior Developer: The Engineering Side of Programming
Letter to a Junior Developer: The Engineering Side of ProgrammingLazar Kovacevic
29 views46 slides
Yet Another Continuous Integration Story by
Yet Another Continuous Integration StoryYet Another Continuous Integration Story
Yet Another Continuous Integration StoryAnton Serdyuk
3.6K views67 slides
Containerized build by
Containerized buildContainerized build
Containerized buildDaniel Foo
31 views17 slides
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE by
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEGavin Pickin
95 views27 slides

What's hot(20)

What Is Cucumber? by QATestLab
What Is Cucumber?What Is Cucumber?
What Is Cucumber?
QATestLab565 views
Test your user interface using BDD (Swedish) by Evolve
Test your user interface using BDD (Swedish)Test your user interface using BDD (Swedish)
Test your user interface using BDD (Swedish)
Evolve153 views
Letter to a Junior Developer: The Engineering Side of Programming by Lazar Kovacevic
Letter to a Junior Developer: The Engineering Side of ProgrammingLetter to a Junior Developer: The Engineering Side of Programming
Letter to a Junior Developer: The Engineering Side of Programming
Lazar Kovacevic29 views
Yet Another Continuous Integration Story by Anton Serdyuk
Yet Another Continuous Integration StoryYet Another Continuous Integration Story
Yet Another Continuous Integration Story
Anton Serdyuk3.6K views
Containerized build by Daniel Foo
Containerized buildContainerized build
Containerized build
Daniel Foo31 views
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE by Gavin Pickin
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
Gavin Pickin95 views
Morden F2E Education - Think of Progressive Web Apps by Caesar Chi
Morden F2E Education - Think of Progressive Web AppsMorden F2E Education - Think of Progressive Web Apps
Morden F2E Education - Think of Progressive Web Apps
Caesar Chi657 views
Hands on BDD with cucumber - Agile Goa Sept 2013 by Sonik Chopra
Hands on BDD with cucumber -  Agile Goa Sept 2013Hands on BDD with cucumber -  Agile Goa Sept 2013
Hands on BDD with cucumber - Agile Goa Sept 2013
Sonik Chopra1.7K views
21o. RubyFloripa - Maintaining legacy Rails app and introducing Elixir by Weverton Timoteo
21o. RubyFloripa - Maintaining legacy Rails app and introducing Elixir21o. RubyFloripa - Maintaining legacy Rails app and introducing Elixir
21o. RubyFloripa - Maintaining legacy Rails app and introducing Elixir
Weverton Timoteo522 views
Productive Android developers (Meetup slides) by Michal Juhas
Productive Android developers (Meetup slides)Productive Android developers (Meetup slides)
Productive Android developers (Meetup slides)
Michal Juhas2.2K views
Meetup React Sanca - 29/11/18 - React Testing by Augusto Lazaro
Meetup React Sanca - 29/11/18 - React TestingMeetup React Sanca - 29/11/18 - React Testing
Meetup React Sanca - 29/11/18 - React Testing
Augusto Lazaro223 views
The state of Jenkins pipelines or do I still need freestyle jobs by Andrey Devyatkin
The state of Jenkins pipelines or do I still need freestyle jobsThe state of Jenkins pipelines or do I still need freestyle jobs
The state of Jenkins pipelines or do I still need freestyle jobs
Andrey Devyatkin567 views
How do we test nodejs apps? by Michal Juhas
How do we test nodejs apps?How do we test nodejs apps?
How do we test nodejs apps?
Michal Juhas561 views
Use React tools for better Angular apps by Martin Hochel
Use React tools for better Angular appsUse React tools for better Angular apps
Use React tools for better Angular apps
Martin Hochel650 views
How to go about testing in React? by Lisa Gagarina
How to go about testing in React? How to go about testing in React?
How to go about testing in React?
Lisa Gagarina967 views

Similar to Php[tek] 2016 - BDD with Behat for Beginners

PHPConf.asia 2016 - BDD with Behat for Beginners by
PHPConf.asia 2016 - BDD with Behat for BeginnersPHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for BeginnersAdam Englander
357 views51 slides
Zend con 2016 bdd with behat for beginners by
Zend con 2016   bdd with behat for beginnersZend con 2016   bdd with behat for beginners
Zend con 2016 bdd with behat for beginnersAdam Englander
279 views52 slides
M365 global developer bootcamp 2019 Intro to SPFx Version by
M365 global developer bootcamp 2019 Intro to SPFx VersionM365 global developer bootcamp 2019 Intro to SPFx Version
M365 global developer bootcamp 2019 Intro to SPFx VersionThomas Daly
164 views136 slides
BDD with Behat and Symfony2 by
BDD with Behat and Symfony2BDD with Behat and Symfony2
BDD with Behat and Symfony2katalisha
5.8K views18 slides
Automation Zaman Now by
Automation Zaman NowAutomation Zaman Now
Automation Zaman NowIbnu Fajar Yunardi
452 views24 slides
Behat sauce by
Behat sauceBehat sauce
Behat sauceShashikant Jagtap
3.2K views31 slides

Similar to Php[tek] 2016 - BDD with Behat for Beginners(20)

PHPConf.asia 2016 - BDD with Behat for Beginners by Adam Englander
PHPConf.asia 2016 - BDD with Behat for BeginnersPHPConf.asia 2016 - BDD with Behat for Beginners
PHPConf.asia 2016 - BDD with Behat for Beginners
Adam Englander357 views
Zend con 2016 bdd with behat for beginners by Adam Englander
Zend con 2016   bdd with behat for beginnersZend con 2016   bdd with behat for beginners
Zend con 2016 bdd with behat for beginners
Adam Englander279 views
M365 global developer bootcamp 2019 Intro to SPFx Version by Thomas Daly
M365 global developer bootcamp 2019 Intro to SPFx VersionM365 global developer bootcamp 2019 Intro to SPFx Version
M365 global developer bootcamp 2019 Intro to SPFx Version
Thomas Daly164 views
BDD with Behat and Symfony2 by katalisha
BDD with Behat and Symfony2BDD with Behat and Symfony2
BDD with Behat and Symfony2
katalisha5.8K views
M365 global developer bootcamp 2019 PA by Thomas Daly
M365 global developer bootcamp 2019  PAM365 global developer bootcamp 2019  PA
M365 global developer bootcamp 2019 PA
Thomas Daly152 views
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests by DECK36
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
DECK362.5K views
Getting started with spfx by Jenkins NS
Getting started with spfxGetting started with spfx
Getting started with spfx
Jenkins NS108 views
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em... by Paul Jensen
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
Paul Jensen679 views
PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition) by Joshua Warren
PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)
PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)
Joshua Warren3.4K views
M365 global developer bootcamp 2019 by Thomas Daly
M365 global developer bootcamp 2019M365 global developer bootcamp 2019
M365 global developer bootcamp 2019
Thomas Daly424 views
pnwphp - PHPSpec & Behat: Two Testing Tools That Write Code For You by Joshua Warren
pnwphp - PHPSpec & Behat: Two Testing Tools That Write Code For Youpnwphp - PHPSpec & Behat: Two Testing Tools That Write Code For You
pnwphp - PHPSpec & Behat: Two Testing Tools That Write Code For You
Joshua Warren482 views
Release with confidence by John Congdon
Release with confidenceRelease with confidence
Release with confidence
John Congdon1.8K views
Behavior & Specification Driven Development in PHP - #OpenWest by Joshua Warren
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
Joshua Warren1.4K views
Introduction to Codenvy / JugSummerCamp 2014 by Florent BENOIT
Introduction to Codenvy / JugSummerCamp 2014Introduction to Codenvy / JugSummerCamp 2014
Introduction to Codenvy / JugSummerCamp 2014
Florent BENOIT949 views
App funnel project status silver boot camp by Bethany Rentz
App funnel project status silver boot campApp funnel project status silver boot camp
App funnel project status silver boot camp
Bethany Rentz379 views
Convert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hour by Brian Culver
Convert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hourConvert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hour
Convert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hour
Brian Culver398 views

More from Adam Englander

Making PHP Smarter - Dutch PHP 2023.pptx by
Making PHP Smarter - Dutch PHP 2023.pptxMaking PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptxAdam Englander
39 views62 slides
Practical API Security - PyCon 2019 by
Practical API Security - PyCon 2019Practical API Security - PyCon 2019
Practical API Security - PyCon 2019Adam Englander
318 views84 slides
Threat Modeling for Dummies by
Threat Modeling for DummiesThreat Modeling for Dummies
Threat Modeling for DummiesAdam Englander
253 views56 slides
ZendCon 2018 - Practical API Security by
ZendCon 2018 - Practical API SecurityZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API SecurityAdam Englander
311 views77 slides
ZendCon 2018 - Cryptography in Depth by
ZendCon 2018 - Cryptography in DepthZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in DepthAdam Englander
244 views275 slides
Threat Modeling for Dummies - Cascadia PHP 2018 by
Threat Modeling for Dummies - Cascadia PHP 2018Threat Modeling for Dummies - Cascadia PHP 2018
Threat Modeling for Dummies - Cascadia PHP 2018Adam Englander
1.4K views58 slides

More from Adam Englander(20)

Making PHP Smarter - Dutch PHP 2023.pptx by Adam Englander
Making PHP Smarter - Dutch PHP 2023.pptxMaking PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptx
Adam Englander39 views
Practical API Security - PyCon 2019 by Adam Englander
Practical API Security - PyCon 2019Practical API Security - PyCon 2019
Practical API Security - PyCon 2019
Adam Englander318 views
ZendCon 2018 - Practical API Security by Adam Englander
ZendCon 2018 - Practical API SecurityZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API Security
Adam Englander311 views
ZendCon 2018 - Cryptography in Depth by Adam Englander
ZendCon 2018 - Cryptography in DepthZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in Depth
Adam Englander244 views
Threat Modeling for Dummies - Cascadia PHP 2018 by Adam Englander
Threat Modeling for Dummies - Cascadia PHP 2018Threat Modeling for Dummies - Cascadia PHP 2018
Threat Modeling for Dummies - Cascadia PHP 2018
Adam Englander1.4K views
Dutch PHP 2018 - Cryptography for Beginners by Adam Englander
Dutch PHP 2018 - Cryptography for BeginnersDutch PHP 2018 - Cryptography for Beginners
Dutch PHP 2018 - Cryptography for Beginners
Adam Englander268 views
php[tek] 2108 - Cryptography Advances in PHP 7.2 by Adam Englander
php[tek] 2108 - Cryptography Advances in PHP 7.2php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2108 - Cryptography Advances in PHP 7.2
Adam Englander246 views
php[tek] 2018 - Biometrics, fantastic failure point of the future by Adam Englander
php[tek] 2018 - Biometrics, fantastic failure point of the futurephp[tek] 2018 - Biometrics, fantastic failure point of the future
php[tek] 2018 - Biometrics, fantastic failure point of the future
Adam Englander146 views
Biometrics: Sexy, Secure and... Stupid - RSAC 2018 by Adam Englander
Biometrics: Sexy, Secure and... Stupid - RSAC 2018Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Adam Englander170 views
Practical API Security - PyCon 2018 by Adam Englander
Practical API Security - PyCon 2018Practical API Security - PyCon 2018
Practical API Security - PyCon 2018
Adam Englander600 views
Practical API Security - Midwest PHP 2018 by Adam Englander
Practical API Security - Midwest PHP 2018Practical API Security - Midwest PHP 2018
Practical API Security - Midwest PHP 2018
Adam Englander270 views
Cryptography for Beginners - Midwest PHP 2018 by Adam Englander
Cryptography for Beginners - Midwest PHP 2018Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018
Adam Englander231 views
Cryptography for Beginners - Sunshine PHP 2018 by Adam Englander
Cryptography for Beginners - Sunshine PHP 2018Cryptography for Beginners - Sunshine PHP 2018
Cryptography for Beginners - Sunshine PHP 2018
Adam Englander405 views
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future by Adam Englander
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the FutureConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
Adam Englander171 views
Con Foo 2017 - Don't Loose Sleep - Secure Your REST by Adam Englander
Con Foo 2017 - Don't Loose Sleep - Secure Your RESTCon Foo 2017 - Don't Loose Sleep - Secure Your REST
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
Adam Englander234 views
ZendCon 2017 - Cryptography for Beginners by Adam Englander
ZendCon 2017 - Cryptography for BeginnersZendCon 2017 - Cryptography for Beginners
ZendCon 2017 - Cryptography for Beginners
Adam Englander691 views
ZendCon 2017: The Red Team is Coming by Adam Englander
ZendCon 2017: The Red Team is ComingZendCon 2017: The Red Team is Coming
ZendCon 2017: The Red Team is Coming
Adam Englander327 views
ZendCon 2017 - Build a Bot Workshop - Async Primer by Adam Englander
ZendCon 2017 - Build a Bot Workshop - Async PrimerZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async Primer
Adam Englander333 views
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat by Adam Englander
Symfony Live San Franciso 2017 - BDD API Development with Symfony and BehatSymfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Adam Englander252 views

Recently uploaded

Report 2030 Digital Decade by
Report 2030 Digital DecadeReport 2030 Digital Decade
Report 2030 Digital DecadeMassimo Talia
14 views41 slides
The details of description: Techniques, tips, and tangents on alternative tex... by
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...BookNet Canada
121 views24 slides
[2023] Putting the R! in R&D.pdf by
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdfEleanor McHugh
38 views127 slides
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor... by
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...Vadym Kazulkin
75 views64 slides
AMAZON PRODUCT RESEARCH.pdf by
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdfJerikkLaureta
15 views13 slides
Attacking IoT Devices from a Web Perspective - Linux Day by
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day Simone Onofri
15 views68 slides

Recently uploaded(20)

The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada121 views
[2023] Putting the R! in R&D.pdf by Eleanor McHugh
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf
Eleanor McHugh38 views
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor... by Vadym Kazulkin
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
Vadym Kazulkin75 views
AMAZON PRODUCT RESEARCH.pdf by JerikkLaureta
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdf
JerikkLaureta15 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views
How the World's Leading Independent Automotive Distributor is Reinventing Its... by NUS-ISS
How the World's Leading Independent Automotive Distributor is Reinventing Its...How the World's Leading Independent Automotive Distributor is Reinventing Its...
How the World's Leading Independent Automotive Distributor is Reinventing Its...
NUS-ISS15 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab15 views
Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst470 views
RADIUS-Omnichannel Interaction System by RADIUS
RADIUS-Omnichannel Interaction SystemRADIUS-Omnichannel Interaction System
RADIUS-Omnichannel Interaction System
RADIUS15 views
DALI Basics Course 2023 by Ivory Egg
DALI Basics Course  2023DALI Basics Course  2023
DALI Basics Course 2023
Ivory Egg14 views
Black and White Modern Science Presentation.pptx by maryamkhalid2916
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptx
maryamkhalid291614 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb12 views
Perth MeetUp November 2023 by Michael Price
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023
Michael Price15 views
Spesifikasi Lengkap ASUS Vivobook Go 14 by Dot Semarang
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14
Dot Semarang35 views
Transcript: The Details of Description Techniques tips and tangents on altern... by BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada130 views

Php[tek] 2016 - BDD with Behat for Beginners

  • 2. https://launchkey.com W elcom e t o p h p [ t ek ] 2 0 1 6 R a t e Ta lk s: https://joind.in/event/phptek-2016 Tw it t er : #phptek W ifi : Sheraton Meetings
  • 4. Session Breakdown Preface (this) Intro to BDD Intro to Behat Build some Tests Selenium Server/Grid* Sauce Labs* Evolution of A Feature* * Time permitting https://launchkey.com
  • 5. Who Are You? What is your role in the development lifecycle? What is your experience level with PHP, Behat, and BDD? https://launchkey.com
  • 6. Pre-Run Checklist Make sure you have: PHP 5.5+ Composer A browser with the Selenium driver Selenium Server Standalone (Optional) https://launchkey.com
  • 7. Create a Project Make a project directory Run “composer init” Follow the prompts For the requirements... https://launchkey.com
  • 8. Add Your Requirements 1. Add the following packages to your project: behat/behat behat/mink-extension behat/mink-goutte-driver behat/mink-selenium2- driver 2. Run “composer install” https://launchkey.com
  • 9. Verify Your Install Run “vendor/bin/behat -h” You should see the help text https://launchkey.com
  • 10. Initialize Behat Run “vendor/bin/behat --init” Behat is initialized Verify by running “vendor/bin/behat” https://launchkey.com
  • 12. What is BDD? BDD is business driven, user focused, and test first. It focuses on delivering business value as effectively and efficiently as possible while maintaining consistent quality throughout the entire application. BDD is a methodology built around the principles of lean development, extreme programming, test driven development, and domain driven design. https://launchkey.com
  • 13. What BDD Provides Better understanding of the business requirement for development and QA Better understanding of existing features for the business Better communication via a ubiquitous language Real insight into the business effect of a defect https://launchkey.com
  • 14. What It Doesn’t Provide The answer to all your problems A replacement for unit testing A replacement for manual testing Super easy to implement everywhere right this second A measure of code quality https://launchkey.com
  • 15. Failed to Assert False is True or How I learned to love BDD https://launchkey.com
  • 17. Stay Focused It is crucial to the success of BDD to focus on what value a feature provides to the business. Always understand the the role of the user and their relationship to the feature. Do not get distracted by the technical aspects of the implementation. https://launchkey.com
  • 18. Story BDD Hierarchy Feature Background Scenario Step Step Scenario Step Step https://launchkey.com
  • 19. Writing Features Applications are comprised of features BDD discretely separates each feature Each feature contains a narrative and a scenario Feature may also contain a background to set the stage for the feature scenarios https://launchkey.com
  • 20. Narrative Feature narratives are written similarly to Agile/Scrum stories and must answer these questions: What is the business benefit? Who is the beneficiary? What is the action performed? https://launchkey.com
  • 21. Background A background should contain steps common to all, or at least most, scenarios to prepare the application environment for the scenarios. Background steps should be tested elsewhere as part of another feature. Steps failing in the background steps will identify that the failure is not related to the feature. https://launchkey.com
  • 22. Scenario A scenarios should contain a narrative Scenarios work in a manner similar to unit tests by arranging the environment necessary to begin the test, perform actions, and then assert that the expected results have been attained Scenarios should not test multiple features. Do not perform actions after assertions. https://launchkey.com
  • 23. Scenario Outline Scenario outlines use a common set of steps with placeholders for data provided in a data table. They are a replacement for multiple scenarios in which data is the only differentiator and does not define the feature. Adding sales tax would be an example of a feature in which the data in the action and assertion would be different. https://launchkey.com
  • 24. Step Steps do one of the following: Arrange the environment Perform an action Assert a result of the previous actions Steps should be reasonably reusable Steps should be aggregated for simplification when arranging the environment https://launchkey.com
  • 26. What is Behat? Open source Behavior Driven Development framework for PHP Official PHP implementation of Cucumber One of the easiest Cucumber implementations to get up and running quickly Good documentation: http://docs.behat.org https://launchkey.com
  • 27. Installation PHAR installation Single global install One version for feature contexts Project Installation Composer based install as dependency Version and dependencies tied to project https://launchkey.com
  • 28. Components Command line executable – behat Configuration file – behat.yml Feature context(s) Feature Files https://launchkey.com
  • 29. CLI Executable Allows for initializing the environment Running features Features and scenarios filterable by tags Chooses environment Listing step definitions https://launchkey.com
  • 30. Configuration File Split up into profiles (inherit from default) Configures custom autoloader path Defines global tag filters Defines output formatters Defines feature suites Configures extensions https://launchkey.com
  • 31. Feature Context Defines steps May extend other contexts May access other contexts May add hooks for pre/post tag, step, scenario, feature, and suite execution. https://launchkey.com
  • 32. Gherkin Gherkin is a Domain Specific Language (DSL) utilized to write Features in Behat. It uses key words to identify the type of step: Given – Arrange When – Act Then - Assert https://launchkey.com
  • 33. Example Gherkin Feature: Home Page Scenario: Login Link Given I am on the homepage When I click " Login" Then I will be on the "LaunchKey | Log in" page https://launchkey.com
  • 34. Step Backing Code Method on a feature context Contains doc block annotated (@) matchers Support defined in context. Defaults to Turnip Supports Turnip and regular expressions Can contain examples doc block Can contain descript in the doc block https://launchkey.com
  • 35. Example Step /** * Opens homepage * Example: Given I am on "/" * Example: When I go to "/" * Example: And I go to "/” * @Given (I )am on :path * @When (I )go to :path */ public function visitPath($path) { $this->browser->open($path); } https://launchkey.com
  • 36. Let’s Get Coding! Make sure you have: PHP 5.5+ Composer A browser with the Selenium driver Selenium Server Standalone https://launchkey.com
  • 37. Create a Project Make a project directory Run “composer init” Follow the prompts For the requirements... https://launchkey.com
  • 38. Add Requirements 1. Add the following packages to your project: behat/behat behat/mink-extension behat/mink-goutte-driver behat/mink-selenium2- driver 2. Run “composer install” https://launchkey.com
  • 39. Verify Your Install Run “vendor/bin/behat –h” You should see the help text https://launchkey.com
  • 40. Initialize Behat Run “vendor/bin/behat --init” Behat is initialized Verify by running “vendor/bin/behat” https://launchkey.com
  • 43. Verify Configuration Run “vendor/bin/behat –dl” You should see a LOT of steps Run “vendor/bin/behat –di” You should see additional information for the steps https://launchkey.com
  • 44. Lets Write A Feature Requirement: In order to use the site As a site visitor I can access the website https://launchkey.com
  • 45. Let’s Check Your Work How did you word your narrative? How did you word your scenario? Did you use existing steps or do you need new steps? https://launchkey.com
  • 46. Let’s Make Another Requirement: In order to be a user As a visitor I can register for a user account https://launchkey.com
  • 47. Add Requirements E-Mail Address is the user identifier and must be unique among all users Name is required and captures the users name Password is required and must utilize a verification field to ensure correct password entry https://launchkey.com
  • 48. Let’s Check Your Work How did you word your narrative? How did you word your scenarios? Did you use existing steps or do you need new steps? Did you clean up after yourself. https://launchkey.com
  • 49. Finish Up Labs Server and Behat features found in GitHub: https://github.com/aenglander/bdd-with-behat-for- beginners Master branch is Behat Master is tagged to go step by step Server branch is server https://launchkey.com
  • 50. Selenium Industry standard Server with remote API Direct integration with Behat/Mink via Selenium Driver Can be used headless with PhantomJS via GhostDriver implementation https://launchkey.com
  • 51. Using Selenium Server Add config to bahat.yml and specify browser BehatMinkExtension: browser_name: chrome goutte: ~ selenium2: ~ Apply @javascript tag to scenarios or a feature Start Selenium Standalone Server Run “vendor/bin/behat” https://launchkey.com
  • 52. Selenium Review Were you able to get your server running? Did your tests pass? Any questions regarding Selenium Server? https://launchkey.com
  • 53. Selenium Grid Allows for multiple simultaneous test runs, multiple browser versions, and multiple operating systems One Hub and Multiple Nodes Uses same app as Standalone Server Can be flakey and hard to manage https://launchkey.com
  • 54. Selenium Grid Example Start hub: selenium-server-standalone –role hub Start nodes selenium-server-standalone –role node –hub URL Set the wd_host under selenium2 in behat.yml https://launchkey.com
  • 55. Hosted Selenium Special Drivers for Sauce Labs and BrowserStack Not well documented but work very well Allow for a “Grid” style environment without managing the Grid https://launchkey.com
  • 56. Configuring Mink Driver Poorly documented Easy to figure out the settings by looking at the driver factories. See: vendor/behat/mink- extension/src/Behat/MinkExtension/ServiceContainer /Driver https://launchkey.com
  • 57. Best Practices Feature files contain one Feature Features should be more business than technical focused Use the three A’s Arrange – Background – Given Act – When Assert - Then https://launchkey.com
  • 58. Best Practices (cont.) Make steps visually verifiable. Feature files should be able to serve as documentation Clean up after yourself Scenarios should be idempotent Spend the time to do it the right way https://launchkey.com
  • 60. Evolution of a Feature https://launchkey.com
  • 61. Business Owner Brings a very general idea as a requirement. Hopefully they have an idea of business priority and impact. This general idea is represented as a product backlog item https://launchkey.com
  • 62. From: Big Boss To: Project Manager Proj, We need a TODO list ASAP! This is top priority. Could mean billions in revenue. Get me an estimate tomorrow! Big https://launchkey.com
  • 63. Scrum Master/BSA Works with the business owner to flesh out requirements. Requirements are very general and generic. They are only used to determine scope and assist with sizing during sprint planning. https://launchkey.com
  • 64. TODO list In order to keep on track with tasks, as a user, I can manage my tasks in a TODO list. This will be accomplished by adding tasks to a task list and being able to update the completion status of those tasks. https://launchkey.com
  • 65. Developer Defines the actual user experience Takes the very generic business requirements and creates very specific scenarios for each feature Scenarios are analogous to use cases https://launchkey.com
  • 66. Feature: Task List As an application user, in order to see my tasks, I will be presented a ask list. Scenario: No pre-existing tasks As a user with no existing tasks, I will see an input field with a placeholder value of “What needs to be done”. The footer will not be visible. Scenario: Pre-existing tasks As a user with pre-existing tasks, I will see the task input fields and below it a list of tasks in the order in which they were entered. https://launchkey.com
  • 67. Test Automation Takes the User Experience requirements and builds “feature” files utilizing Gherkin, the Cucumber DSL for writing test scenarios Scenarios will be standardized to promote ubiquitous language conformity and step definition re-use Missing step definitions identified https://launchkey.com
  • 68. Feature: Task List As an application user, in order to see my tasks, I will be presented a task list. Background: Given I am on the homepage Scenario: Pre-existing tasks shows list Given the “Do first” task exists And the “Do next” task exists Then the “Do first” task is the first item in the task list And the “Do next” task is the second item in the task list https://launchkey.com
  • 69. Feature Acceptance The Feature files with their scenarios act as acceptance criteria for development Once the tests pass, the story is considered complete and ready for demo to the product owner. Any features/scenarios that cannot be immediately tested in automation are tagged as such but are added regardless. https://launchkey.com
  • 70. Please Rate This Talk https://joind.in/talk/834ba https://launchkey.com
  • 71. adam@launchkey.com adam_englander on Twitter #aenglander on Freenode aenglander on GitHub https://github.com/aenglander/bdd-with-behat-for- beginners https://joind.in/talk/834ba https://launchkey.com

Editor's Notes

  1. The direct correlation between the SOAP box and BDD is the reason BDD is becoming more and more popular.
  2. I never meant to learn BDD. I was just looking for a tool to help me stop breaking a critical legacy business application every time we released a new feature. We had built entire integration testing platforms but they would not give me or the business what we needed to identify defects and were constantly giving false positives and negatives to the brittle nature of the tests. The first step was using feature based testing with Cucumber and then Behat when it became available. Embracing BDD, like everything else in my career, was a process of enlightenment. It took time and required pain to drive growth.