Web Acceptance Testing with Behat

12,556 views

Published on

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.

Published in: Technology
0 Comments
13 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
12,556
On SlideShare
0
From Embeds
0
Number of Embeds
7,915
Actions
Shares
0
Downloads
63
Comments
0
Likes
13
Embeds 0
No embeds

No notes for slide

Web Acceptance Testing with Behat

  1. 1. AUTOMATED WEB ACCEPTANCE TESTING WITH BEHAT Fabian Kiss YMC AG | May 2012Picture by viZZZual.com, licensed under the CC BY 2.0
  2. 2. IN AGILETESTING Picture by Sheffield Tiger, licensed under the CC BY 2.0
  3. 3. MIKE COHNS AGILE TESTING PYRAMIDSucceeding with Agile: Software Development Using Scrum, Addison-Wesley at ed om ut s A t t es
  4. 4. MIKE COHNS AGILE TESTING PYRAMIDSucceeding with Agile: Software Development Using Scrum, Addison-Wesley UI Service Unit
  5. 5. MIKE COHNS AGILE TESTING PYRAMIDSucceeding with Agile: Software Development Using Scrum, Addison-Wesley least investment UI Service most investment Unit
  6. 6. MIKE COHNS AGILE TESTING PYRAMIDSucceeding with Agile: Software Development Using Scrum, Addison-Wesley least investment UI Service most investment Unit
  7. 7. BRIAN MARICKS AGILE TESTING MATRIXhttp://www.exampler.com/old-blog/2003/08/21/ tests ated ut om al +a nu Ma
  8. 8. BRIAN MARICKS AGILE TESTING MATRIXhttp://www.exampler.com/old-blog/2003/08/21/ Acceptance Usability Testing Testing ... ... Performance Unit Testing Testing ... …
  9. 9. BRIAN MARICKS AGILE TESTING MATRIXhttp://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. 10. BRIAN MARICKS AGILE TESTING MATRIXhttp://www.exampler.com/old-blog/2003/08/21/ Business-facing Acceptance Usability Support programming Testing Testing Critique product ... ... Performance Unit Testing Testing ... … Technology-facing
  11. 11. tests ated ut om al +a nuMa
  12. 12. tests ated ut om al +a nuMa
  13. 13. BRIAN MARICKS AGILE TESTING MATRIXhttp://www.exampler.com/old-blog/2003/08/21/ Acceptance Usability Testing Testing ... ... Performance Unit Testing Testing ... …
  14. 14. BRIAN MARICKS AGILE TESTING MATRIXhttp://www.exampler.com/old-blog/2003/08/21/ Acceptance Usability BDD Testing Testing ... ... Performance TDD Unit Testing Testing /BDD ... …
  15. 15. BDD
  16. 16. Specification-oriented BDDBDD Scenario-oriented BDD
  17. 17. Specification-oriented BDD RSpecBDD Scenario-oriented BDD
  18. 18. Specification-oriented BDD RSpecBDD Cucumber Scenario-oriented BDD Behat
  19. 19. Specification-oriented BDD RSpecBDD Cucumber Gherkin DSL Scenario-oriented BDD Behat
  20. 20. Specification-oriented BDD RSpecBDD Cucumber Gherkin DSL Scenario-oriented BDD Behat
  21. 21. Specification-oriented BDD RSpec ...BDD Cucumber Gherkin DSL Scenario-oriented BDD Behat ...
  22. 22. GHERKIN SYNTAX + SEMANTICShttp://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. 23. GHERKIN SYNTAX + SEMANTICShttp://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. 24. GHERKIN SYNTAX + SEMANTICShttp://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. 25. GHERKIN SYNTAX + SEMANTICShttp://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. 26. GHERKIN SYNTAX + SEMANTICShttp://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. 27. GHERKIN SYNTAX + SEMANTICShttp://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. 28. GHERKIN EXAMPLEhttp://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 elses blog   Given I am logged in as Wilson   When I try to post to "Gregs anti­tax rants"   Then I should see "Hey! Thats not your blog!"
  29. 29. GHERKIN EXAMPLEhttp://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 elses blog   Given I am logged in as Wilson   When I try to post to "Gregs anti­tax rants"   Then I should see "Hey! Thats not your blog!"
  30. 30. STEPS & STEP DEFINITIONShttp://docs.behat.org/quick_intro.html#basic-usage Given some precondition /**  * @Given /^some precondition$/  */ public function somePrecondition() {     //... }
  31. 31. STEPS & STEP DEFINITIONShttp://docs.behat.org/quick_intro.html#basic-usage Given some preconditionStepStep /**definition  * @Given /^some precondition$/  */ public function somePrecondition() {     //... }
  32. 32. STEPS & STEP DEFINITIONShttp://docs.behat.org/quick_intro.html#basic-usage Given some preconditionStep MatchingStep /**definition  * @Given /^some precondition$/  */ public function somePrecondition() {     //... } Run
  33. 33. STEP ARGUMENTShttp://docs.behat.org/quick_intro.html#some-more-behat-basics When I try to post to "Expensive Therapy" /**  * @When /^I try to post to "([^"]*)"$/  */ public function iTryToPostTo($site) {     //... }
  34. 34. STEP ARGUMENTShttp://docs.behat.org/quick_intro.html#some-more-behat-basics When I try to post to "Expensive Therapy" Argument /**  * @When /^I try to post to "([^"]*)"$/  */ public function iTryToPostTo($blog) {     //... }
  35. 35. SCENARIO BACKGROUNDShttp://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 elses blog   When I try to post to "Gregs anti­tax rants"   Then I should see "Hey! Thats not your blog!"
  36. 36. SCENARIO BACKGROUNDShttp://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 elses blog   When I try to post to "Gregs anti­tax rants"   Then I should see "Hey! Thats not your blog!"
  37. 37. SCENARIO OUTLINEShttp://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. |    | Gregs anti­tax rants | Hey! Thats not your blog!  |
  38. 38. SCENARIO OUTLINEShttp://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. |    | Gregs anti­tax rants | Hey! Thats not your blog!  |
  39. 39. STEP TABLEShttp://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     |    | Gregs anti­tax rants |   Then I should see an authorization outcome
  40. 40. STEP TABLEShttp://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     |    | Gregs anti­tax rants |   Then I should see an authorization outcome
  41. 41. ACCESSING THE WEB Picture by Misserion, licensed under the CC BY 2.0
  42. 42. MINK APIhttp://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. 43. MINK APIhttp://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();
  44. 44. MINK APIhttp://mink.behat.org/ Driver object $client = new SeleniumClient($host, $port); $driver = new BehatMinkDriverSeleniumDriver(     firefox, base_url, $client ); Sahi, Goutte, Zombie.js 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();
  45. 45. MINK APIhttp://mink.behat.org/ Driver object $client = new SeleniumClient($host, $port); $driver = new BehatMinkDriverSeleniumDriver(     firefox, base_url, $client ); Sahi, Goutte, Zombie.js 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();
  46. 46. MINK APIhttp://mink.behat.org/ Driver object $client = new SeleniumClient($host, $port); $driver = new BehatMinkDriverSeleniumDriver(     firefox, base_url, $client ); Sahi, Goutte, Zombie.js 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();
  47. 47. BEHAT REPORT~/Behat$ behat features/blogpost.featureFeature: Blog posting  As a blogger  I want to post an article to a blog  Scenario: Wilson posts to his own blog            # features/blogpost.feature:5    Given I am logged in as "Wilson"                # FeatureContext::iAmLoggedInAs()    When I try to post to "Expensive Therapy"       # FeatureContext::iTryToPostTo()    Then I should see "Your article was published." # FeatureContext::iShouldSee()  Scenario: Wilson fails to post to somebody elses blog # features/blogpost.feature:10    Given I am logged in as "Wilson"                     # FeatureContext::iAmLoggedInAs()    When I try to post to "Gregs anti­tax rants"        # FeatureContext::iTryToPostTo()      Blog "Gregs anti­tax rants" does not exist    Then I should see "Hey! Thats not your blog!"       # FeatureContext::iShouldSee()2 scenarios (1 passed, 1 failed)6 steps (4 passed, 1 skipped, 1 failed)
  48. 48. BEHAT REPORT~/Behat$ behat features/blogpost.feature ­­format prettyFeature: Blog posting  As a blogger  I want to post an article to a blog  Scenario: Wilson posts to his own blog            # features/blogpost.feature:5    Given I am logged in as "Wilson"                # FeatureContext::iAmLoggedInAs()    When I try to post to "Expensive Therapy"       # FeatureContext::iTryToPostTo()    Then I should see "Your article was published." # FeatureContext::iShouldSee()  Scenario: Wilson fails to post to somebody elses blog # features/blogpost.feature:10    Given I am logged in as "Wilson"                     # FeatureContext::iAmLoggedInAs()    When I try to post to "Gregs anti­tax rants"        # FeatureContext::iTryToPostTo()      Blog "Gregs anti­tax rants" does not exist    Then I should see "Hey! Thats not your blog!"       # FeatureContext::iShouldSee()2 scenarios (1 passed, 1 failed)6 steps (4 passed, 1 skipped, 1 failed) default formatter (“pretty”) all formatters: http://docs.behat.org/guides/6.cli.html#format-options
  49. 49. CHALLENGES...
  50. 50. Picture by Marjan Krebelj, licensed under the CC BY 2.0 DEVELOPERS WRITE SCENARIOS
  51. 51. DEVELOPERS WRITE SCENARIOSPicture by Marjan Krebelj, licensed under the CC BY 2.0 AN ARTIFACT ASKED FOR? UNDERSTANDABILITY?
  52. 52. SCENARIO ABSTRACTION LEVEL Picture by Conor Lawless, licensed under the CC BY 2.0
  53. 53. Picture by Conor Lawless, licensed under the CC BY 2.0SCENARIO 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 .
  54. 54. REDUNDANCYPicture by Rob Faulkner, licensed under the CC BY 2.0
  55. 55. REDUNDANCY Picture by Rob Faulkner, licensed under the CC BY 2.0LIMITED: GHERKINS REUSE CAPABILITIESLIMITED: UNDERSTANDING OF THOSE
  56. 56. Picture by Earls37a, licensed under the CC BY 2.0TIME-CONSUMING REFACTORING
  57. 57. Picture by Earls37a, licensed under the CC BY 2.0EXECUTION IN REAL-TIME TIME-CONSUMING REFACTORING
  58. 58. COMPLEX INFRASTRUCTURE Picture by Domenico Nardone, licensed under the CC BY 2.0
  59. 59. Picture by Domenico Nardone, licensed under the CC BY 2.0COMPLEX INFRASTRUCTUREBehat Mink Driver Browser Emulator Browser
  60. 60. FURTHER REFERENCES: http://www.softwarequalityconnection.com/2011/08/how-to-improve-communication-between-qa-and-development/ http://dannorth.net/introducing-bdd/ http://www.infoq.com/news/2011/02/BDD-ATDD http://www.slideshare.net/headrevision/the-concept-of-behaviordriven-development http://www.slideshare.net/everzet/bdd-in-symfony2SOME BEST PRACTICES: http://www.agileengineeringdesign.com/2012/01/7-deadly-sins-of-automated-software-testing/ http://elabs.se/blog/15-you-re-cuking-it-wrong http://www.engineyard.com/blog/2009/15-expert-tips-for-using-cucumber/ http://eggsonbread.com/2010/09/06/my-cucumber-best-practices-and-tips/

×