How to support acceptance testing of web applications with the PHP tool Behat in a BDD manner.
Including an overview of acceptance testing in agile software development in general.
Concluding with the most frequent challenges of using Behat and similar tools in practice.
1. AUTOMATED
WEB ACCEPTANCE TESTING
WITH BEHAT
Fabian Kiss
YMC AG | May 2012
Picture by viZZZual.com, licensed under the CC BY 2.0
2. IN AGILE
TESTING
Picture by Sheffield Tiger, licensed under the CC BY 2.0
3. MIKE COHN'S AGILE TESTING PYRAMID
Succeeding with Agile: Software Development Using Scrum, Addison-Wesley
at ed
om
ut s
A t
t es
4. MIKE COHN'S AGILE TESTING PYRAMID
Succeeding with Agile: Software Development Using Scrum, Addison-Wesley
UI
Service
Unit
5. MIKE COHN'S AGILE TESTING PYRAMID
Succeeding with Agile: Software Development Using Scrum, Addison-Wesley
least investment
UI
Service
most investment
Unit
6. MIKE COHN'S AGILE TESTING PYRAMID
Succeeding with Agile: Software Development Using Scrum, Addison-Wesley
least investment
UI
Service
most investment
Unit
7. BRIAN MARICK'S AGILE TESTING MATRIX
http://www.exampler.com/old-blog/2003/08/21/
tests
ated
ut om
al +a
nu
Ma
8. BRIAN MARICK'S AGILE TESTING MATRIX
http://www.exampler.com/old-blog/2003/08/21/
Acceptance Usability
Testing Testing
... ...
Performance
Unit Testing
Testing
...
…
9. BRIAN MARICK'S AGILE TESTING MATRIX
http://www.exampler.com/old-blog/2003/08/21/
Business-facing
Acceptance Usability
Support programming
Testing Testing
Critique product
... ...
Performance
Unit Testing
Testing
...
…
Technology-facing
10. BRIAN MARICK'S AGILE TESTING MATRIX
http://www.exampler.com/old-blog/2003/08/21/
Business-facing
Acceptance Usability
Support programming
Testing Testing
Critique product
... ...
Performance
Unit Testing
Testing
...
…
Technology-facing
22. GHERKIN SYNTAX + SEMANTICS
http://docs.behat.org/guides/1.gherkin.html
Scenario: Some determinable business situation
Given some precondition
And some other precondition
When some action by the actor
And some other action
Then some testable outcome is achieved
And something else we can check happens too
23. GHERKIN SYNTAX + SEMANTICS
http://docs.behat.org/guides/1.gherkin.html
Scenario: Some determinable business situation
Given some precondition
And some other precondition
When some action by the actor
And some other action
Then some testable outcome is achieved
And something else we can check happens too
24. GHERKIN SYNTAX + SEMANTICS
http://docs.behat.org/guides/1.gherkin.html
Scenario: Some determinable business situation
Given some precondition
And some other precondition
When some action by the actor
And some other action
Then some testable outcome is achieved
And something else we can check happens too
25. GHERKIN SYNTAX + SEMANTICS
http://docs.behat.org/guides/1.gherkin.html
Scenario: Some determinable business situation
Given some precondition
And some other precondition
When some action by the actor
And some other action
Then some testable outcome is achieved
And something else we can check happens too
26. GHERKIN SYNTAX + SEMANTICS
http://docs.behat.org/guides/1.gherkin.html
Scenario: Some determinable business situation
Given some precondition
And some other precondition
When some action by the actor
And some other action
Then some testable outcome is achieved
And something else we can check happens too
27. GHERKIN SYNTAX + SEMANTICS
http://docs.behat.org/guides/1.gherkin.html
Scenario: Some determinable business situation
Given some precondition
And some other precondition
When some action by the actor
And some other action
Then some testable outcome is achieved
And something else we can check happens too
28. GHERKIN EXAMPLE
http://docs.behat.org/guides/1.gherkin.html
Scenario: Wilson posts to his own blog
Given I am logged in as Wilson
When I try to post to "Expensive Therapy"
Then I should see "Your article was published."
Scenario: Wilson fails to post to somebody else's blog
Given I am logged in as Wilson
When I try to post to "Greg's antitax rants"
Then I should see "Hey! That's not your blog!"
29. GHERKIN EXAMPLE
http://docs.behat.org/guides/1.gherkin.html
Feature
Scenario: Wilson posts to his own blog
Given I am logged in as Wilson
When I try to post to "Expensive Therapy"
Then I should see "Your article was published."
Scenario: Wilson fails to post to somebody else's blog
Given I am logged in as Wilson
When I try to post to "Greg's antitax rants"
Then I should see "Hey! That's not your blog!"
30. STEPS & STEP DEFINITIONS
http://docs.behat.org/quick_intro.html#basic-usage
Given some precondition
/**
* @Given /^some precondition$/
*/
public function somePrecondition()
{
//...
}
31. STEPS & STEP DEFINITIONS
http://docs.behat.org/quick_intro.html#basic-usage
Given some precondition
Step
Step
/**
definition
* @Given /^some precondition$/
*/
public function somePrecondition()
{
//...
}
32. STEPS & STEP DEFINITIONS
http://docs.behat.org/quick_intro.html#basic-usage
Given some precondition
Step
Matching
Step
/**
definition
* @Given /^some precondition$/
*/
public function somePrecondition()
{
//...
}
Run
35. SCENARIO BACKGROUNDS
http://docs.behat.org/guides/1.gherkin.html#backgrounds
Background:
Given I am logged in as Wilson
Scenario: Wilson posts to his own blog
When I try to post to "Expensive Therapy"
Then I should see "Your article was published."
Scenario: Wilson fails to post to somebody else's blog
When I try to post to "Greg's antitax rants"
Then I should see "Hey! That's not your blog!"
36. SCENARIO BACKGROUNDS
http://docs.behat.org/guides/1.gherkin.html#backgrounds
Background:
Given I am logged in as Wilson
Scenario: Wilson posts to his own blog
When I try to post to "Expensive Therapy"
Then I should see "Your article was published."
Scenario: Wilson fails to post to somebody else's blog
When I try to post to "Greg's antitax rants"
Then I should see "Hey! That's not your blog!"
37. SCENARIO OUTLINES
http://docs.behat.org/guides/1.gherkin.html#scenario-outlines
Scenario Outline: Wilson posts to a blog
Given I am logged in as Wilson
When I try to post to "<blog>"
Then I should see "<authorization>"
Examples:
| blog | authorization |
| Expensive Therapy | Your article was published. |
| Greg's antitax rants | Hey! That's not your blog! |
38. SCENARIO OUTLINES
http://docs.behat.org/guides/1.gherkin.html#scenario-outlines
Scenario Outline: Wilson posts to a blog
Given I am logged in as Wilson
When I try to post to "<blog>" x2
Then I should see "<authorization>"
Examples:
| blog | authorization |
| Expensive Therapy | Your article was published. |
| Greg's antitax rants | Hey! That's not your blog! |
39. STEP TABLES
http://docs.behat.org/guides/1.gherkin.html#tables
Scenario: Wilson posts to a blog
Given I am logged in as Wilson
When I try to post to:
| blog |
| Expensive Therapy |
| Greg's antitax rants |
Then I should see an authorization outcome
40. STEP TABLES
http://docs.behat.org/guides/1.gherkin.html#tables
Scenario: Wilson posts to a blog
Given I am logged in as Wilson
When I try to post to:
| blog | x2
| Expensive Therapy |
| Greg's antitax rants |
Then I should see an authorization outcome
41. ACCESSING THE WEB
Picture by Misserion, licensed under the CC BY 2.0
42. MINK API
http://mink.behat.org/
Driver object
$client = new SeleniumClient($host, $port);
$driver = new BehatMinkDriverSeleniumDriver(
'firefox', 'base_url', $client
);
Session object
$session = new BehatMinkSession($driver);
$session>start();
$session>visit('http://my_project.dev/some_page.php')
Exemplary interaction
$page = $session>getPage();
$elementByCss = $page>find('css', 'h3 > a');
$elementByCss>click();
43. MINK API
http://mink.behat.org/
Driver object
$client = new SeleniumClient($host, $port);
$driver = new BehatMinkDriverSeleniumDriver(
'firefox', 'base_url', $client
);
Session object
$session = new BehatMinkSession($driver);
$session>start();
$session>visit('http://my_project.dev/some_page.php')
Exemplary interaction
$page = $session>getPage();
$elementByCss = $page>find('css', 'h3 > a');
$elementByCss>click();
53. Picture by Conor Lawless, licensed under the CC BY 2.0
SCENARIO ABSTRACTION LEVEL t name”
t name into field “firs
fill my firs name”
When field “last
VS.
I Wh en I name into
the f fill ill my last
or m When I f
..
When I fill .