SlideShare a Scribd company logo
1 of 66
PHPDAY 2013, VERONA
Automated acceptance testing with Behat and Mink
&
Saturday, May 18, 13
LET ME INTRODUCE MYSELF
• @Richard_Tuin
• Software developer from the Netherlands
• Particular interest in QA
• Working for
Saturday, May 18, 13
INEFFICIENCY
• Different view on scope and resulting product
• Clients don’t get a feel of how they will use the product
• “I like what you’ve built, but it doesn’t do what i meant”
• “Thanks for this new feature, but now x stopped working!”
Saturday, May 18, 13
INEFFICIENCY
• Different view on scope and resulting product
• Clients don’t get a feel of how they will use the product
• “I like what you’ve built, but it doesn’t do what i meant”
• “Thanks for this new feature, but now x stopped working!”
Saturday, May 18, 13
BECAUSE
• ... the dev team and the client have the same goal
• ... we want to know that what we build has value
• ... we want to deliver consistent quality
Saturday, May 18, 13
BUTTHERE’S ANOTHER
PROBLEM...
Saturday, May 18, 13
Developers are lazy
Saturday, May 18, 13
SOTHIS MEANS...
• ... we have to focus more on communication
• ... leave no room for misinterpretation
• ... we have to work together with the client
• ... we got to have a system
• ... we have to validate regularly if what we have built is still
according to acceptance criteria
Saturday, May 18, 13
SOTHIS MEANS...
• ... we have to focus more on communication
• ... leave no room for misinterpretation
• ... we have to work together with the client
• ... we got to have a system
• ... we have to validate regularly if what we have built is still
according to acceptance criteria
Automation?
Saturday, May 18, 13
WORKTOGETHER & DOCUMENTTOGETHER
Saturday, May 18, 13
AUTOMATETHEVALIDATION
AGAINST ACCEPTANCE
CRITERIA
Documentation
Saturday, May 18, 13
SO... HOW?
Saturday, May 18, 13
ITERATIVE
is the keyword
Saturday, May 18, 13
ITERATIVE
“Gradually get to the highest value.”
Saturday, May 18, 13
ITERATIVE SOFTWARE
DEVELOPMENT
Saturday, May 18, 13
WRITING REQUIREMENTS
• Describe how a problem will be solved
• Write them together with your client
• In the (technical) language of the client
• Try to describe the functional problem, not the technical one
Saturday, May 18, 13
WRITE EXAMPLES!
They will reduce misinterpretation and illustrate the result
Saturday, May 18, 13
FEATURE FILE LAYOUT
Feature: {feature description}
{intention}
As a {person}
I want {feature}
So that {intention}
Scenario: {specific scenario description}
Given {context}
And {more context}
When {action}
Then {result}
Scenario: ...
Information: http://dannorth.net/whats-in-a-story/
Saturday, May 18, 13
EXAMPLE FEATURE
Feature: Searching on the internet
As a google.com visitor
I want to use the search engine
So that i can find information on the internet
Scenario: Simple keyword search
Given I am on the homepage
When I fill in the search term “PHP”
And I press “Google search”
Then I should see search results containing “PHP”
Scenario: I feel lucky
Given I am on the homepage
When I fill in the search term “PHP”
And I press “I’m feeling lucky”
Then I should not be on google.com
And I should see “PHP”
Saturday, May 18, 13
STEPS? (TERMINOLOGY)
Feature: {feature description}
{intention}
As a {person}
I want {feature}
So that {intention}
Scenario: {specific scenario description}
Given {context}
And {more context}
When {action}
Then {result}
Scenario: ...
Saturday, May 18, 13
STEPS? (TERMINOLOGY)
Feature: {feature description}
{intention}
As a {person}
I want {feature}
So that {intention}
Scenario: {specific scenario description}
Given {context}
And {more context}
When {action}
Then {result}
Scenario: ...
Feature, user story, module
Saturday, May 18, 13
STEPS? (TERMINOLOGY)
Feature: {feature description}
{intention}
As a {person}
I want {feature}
So that {intention}
Scenario: {specific scenario description}
Given {context}
And {more context}
When {action}
Then {result}
Scenario: ...
Feature, user story, module
Scenario
Saturday, May 18, 13
STEPS? (TERMINOLOGY)
Feature: {feature description}
{intention}
As a {person}
I want {feature}
So that {intention}
Scenario: {specific scenario description}
Given {context}
And {more context}
When {action}
Then {result}
Scenario: ...
Feature, user story, module
Scenario
Steps
Saturday, May 18, 13
LIVING DOCUMENTATION
• All features and scenarios make great documentation!
• A change request starts with rewriting documentation
• Easy to see what functionality the application contains
• Easy to get a feel for the impact of a change
• Easy to get a new team member involved
Saturday, May 18, 13
COMMUNICATION IS KEY
Automation is not the focus
Saturday, May 18, 13
Developers are lazy
Saturday, May 18, 13
AUTOMATION
Makes us happy :-)
Saturday, May 18, 13
“A php framework for testing your business expectations.”
-behat.org
Saturday, May 18, 13
“Mink is an open source acceptance test framework for web
applications, written in PHP 5.3.”
Saturday, May 18, 13
+
Saturday, May 18, 13
+
AWESOME
Saturday, May 18, 13
COMPONENTS OF A BEHAT+MINK
FUNCTIONALTEST SUITE
• Features
• Feature parser
• Generic browser controller client
• Browser controller/simulator
• Executable code that controls the browser controller client
Saturday, May 18, 13
COMPONENTS OF A BEHAT+MINK
FUNCTIONALTEST SUITE
• Features
• Feature parser
• Generic browser controller client
• Browser controller/simulator
• Executable code that controls the browser controller client
Living documentation
Saturday, May 18, 13
COMPONENTS OF A BEHAT+MINK
FUNCTIONALTEST SUITE
• Features
• Feature parser
• Generic browser controller client
• Browser controller/simulator
• Executable code that controls the browser controller client
Living documentation
Behat
Saturday, May 18, 13
COMPONENTS OF A BEHAT+MINK
FUNCTIONALTEST SUITE
• Features
• Feature parser
• Generic browser controller client
• Browser controller/simulator
• Executable code that controls the browser controller client
Living documentation
Behat
Mink
Saturday, May 18, 13
COMPONENTS OF A BEHAT+MINK
FUNCTIONALTEST SUITE
• Features
• Feature parser
• Generic browser controller client
• Browser controller/simulator
• Executable code that controls the browser controller client
Living documentation
Behat
Mink
Selenium, Zombie.js, Goutte,
etc.
Saturday, May 18, 13
COMPONENTS OF A BEHAT+MINK
FUNCTIONALTEST SUITE
• Features
• Feature parser
• Generic browser controller client
• Browser controller/simulator
• Executable code that controls the browser controller client
Living documentation
Behat
Mink
Selenium, Zombie.js, Goutte,
etc.
MinkExtension
Saturday, May 18, 13
1. Using Composer or Phar
$ composer install
{
"require": {
"behat/behat": "*",
"behat/mink": "*",
"behat/mink-extension": "*",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium2-driver": "*"
},
"minimum-stability": "dev",
"config": {
"bin-dir": "bin/"
}
}
INSTALLING BEHAT+MINK
Saturday, May 18, 13
1. Using Composer or Phar
$ composer install
{
"require": {
"behat/behat": "*",
"behat/mink": "*",
"behat/mink-extension": "*",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium2-driver": "*"
},
"minimum-stability": "dev",
"config": {
"bin-dir": "bin/"
}
}
INSTALLING BEHAT+MINK
That’s it!
Saturday, May 18, 13
HELLO BEHAT
1. Initialize a Behat testsuite skeleton
$ bin/behat --init
2. Behat creates it’s standard project structure
Saturday, May 18, 13
MINKEXTENSION
1. Bridges the gap between Behat and Mink
2. Contains a set of predefined step definitions
3. Not all step definitions may be usable for all projects
4. Behat + Mink is easy:
use BehatMinkExtensionContextMinkContext;
class FeatureContext extends MinkContext
{
// ...
}
features/FeatureContext.php
Saturday, May 18, 13
MINKEXTENSION STEPS
Given /^(?:|I )am on (?:|the )homepage$/
When /^(?:|I )go to (?:|the )homepage$/
Given /^(?:|I )am on "(?P<page>[^"]+)"$/
When /^(?:|I )fill in "(?P<field>(?:[^"]|")*)" with "(?P<value>(?:[^"]|")*)"$/
When /^(?:|I )press "(?P<button>(?:[^"]|")*)"$/
When /^(?:|I )follow "(?P<link>(?:[^"]|")*)"$/
Then /^(?:|I )should be on "(?P<page>[^"]+)"$/
Then /^(?:|I )should see "(?P<text>(?:[^"]|")*)"$/
$ bin/behat -dl
/**
* Clicks link with specified id|title|alt|text.
*
* @When /^(?:|I )follow "(?P<link>(?:[^"]|")*)"$/
*/
public function clickLink($link)
{
$link = $this->fixStepArgument($link);
$this->getSession()->getPage()->clickLink($link);
}
Saturday, May 18, 13
BEHAT.YML
• Place for configuration options
• Basic Behat / Mink config
default:
extensions:
BehatMinkExtensionExtension:
base_url: "http://www.yourwebsite.com"
goutte: ~
selenium2: ~
Saturday, May 18, 13
EXAMPLE FEATURE
Saturday, May 18, 13
EXAMPLE FEATURE
Feature: Search on the internet
As a google.com visitor
I want to use the search engine
So that i can find information on the internet
Scenario: Simple keyword search
Given I am on the homepage
When I fill in the search term “PHP”
And I press “Google search”
Then I should see search results containing “PHP”
features/search.feature
Saturday, May 18, 13
STEP DEFINITIONS
/**
* @When /^I fill in the search term "([^"]*)"$/
*/
public function iSearchTheTerm($arg1)
{
throw new PendingException();
}
Put these in your FeatureContext.php file.
$ bin/behat
Running Behat
Behat gives you step suggestions:
Saturday, May 18, 13
WRITING STEP DEFINITIONS
/**
* @When /^I search the term "([^"]*)"$/
*/
public function iSearchTheTerm($searchTerm)
{
$this->fillField('q', $searchTerm); // method from MinkExtension
$this->pressButton('Google search');
}
Saturday, May 18, 13
MINKTERMINOLOGY
• Driver = Browser controller/emulator
• Session = Browser
• Page = Document(Element)
• Element
• Selectors
• XPath
• CSS
• Named
Saturday, May 18, 13
RUNNING IT
Saturday, May 18, 13
PAGE/DOCUMENTTRAVERSAL
• Selection of elements on a page
• Selectors based on XPath, CSS, Names
$page = $this->getPage();
$elements = $page->findAll('xpath', './/div[@class="sa_mc"]');
$elements = $page->findAll('css', 'div[class="sa_mc"]');
Saturday, May 18, 13
ELEMENT ACTIONS
$page = $this->getSession()->getPage();
$loginLink = $page->find('css', '#login');
$loginLink->click();
->getValue();
->setValue();
->keyUp();
->press();
etcetera...
Saturday, May 18, 13
OTHER FEATURES
Great to get started
Saturday, May 18, 13
PROFILES
• Full configuration per environment
• Feature / Scenario selection based on filters
• Define them in behat.yml:
• Call the profile with: $ bin/behat --profile acceptance
default:
extension:
BehatMinkExtensionContextMinkContext
base_url: “http://www.example.org”
acceptance:
extension:
BehatMinkExtensionContextMinkContext
base_url: “http://acc.example.org”
Saturday, May 18, 13
TAGS
• Metadata for features and scenarios
• Via command line: $ bin/behat --tags “@smoke”
• Define as filter in profile
@smoke
Feature: Search on the www
@javascript
Scenario: ...
search.feature
smoke:
filters:
tags: “@smoke”
behat.yml
nojs:
filters:
tags: “~@javascript”
behat.yml
Saturday, May 18, 13
FILTERS
• Grouping tests
• Tags
• Configuration in behat.yml
smoketests:
filters:
tags: “@smoketest&&~@wip”
development:
filters:
tags: “~@slow&&~@wip”
Saturday, May 18, 13
BROWSER CONTROLLERS
Javascript Speed Remark
Goutte No ++ Emulator
Selenium2 Yes -
Zombie.js Yes +
Saturday, May 18, 13
SCENARIO OUTLINES
Scenario Outline: Simple keyword search
Given I am on the homepage
When I search the term <searchterm>
Then I should see search results containing <searchterm>
Examples:
| searchterm |
| PHP |
| Java |
| Pie |
| This string is possibly too long and uncommon |
Saturday, May 18, 13
DRIVER BENCHMARK
Goutte 2.736ms
Selenium2 16.682ms
Zombie.js 7.533ms
0 5,000 10,000 15,000 20,000
Goutte Selenium2 Zombie.js
Saturday, May 18, 13
HOOKS
• @beforeSuite
• @beforeFeature
• @beforeScenario
• @beforeStep
• @afterSuite
• @afterFeature
• @afterScenario
• @afterStep
Saturday, May 18, 13
HOOKS
• @beforeSuite
• @beforeFeature
• @beforeScenario
• @beforeStep
• @afterSuite
• @afterFeature
• @afterScenario
• @afterStep
Saturday, May 18, 13
HOOK EXAMPLE
/**
* @afterScenario
*/
public function logoutUser()
{
$this->visit('/logout');
}
features/bootstrap/FeatureContext.php
Saturday, May 18, 13
LOCALIZATION
• Write features in your own language
# language: it
Funzionalità: non so scrivere italiano
Scenario: ...
Dato ...
Quando ...
Allora ...
Schema dello scenario: ...
Dato ...
Quando ...
Allora ...
Esempi:
...
Saturday, May 18, 13
INTEGRATION WITH JENKINS
• Behat includes export to jUnit format
• Jenkins build step example
${WORKSPACE}/bin/behat --format junit --out ${WORKSPACE}/build
Saturday, May 18, 13
CONCLUSION
1. Writing examples is great to improve communication
2. Automating acceptance criteria = consistent quality
3. Behat and Mink are an excellent combination to do this
Saturday, May 18, 13
QUESTIONS?
Saturday, May 18, 13
THANKYOU!
• Feedback: http://joind.in/talk/view/8647
• More questions? Contact me, i love this subject!
• @Richard_Tuin
• richardtuin@gmail.com
• skype: richardtuin
Saturday, May 18, 13

More Related Content

Similar to Phpday - Automated acceptance testing with Behat and Mink

Intro to Ember.js
Intro to Ember.jsIntro to Ember.js
Intro to Ember.jsJay Phelps
 
DIY Synthetic: Private WebPagetest Magic
DIY Synthetic: Private WebPagetest MagicDIY Synthetic: Private WebPagetest Magic
DIY Synthetic: Private WebPagetest MagicJonathan Klein
 
Monitoring Behavioral Driven Infrastructures mit Cucumber-Nagios by Mike Adolphs
Monitoring Behavioral Driven Infrastructures mit Cucumber-Nagios by Mike AdolphsMonitoring Behavioral Driven Infrastructures mit Cucumber-Nagios by Mike Adolphs
Monitoring Behavioral Driven Infrastructures mit Cucumber-Nagios by Mike AdolphsNETWAYS
 
Mobile App Feature Configuration and A/B Experiments
Mobile App Feature Configuration and A/B ExperimentsMobile App Feature Configuration and A/B Experiments
Mobile App Feature Configuration and A/B Experimentslacyrhoades
 
Scaling PHP to 40 Million Uniques
Scaling PHP to 40 Million UniquesScaling PHP to 40 Million Uniques
Scaling PHP to 40 Million UniquesJonathan Klein
 
GraphQL Without a Database | Frontend Developer Love
GraphQL Without a Database | Frontend Developer LoveGraphQL Without a Database | Frontend Developer Love
GraphQL Without a Database | Frontend Developer LoveRoy Derks
 
Teaching Programming Online
Teaching Programming OnlineTeaching Programming Online
Teaching Programming OnlinePamela Fox
 
Moving away from legacy code with BDD
Moving away from legacy code with BDDMoving away from legacy code with BDD
Moving away from legacy code with BDDKonstantin Kudryashov
 
Tek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSTek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSPablo Godel
 
APIDays 2018 - API Development Lifecycle - The secret ingredient behind RESTf...
APIDays 2018 - API Development Lifecycle - The secret ingredient behind RESTf...APIDays 2018 - API Development Lifecycle - The secret ingredient behind RESTf...
APIDays 2018 - API Development Lifecycle - The secret ingredient behind RESTf...FABERNOVEL TECHNOLOGIES
 
Lone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New AngleLone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New AnglePablo Godel
 
Mwalls velocity levelup
Mwalls velocity levelupMwalls velocity levelup
Mwalls velocity levelupMandi Walls
 
What Ops Can Learn From Design
What Ops Can Learn From DesignWhat Ops Can Learn From Design
What Ops Can Learn From DesignRobert Treat
 
PHPDay 2013 - High Performance PHP
PHPDay 2013 - High Performance PHPPHPDay 2013 - High Performance PHP
PHPDay 2013 - High Performance PHPJonathan Klein
 
PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...
PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...
PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...Lincoln III
 
Business selectors
Business selectorsBusiness selectors
Business selectorsbenwaine
 
Discover the Possibilities of the Jira Cloud Asset API
Discover the Possibilities of the Jira Cloud Asset APIDiscover the Possibilities of the Jira Cloud Asset API
Discover the Possibilities of the Jira Cloud Asset APIAtlassian
 

Similar to Phpday - Automated acceptance testing with Behat and Mink (20)

Intro to Ember.js
Intro to Ember.jsIntro to Ember.js
Intro to Ember.js
 
DIY Synthetic: Private WebPagetest Magic
DIY Synthetic: Private WebPagetest MagicDIY Synthetic: Private WebPagetest Magic
DIY Synthetic: Private WebPagetest Magic
 
Monitoring Behavioral Driven Infrastructures mit Cucumber-Nagios by Mike Adolphs
Monitoring Behavioral Driven Infrastructures mit Cucumber-Nagios by Mike AdolphsMonitoring Behavioral Driven Infrastructures mit Cucumber-Nagios by Mike Adolphs
Monitoring Behavioral Driven Infrastructures mit Cucumber-Nagios by Mike Adolphs
 
Mobile App Feature Configuration and A/B Experiments
Mobile App Feature Configuration and A/B ExperimentsMobile App Feature Configuration and A/B Experiments
Mobile App Feature Configuration and A/B Experiments
 
Scaling PHP to 40 Million Uniques
Scaling PHP to 40 Million UniquesScaling PHP to 40 Million Uniques
Scaling PHP to 40 Million Uniques
 
GraphQL Without a Database | Frontend Developer Love
GraphQL Without a Database | Frontend Developer LoveGraphQL Without a Database | Frontend Developer Love
GraphQL Without a Database | Frontend Developer Love
 
Teaching Programming Online
Teaching Programming OnlineTeaching Programming Online
Teaching Programming Online
 
April JavaScript Tools
April JavaScript ToolsApril JavaScript Tools
April JavaScript Tools
 
Moving away from legacy code with BDD
Moving away from legacy code with BDDMoving away from legacy code with BDD
Moving away from legacy code with BDD
 
Tek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSTek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJS
 
APIDays 2018 - API Development Lifecycle - The secret ingredient behind RESTf...
APIDays 2018 - API Development Lifecycle - The secret ingredient behind RESTf...APIDays 2018 - API Development Lifecycle - The secret ingredient behind RESTf...
APIDays 2018 - API Development Lifecycle - The secret ingredient behind RESTf...
 
Lone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New AngleLone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New Angle
 
Mwalls velocity levelup
Mwalls velocity levelupMwalls velocity levelup
Mwalls velocity levelup
 
What Ops Can Learn From Design
What Ops Can Learn From DesignWhat Ops Can Learn From Design
What Ops Can Learn From Design
 
PHPDay 2013 - High Performance PHP
PHPDay 2013 - High Performance PHPPHPDay 2013 - High Performance PHP
PHPDay 2013 - High Performance PHP
 
Behat
BehatBehat
Behat
 
PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...
PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...
PrettyFaces: SEO, Dynamic, Parameters, Bookmarks, Navigation for JSF / JSF2 (...
 
Business selectors
Business selectorsBusiness selectors
Business selectors
 
Backbone
BackboneBackbone
Backbone
 
Discover the Possibilities of the Jira Cloud Asset API
Discover the Possibilities of the Jira Cloud Asset APIDiscover the Possibilities of the Jira Cloud Asset API
Discover the Possibilities of the Jira Cloud Asset API
 

Recently uploaded

fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Recently uploaded (20)

fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

Phpday - Automated acceptance testing with Behat and Mink

  • 1. PHPDAY 2013, VERONA Automated acceptance testing with Behat and Mink & Saturday, May 18, 13
  • 2. LET ME INTRODUCE MYSELF • @Richard_Tuin • Software developer from the Netherlands • Particular interest in QA • Working for Saturday, May 18, 13
  • 3. INEFFICIENCY • Different view on scope and resulting product • Clients don’t get a feel of how they will use the product • “I like what you’ve built, but it doesn’t do what i meant” • “Thanks for this new feature, but now x stopped working!” Saturday, May 18, 13
  • 4. INEFFICIENCY • Different view on scope and resulting product • Clients don’t get a feel of how they will use the product • “I like what you’ve built, but it doesn’t do what i meant” • “Thanks for this new feature, but now x stopped working!” Saturday, May 18, 13
  • 5. BECAUSE • ... the dev team and the client have the same goal • ... we want to know that what we build has value • ... we want to deliver consistent quality Saturday, May 18, 13
  • 8. SOTHIS MEANS... • ... we have to focus more on communication • ... leave no room for misinterpretation • ... we have to work together with the client • ... we got to have a system • ... we have to validate regularly if what we have built is still according to acceptance criteria Saturday, May 18, 13
  • 9. SOTHIS MEANS... • ... we have to focus more on communication • ... leave no room for misinterpretation • ... we have to work together with the client • ... we got to have a system • ... we have to validate regularly if what we have built is still according to acceptance criteria Automation? Saturday, May 18, 13
  • 14. ITERATIVE “Gradually get to the highest value.” Saturday, May 18, 13
  • 16. WRITING REQUIREMENTS • Describe how a problem will be solved • Write them together with your client • In the (technical) language of the client • Try to describe the functional problem, not the technical one Saturday, May 18, 13
  • 17. WRITE EXAMPLES! They will reduce misinterpretation and illustrate the result Saturday, May 18, 13
  • 18. FEATURE FILE LAYOUT Feature: {feature description} {intention} As a {person} I want {feature} So that {intention} Scenario: {specific scenario description} Given {context} And {more context} When {action} Then {result} Scenario: ... Information: http://dannorth.net/whats-in-a-story/ Saturday, May 18, 13
  • 19. EXAMPLE FEATURE Feature: Searching on the internet As a google.com visitor I want to use the search engine So that i can find information on the internet Scenario: Simple keyword search Given I am on the homepage When I fill in the search term “PHP” And I press “Google search” Then I should see search results containing “PHP” Scenario: I feel lucky Given I am on the homepage When I fill in the search term “PHP” And I press “I’m feeling lucky” Then I should not be on google.com And I should see “PHP” Saturday, May 18, 13
  • 20. STEPS? (TERMINOLOGY) Feature: {feature description} {intention} As a {person} I want {feature} So that {intention} Scenario: {specific scenario description} Given {context} And {more context} When {action} Then {result} Scenario: ... Saturday, May 18, 13
  • 21. STEPS? (TERMINOLOGY) Feature: {feature description} {intention} As a {person} I want {feature} So that {intention} Scenario: {specific scenario description} Given {context} And {more context} When {action} Then {result} Scenario: ... Feature, user story, module Saturday, May 18, 13
  • 22. STEPS? (TERMINOLOGY) Feature: {feature description} {intention} As a {person} I want {feature} So that {intention} Scenario: {specific scenario description} Given {context} And {more context} When {action} Then {result} Scenario: ... Feature, user story, module Scenario Saturday, May 18, 13
  • 23. STEPS? (TERMINOLOGY) Feature: {feature description} {intention} As a {person} I want {feature} So that {intention} Scenario: {specific scenario description} Given {context} And {more context} When {action} Then {result} Scenario: ... Feature, user story, module Scenario Steps Saturday, May 18, 13
  • 24. LIVING DOCUMENTATION • All features and scenarios make great documentation! • A change request starts with rewriting documentation • Easy to see what functionality the application contains • Easy to get a feel for the impact of a change • Easy to get a new team member involved Saturday, May 18, 13
  • 25. COMMUNICATION IS KEY Automation is not the focus Saturday, May 18, 13
  • 27. AUTOMATION Makes us happy :-) Saturday, May 18, 13
  • 28. “A php framework for testing your business expectations.” -behat.org Saturday, May 18, 13
  • 29. “Mink is an open source acceptance test framework for web applications, written in PHP 5.3.” Saturday, May 18, 13
  • 32. COMPONENTS OF A BEHAT+MINK FUNCTIONALTEST SUITE • Features • Feature parser • Generic browser controller client • Browser controller/simulator • Executable code that controls the browser controller client Saturday, May 18, 13
  • 33. COMPONENTS OF A BEHAT+MINK FUNCTIONALTEST SUITE • Features • Feature parser • Generic browser controller client • Browser controller/simulator • Executable code that controls the browser controller client Living documentation Saturday, May 18, 13
  • 34. COMPONENTS OF A BEHAT+MINK FUNCTIONALTEST SUITE • Features • Feature parser • Generic browser controller client • Browser controller/simulator • Executable code that controls the browser controller client Living documentation Behat Saturday, May 18, 13
  • 35. COMPONENTS OF A BEHAT+MINK FUNCTIONALTEST SUITE • Features • Feature parser • Generic browser controller client • Browser controller/simulator • Executable code that controls the browser controller client Living documentation Behat Mink Saturday, May 18, 13
  • 36. COMPONENTS OF A BEHAT+MINK FUNCTIONALTEST SUITE • Features • Feature parser • Generic browser controller client • Browser controller/simulator • Executable code that controls the browser controller client Living documentation Behat Mink Selenium, Zombie.js, Goutte, etc. Saturday, May 18, 13
  • 37. COMPONENTS OF A BEHAT+MINK FUNCTIONALTEST SUITE • Features • Feature parser • Generic browser controller client • Browser controller/simulator • Executable code that controls the browser controller client Living documentation Behat Mink Selenium, Zombie.js, Goutte, etc. MinkExtension Saturday, May 18, 13
  • 38. 1. Using Composer or Phar $ composer install { "require": { "behat/behat": "*", "behat/mink": "*", "behat/mink-extension": "*", "behat/mink-goutte-driver": "*", "behat/mink-selenium2-driver": "*" }, "minimum-stability": "dev", "config": { "bin-dir": "bin/" } } INSTALLING BEHAT+MINK Saturday, May 18, 13
  • 39. 1. Using Composer or Phar $ composer install { "require": { "behat/behat": "*", "behat/mink": "*", "behat/mink-extension": "*", "behat/mink-goutte-driver": "*", "behat/mink-selenium2-driver": "*" }, "minimum-stability": "dev", "config": { "bin-dir": "bin/" } } INSTALLING BEHAT+MINK That’s it! Saturday, May 18, 13
  • 40. HELLO BEHAT 1. Initialize a Behat testsuite skeleton $ bin/behat --init 2. Behat creates it’s standard project structure Saturday, May 18, 13
  • 41. MINKEXTENSION 1. Bridges the gap between Behat and Mink 2. Contains a set of predefined step definitions 3. Not all step definitions may be usable for all projects 4. Behat + Mink is easy: use BehatMinkExtensionContextMinkContext; class FeatureContext extends MinkContext { // ... } features/FeatureContext.php Saturday, May 18, 13
  • 42. MINKEXTENSION STEPS Given /^(?:|I )am on (?:|the )homepage$/ When /^(?:|I )go to (?:|the )homepage$/ Given /^(?:|I )am on "(?P<page>[^"]+)"$/ When /^(?:|I )fill in "(?P<field>(?:[^"]|")*)" with "(?P<value>(?:[^"]|")*)"$/ When /^(?:|I )press "(?P<button>(?:[^"]|")*)"$/ When /^(?:|I )follow "(?P<link>(?:[^"]|")*)"$/ Then /^(?:|I )should be on "(?P<page>[^"]+)"$/ Then /^(?:|I )should see "(?P<text>(?:[^"]|")*)"$/ $ bin/behat -dl /** * Clicks link with specified id|title|alt|text. * * @When /^(?:|I )follow "(?P<link>(?:[^"]|")*)"$/ */ public function clickLink($link) { $link = $this->fixStepArgument($link); $this->getSession()->getPage()->clickLink($link); } Saturday, May 18, 13
  • 43. BEHAT.YML • Place for configuration options • Basic Behat / Mink config default: extensions: BehatMinkExtensionExtension: base_url: "http://www.yourwebsite.com" goutte: ~ selenium2: ~ Saturday, May 18, 13
  • 45. EXAMPLE FEATURE Feature: Search on the internet As a google.com visitor I want to use the search engine So that i can find information on the internet Scenario: Simple keyword search Given I am on the homepage When I fill in the search term “PHP” And I press “Google search” Then I should see search results containing “PHP” features/search.feature Saturday, May 18, 13
  • 46. STEP DEFINITIONS /** * @When /^I fill in the search term "([^"]*)"$/ */ public function iSearchTheTerm($arg1) { throw new PendingException(); } Put these in your FeatureContext.php file. $ bin/behat Running Behat Behat gives you step suggestions: Saturday, May 18, 13
  • 47. WRITING STEP DEFINITIONS /** * @When /^I search the term "([^"]*)"$/ */ public function iSearchTheTerm($searchTerm) { $this->fillField('q', $searchTerm); // method from MinkExtension $this->pressButton('Google search'); } Saturday, May 18, 13
  • 48. MINKTERMINOLOGY • Driver = Browser controller/emulator • Session = Browser • Page = Document(Element) • Element • Selectors • XPath • CSS • Named Saturday, May 18, 13
  • 50. PAGE/DOCUMENTTRAVERSAL • Selection of elements on a page • Selectors based on XPath, CSS, Names $page = $this->getPage(); $elements = $page->findAll('xpath', './/div[@class="sa_mc"]'); $elements = $page->findAll('css', 'div[class="sa_mc"]'); Saturday, May 18, 13
  • 51. ELEMENT ACTIONS $page = $this->getSession()->getPage(); $loginLink = $page->find('css', '#login'); $loginLink->click(); ->getValue(); ->setValue(); ->keyUp(); ->press(); etcetera... Saturday, May 18, 13
  • 52. OTHER FEATURES Great to get started Saturday, May 18, 13
  • 53. PROFILES • Full configuration per environment • Feature / Scenario selection based on filters • Define them in behat.yml: • Call the profile with: $ bin/behat --profile acceptance default: extension: BehatMinkExtensionContextMinkContext base_url: “http://www.example.org” acceptance: extension: BehatMinkExtensionContextMinkContext base_url: “http://acc.example.org” Saturday, May 18, 13
  • 54. TAGS • Metadata for features and scenarios • Via command line: $ bin/behat --tags “@smoke” • Define as filter in profile @smoke Feature: Search on the www @javascript Scenario: ... search.feature smoke: filters: tags: “@smoke” behat.yml nojs: filters: tags: “~@javascript” behat.yml Saturday, May 18, 13
  • 55. FILTERS • Grouping tests • Tags • Configuration in behat.yml smoketests: filters: tags: “@smoketest&&~@wip” development: filters: tags: “~@slow&&~@wip” Saturday, May 18, 13
  • 56. BROWSER CONTROLLERS Javascript Speed Remark Goutte No ++ Emulator Selenium2 Yes - Zombie.js Yes + Saturday, May 18, 13
  • 57. SCENARIO OUTLINES Scenario Outline: Simple keyword search Given I am on the homepage When I search the term <searchterm> Then I should see search results containing <searchterm> Examples: | searchterm | | PHP | | Java | | Pie | | This string is possibly too long and uncommon | Saturday, May 18, 13
  • 58. DRIVER BENCHMARK Goutte 2.736ms Selenium2 16.682ms Zombie.js 7.533ms 0 5,000 10,000 15,000 20,000 Goutte Selenium2 Zombie.js Saturday, May 18, 13
  • 59. HOOKS • @beforeSuite • @beforeFeature • @beforeScenario • @beforeStep • @afterSuite • @afterFeature • @afterScenario • @afterStep Saturday, May 18, 13
  • 60. HOOKS • @beforeSuite • @beforeFeature • @beforeScenario • @beforeStep • @afterSuite • @afterFeature • @afterScenario • @afterStep Saturday, May 18, 13
  • 61. HOOK EXAMPLE /** * @afterScenario */ public function logoutUser() { $this->visit('/logout'); } features/bootstrap/FeatureContext.php Saturday, May 18, 13
  • 62. LOCALIZATION • Write features in your own language # language: it Funzionalità: non so scrivere italiano Scenario: ... Dato ... Quando ... Allora ... Schema dello scenario: ... Dato ... Quando ... Allora ... Esempi: ... Saturday, May 18, 13
  • 63. INTEGRATION WITH JENKINS • Behat includes export to jUnit format • Jenkins build step example ${WORKSPACE}/bin/behat --format junit --out ${WORKSPACE}/build Saturday, May 18, 13
  • 64. CONCLUSION 1. Writing examples is great to improve communication 2. Automating acceptance criteria = consistent quality 3. Behat and Mink are an excellent combination to do this Saturday, May 18, 13
  • 66. THANKYOU! • Feedback: http://joind.in/talk/view/8647 • More questions? Contact me, i love this subject! • @Richard_Tuin • richardtuin@gmail.com • skype: richardtuin Saturday, May 18, 13