Behavior Driven Development - How To Start with Behat

1,197 views

Published on

Published in: Engineering
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,197
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
13
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Behavior Driven Development - How To Start with Behat

  1. 1. Behaviour Driven Development (BDD)
  2. 2. What is BDD? Behaviour Driven Development
  3. 3. Behaviours = Scenarios What is it supposed to do?
  4. 4. Driven Development Well, driving your development process
  5. 5. Behat Documentation “It’s the idea that you start by writing human- readable sentences that describe a feature of your application and how it should work, and only then implement this behaviour in software.”
  6. 6. BDD Steps Think Red Bar Green Bar Refactor
  7. 7. Test Framework Browser Driver &
  8. 8. Scenario Given [Context] And [More context] ! When (I do) [Action] And [Other Action] ! Then (I should see) [Outcome] And [More Outcomes] It’s called Gherkin btw
  9. 9. Given • Will almost always be the URL of the page to test ! ! Given /^(?:|I )am on (?:|the )homepage$/ Given /^(?:|I )am on "(?P<page>[^"]+)"$/ • Example:
 Given I am on “/credit-card”
  10. 10. When • Any user action - press a button, fill a the textbox, select a select box
 When /^(?:|I )go to "(?P<page>[^"]+)"$/ When /^(?:|I )reload the page$/ When /^(?:|I )move backward one page$/ When /^(?:|I )move forward one page$/ When /^(?:|I )press "(?P<button>(?:[^"]|")*)"$/ When /^(?:|I )follow "(?P<link>(?:[^"]|")*)"$/ When /^(?:|I )fill in "(?P<field>(?:[^"]|")*)" with "(?P<value>(?:[^"]|")*)"$/ When /^(?:|I )fill in "(?P<field>(?:[^"]|")*)" with:$/ When /^(?:|I )fill in "(?P<value>(?:[^"]|")*)" for "(?P<field>(?:[^"]|")*)"$/ When /^(?:|I )fill in the following:$/ When /^(?:|I )select "(?P<option>(?:[^"]|")*)" from "(?P<select>(?:[^"]|")*)"$/ When /^(?:|I )check "(?P<option>(?:[^"]|")*)"$/ When /^(?:|I )uncheck "(?P<option>(?:[^"]|")*)"$/ When /^(?:|I )attach the file "(?P[^"]*)" to “(?P<field>(?:[^"]|")*)"$/ • Example:
 When I press “More Info”
  11. 11. Then • What should be seen / happen on the page
 Then /^(?:|I )should be on "(?P<page>[^"]+)"$/ Then /^(?:|I )should be on (?:|the )homepage$/ Then /^the response status code should be (?P<code>d+)$/ Then /^the response status code should not be (?P<code>d+)$/ Then /^(?:|I )should see "(?P<text>(?:[^"]|")*)"$/ Then /^(?:|I )should not see "(?P<text>(?:[^"]|")*)"$/ Then /^(?:|I )should see text matching (?P<pattern>"(?:[^"]|")*")$/ Then /^(?:|I )should not see text matching (?P<pattern>"(?:[^"]|")*")$/ Then /^the response should contain "(?P<text>(?:[^"]|")*)"$/ Then /^the response should not contain "(?P<text>(?:[^"]|")*)"$/ Then /^(?:|I )should see "(?P<text>(?:[^"]|")*)" in the "(?P<element>[^"]*)" element$/ Then /^(?:|I )should not see "(?P<text>(?:[^"]|")*)" in the "(?P<element>[^"]*)" element$/ Then /^the "(?P<element>[^"]*)" element should contain "(?P<value>(?:[^"]|")*)"$/ Then /^the "(?P<element>[^"]*)" element should not contain "(?P<value>(?:[^"]|")*)"$/ Then /^(?:|I )should see an? "(?P<element>[^"]*)" element$/ Then /^(?:|I )should not see an? "(?P<element>[^"]*)" element$/ Then /^the "(?P<field>(?:[^"]|")*)" field should contain "(?P<value>(?:[^"]|")*)"$/ Then /^the "(?P<field>(?:[^"]|")*)" field should not contain "(?P<value>(?:[^"]|")*)"$/ Then /^(?:|I )should see (?P<num>d+) "(?P<element>[^"]*)" elements?$/ Then /^print current URL$/ Then /^print last response$/ • Example:
 Then I should be on “Maybank Gold Card 2”

  12. 12. What to test?
  13. 13. Scenario Given I am on “/credit-card” ! When I hover on “.rating-icon” ! Then I should see “3% cashback”
  14. 14. Scenario Given I am on “/credit-card” ! When I check “#petrol-filter” And I press “Filter” ! Then I should see [Petrol] card And I should not see [Groceries] card And I should not see [Travel] card And I should not see [Shopping] card And I should not see [Bills] card
  15. 15. Output
  16. 16. Recap • Think about the behaviours you want • Write scenarios that describe those behaviours • Start a failing test • Write code for it to pass • Restart test = green

×