behavior driven development - how to start with behat
DESCRIPTION
TRANSCRIPT
![Page 1: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/1.jpg)
Behaviour Driven Development (BDD)
What is BDD Behaviour Driven Development
Behaviours = Scenarios What is it supposed to do
Driven Development Well driving your development
process
Behat Documentation
ldquoItrsquos 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 softwarerdquo
BDD StepsThink
Red Bar
Green Bar
Refactor
Test Framework Browser Driver
amp
ScenarioGiven [Context]And [More context]
When (I do) [Action]And [Other Action]
Then (I should see) [Outcome]And [More Outcomes]
Itrsquos called Gherkin
btw
Given
bull Will almost always be the URL of the page to test Given ^(|I )am on (|the )homepage$ Given ^(|I )am on (Pltpagegt[^]+)$
bull ExampleGiven I am on ldquocredit-cardrdquo
Whenbull Any user action - press a button fill a the textbox
select a select box When ^(|I )go to (Pltpagegt[^]+)$ When ^(|I )reload the page$ When ^(|I )move backward one page$ When ^(|I )move forward one page$ When ^(|I )press (Pltbuttongt([^]|))$ When ^(|I )follow (Pltlinkgt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with (Pltvaluegt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with$ When ^(|I )fill in (Pltvaluegt([^]|)) for (Pltfieldgt([^]|))$ When ^(|I )fill in the following$ When ^(|I )select (Pltoptiongt([^]|)) from (Pltselectgt([^]|))$ When ^(|I )check (Pltoptiongt([^]|))$ When ^(|I )uncheck (Pltoptiongt([^]|))$ When ^(|I )attach the file (P[^]) to ldquo(Pltfieldgt([^]|))$
bull Example When I press ldquoMore Infordquo
Thenbull What should be seen happen on the page Then ^(|I )should be on (Pltpagegt[^]+)$ Then ^(|I )should be on (|the )homepage$ Then ^the response status code should be (Pltcodegtd+)$ Then ^the response status code should not be (Pltcodegtd+)$ Then ^(|I )should see (Plttextgt([^]|))$ Then ^(|I )should not see (Plttextgt([^]|))$ Then ^(|I )should see text matching (Pltpatterngt([^]|))$ Then ^(|I )should not see text matching (Pltpatterngt([^]|))$ Then ^the response should contain (Plttextgt([^]|))$ Then ^the response should not contain (Plttextgt([^]|))$ Then ^(|I )should see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^(|I )should not see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^the (Pltelementgt[^]) element should contain (Pltvaluegt([^]|))$ Then ^the (Pltelementgt[^]) element should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see an (Pltelementgt[^]) element$ Then ^(|I )should not see an (Pltelementgt[^]) element$ Then ^the (Pltfieldgt([^]|)) field should contain (Pltvaluegt([^]|))$ Then ^the (Pltfieldgt([^]|)) field should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see (Pltnumgtd+) (Pltelementgt[^]) elements$ Then ^print current URL$ Then ^print last response$
bull ExampleThen I should be on ldquoMaybank Gold Card 2rdquo
What to test
Scenario
Given I am on ldquocredit-cardrdquo
When I hover on ldquorating-iconrdquo
Then I should see ldquo3 cashbackrdquo
ScenarioGiven I am on ldquocredit-cardrdquoWhen I check ldquopetrol-filterrdquoAnd I press ldquoFilterrdquoThen I should see [Petrol] cardAnd I should not see [Groceries] cardAnd I should not see [Travel] cardAnd I should not see [Shopping] cardAnd I should not see [Bills] card
Output
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green
![Page 2: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/2.jpg)
What is BDD Behaviour Driven Development
Behaviours = Scenarios What is it supposed to do
Driven Development Well driving your development
process
Behat Documentation
ldquoItrsquos 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 softwarerdquo
BDD StepsThink
Red Bar
Green Bar
Refactor
Test Framework Browser Driver
amp
ScenarioGiven [Context]And [More context]
When (I do) [Action]And [Other Action]
Then (I should see) [Outcome]And [More Outcomes]
Itrsquos called Gherkin
btw
Given
bull Will almost always be the URL of the page to test Given ^(|I )am on (|the )homepage$ Given ^(|I )am on (Pltpagegt[^]+)$
bull ExampleGiven I am on ldquocredit-cardrdquo
Whenbull Any user action - press a button fill a the textbox
select a select box When ^(|I )go to (Pltpagegt[^]+)$ When ^(|I )reload the page$ When ^(|I )move backward one page$ When ^(|I )move forward one page$ When ^(|I )press (Pltbuttongt([^]|))$ When ^(|I )follow (Pltlinkgt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with (Pltvaluegt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with$ When ^(|I )fill in (Pltvaluegt([^]|)) for (Pltfieldgt([^]|))$ When ^(|I )fill in the following$ When ^(|I )select (Pltoptiongt([^]|)) from (Pltselectgt([^]|))$ When ^(|I )check (Pltoptiongt([^]|))$ When ^(|I )uncheck (Pltoptiongt([^]|))$ When ^(|I )attach the file (P[^]) to ldquo(Pltfieldgt([^]|))$
bull Example When I press ldquoMore Infordquo
Thenbull What should be seen happen on the page Then ^(|I )should be on (Pltpagegt[^]+)$ Then ^(|I )should be on (|the )homepage$ Then ^the response status code should be (Pltcodegtd+)$ Then ^the response status code should not be (Pltcodegtd+)$ Then ^(|I )should see (Plttextgt([^]|))$ Then ^(|I )should not see (Plttextgt([^]|))$ Then ^(|I )should see text matching (Pltpatterngt([^]|))$ Then ^(|I )should not see text matching (Pltpatterngt([^]|))$ Then ^the response should contain (Plttextgt([^]|))$ Then ^the response should not contain (Plttextgt([^]|))$ Then ^(|I )should see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^(|I )should not see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^the (Pltelementgt[^]) element should contain (Pltvaluegt([^]|))$ Then ^the (Pltelementgt[^]) element should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see an (Pltelementgt[^]) element$ Then ^(|I )should not see an (Pltelementgt[^]) element$ Then ^the (Pltfieldgt([^]|)) field should contain (Pltvaluegt([^]|))$ Then ^the (Pltfieldgt([^]|)) field should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see (Pltnumgtd+) (Pltelementgt[^]) elements$ Then ^print current URL$ Then ^print last response$
bull ExampleThen I should be on ldquoMaybank Gold Card 2rdquo
What to test
Scenario
Given I am on ldquocredit-cardrdquo
When I hover on ldquorating-iconrdquo
Then I should see ldquo3 cashbackrdquo
ScenarioGiven I am on ldquocredit-cardrdquoWhen I check ldquopetrol-filterrdquoAnd I press ldquoFilterrdquoThen I should see [Petrol] cardAnd I should not see [Groceries] cardAnd I should not see [Travel] cardAnd I should not see [Shopping] cardAnd I should not see [Bills] card
Output
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green
![Page 3: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/3.jpg)
Behaviours = Scenarios What is it supposed to do
Driven Development Well driving your development
process
Behat Documentation
ldquoItrsquos 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 softwarerdquo
BDD StepsThink
Red Bar
Green Bar
Refactor
Test Framework Browser Driver
amp
ScenarioGiven [Context]And [More context]
When (I do) [Action]And [Other Action]
Then (I should see) [Outcome]And [More Outcomes]
Itrsquos called Gherkin
btw
Given
bull Will almost always be the URL of the page to test Given ^(|I )am on (|the )homepage$ Given ^(|I )am on (Pltpagegt[^]+)$
bull ExampleGiven I am on ldquocredit-cardrdquo
Whenbull Any user action - press a button fill a the textbox
select a select box When ^(|I )go to (Pltpagegt[^]+)$ When ^(|I )reload the page$ When ^(|I )move backward one page$ When ^(|I )move forward one page$ When ^(|I )press (Pltbuttongt([^]|))$ When ^(|I )follow (Pltlinkgt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with (Pltvaluegt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with$ When ^(|I )fill in (Pltvaluegt([^]|)) for (Pltfieldgt([^]|))$ When ^(|I )fill in the following$ When ^(|I )select (Pltoptiongt([^]|)) from (Pltselectgt([^]|))$ When ^(|I )check (Pltoptiongt([^]|))$ When ^(|I )uncheck (Pltoptiongt([^]|))$ When ^(|I )attach the file (P[^]) to ldquo(Pltfieldgt([^]|))$
bull Example When I press ldquoMore Infordquo
Thenbull What should be seen happen on the page Then ^(|I )should be on (Pltpagegt[^]+)$ Then ^(|I )should be on (|the )homepage$ Then ^the response status code should be (Pltcodegtd+)$ Then ^the response status code should not be (Pltcodegtd+)$ Then ^(|I )should see (Plttextgt([^]|))$ Then ^(|I )should not see (Plttextgt([^]|))$ Then ^(|I )should see text matching (Pltpatterngt([^]|))$ Then ^(|I )should not see text matching (Pltpatterngt([^]|))$ Then ^the response should contain (Plttextgt([^]|))$ Then ^the response should not contain (Plttextgt([^]|))$ Then ^(|I )should see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^(|I )should not see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^the (Pltelementgt[^]) element should contain (Pltvaluegt([^]|))$ Then ^the (Pltelementgt[^]) element should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see an (Pltelementgt[^]) element$ Then ^(|I )should not see an (Pltelementgt[^]) element$ Then ^the (Pltfieldgt([^]|)) field should contain (Pltvaluegt([^]|))$ Then ^the (Pltfieldgt([^]|)) field should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see (Pltnumgtd+) (Pltelementgt[^]) elements$ Then ^print current URL$ Then ^print last response$
bull ExampleThen I should be on ldquoMaybank Gold Card 2rdquo
What to test
Scenario
Given I am on ldquocredit-cardrdquo
When I hover on ldquorating-iconrdquo
Then I should see ldquo3 cashbackrdquo
ScenarioGiven I am on ldquocredit-cardrdquoWhen I check ldquopetrol-filterrdquoAnd I press ldquoFilterrdquoThen I should see [Petrol] cardAnd I should not see [Groceries] cardAnd I should not see [Travel] cardAnd I should not see [Shopping] cardAnd I should not see [Bills] card
Output
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green
![Page 4: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/4.jpg)
Driven Development Well driving your development
process
Behat Documentation
ldquoItrsquos 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 softwarerdquo
BDD StepsThink
Red Bar
Green Bar
Refactor
Test Framework Browser Driver
amp
ScenarioGiven [Context]And [More context]
When (I do) [Action]And [Other Action]
Then (I should see) [Outcome]And [More Outcomes]
Itrsquos called Gherkin
btw
Given
bull Will almost always be the URL of the page to test Given ^(|I )am on (|the )homepage$ Given ^(|I )am on (Pltpagegt[^]+)$
bull ExampleGiven I am on ldquocredit-cardrdquo
Whenbull Any user action - press a button fill a the textbox
select a select box When ^(|I )go to (Pltpagegt[^]+)$ When ^(|I )reload the page$ When ^(|I )move backward one page$ When ^(|I )move forward one page$ When ^(|I )press (Pltbuttongt([^]|))$ When ^(|I )follow (Pltlinkgt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with (Pltvaluegt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with$ When ^(|I )fill in (Pltvaluegt([^]|)) for (Pltfieldgt([^]|))$ When ^(|I )fill in the following$ When ^(|I )select (Pltoptiongt([^]|)) from (Pltselectgt([^]|))$ When ^(|I )check (Pltoptiongt([^]|))$ When ^(|I )uncheck (Pltoptiongt([^]|))$ When ^(|I )attach the file (P[^]) to ldquo(Pltfieldgt([^]|))$
bull Example When I press ldquoMore Infordquo
Thenbull What should be seen happen on the page Then ^(|I )should be on (Pltpagegt[^]+)$ Then ^(|I )should be on (|the )homepage$ Then ^the response status code should be (Pltcodegtd+)$ Then ^the response status code should not be (Pltcodegtd+)$ Then ^(|I )should see (Plttextgt([^]|))$ Then ^(|I )should not see (Plttextgt([^]|))$ Then ^(|I )should see text matching (Pltpatterngt([^]|))$ Then ^(|I )should not see text matching (Pltpatterngt([^]|))$ Then ^the response should contain (Plttextgt([^]|))$ Then ^the response should not contain (Plttextgt([^]|))$ Then ^(|I )should see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^(|I )should not see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^the (Pltelementgt[^]) element should contain (Pltvaluegt([^]|))$ Then ^the (Pltelementgt[^]) element should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see an (Pltelementgt[^]) element$ Then ^(|I )should not see an (Pltelementgt[^]) element$ Then ^the (Pltfieldgt([^]|)) field should contain (Pltvaluegt([^]|))$ Then ^the (Pltfieldgt([^]|)) field should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see (Pltnumgtd+) (Pltelementgt[^]) elements$ Then ^print current URL$ Then ^print last response$
bull ExampleThen I should be on ldquoMaybank Gold Card 2rdquo
What to test
Scenario
Given I am on ldquocredit-cardrdquo
When I hover on ldquorating-iconrdquo
Then I should see ldquo3 cashbackrdquo
ScenarioGiven I am on ldquocredit-cardrdquoWhen I check ldquopetrol-filterrdquoAnd I press ldquoFilterrdquoThen I should see [Petrol] cardAnd I should not see [Groceries] cardAnd I should not see [Travel] cardAnd I should not see [Shopping] cardAnd I should not see [Bills] card
Output
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green
![Page 5: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/5.jpg)
Behat Documentation
ldquoItrsquos 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 softwarerdquo
BDD StepsThink
Red Bar
Green Bar
Refactor
Test Framework Browser Driver
amp
ScenarioGiven [Context]And [More context]
When (I do) [Action]And [Other Action]
Then (I should see) [Outcome]And [More Outcomes]
Itrsquos called Gherkin
btw
Given
bull Will almost always be the URL of the page to test Given ^(|I )am on (|the )homepage$ Given ^(|I )am on (Pltpagegt[^]+)$
bull ExampleGiven I am on ldquocredit-cardrdquo
Whenbull Any user action - press a button fill a the textbox
select a select box When ^(|I )go to (Pltpagegt[^]+)$ When ^(|I )reload the page$ When ^(|I )move backward one page$ When ^(|I )move forward one page$ When ^(|I )press (Pltbuttongt([^]|))$ When ^(|I )follow (Pltlinkgt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with (Pltvaluegt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with$ When ^(|I )fill in (Pltvaluegt([^]|)) for (Pltfieldgt([^]|))$ When ^(|I )fill in the following$ When ^(|I )select (Pltoptiongt([^]|)) from (Pltselectgt([^]|))$ When ^(|I )check (Pltoptiongt([^]|))$ When ^(|I )uncheck (Pltoptiongt([^]|))$ When ^(|I )attach the file (P[^]) to ldquo(Pltfieldgt([^]|))$
bull Example When I press ldquoMore Infordquo
Thenbull What should be seen happen on the page Then ^(|I )should be on (Pltpagegt[^]+)$ Then ^(|I )should be on (|the )homepage$ Then ^the response status code should be (Pltcodegtd+)$ Then ^the response status code should not be (Pltcodegtd+)$ Then ^(|I )should see (Plttextgt([^]|))$ Then ^(|I )should not see (Plttextgt([^]|))$ Then ^(|I )should see text matching (Pltpatterngt([^]|))$ Then ^(|I )should not see text matching (Pltpatterngt([^]|))$ Then ^the response should contain (Plttextgt([^]|))$ Then ^the response should not contain (Plttextgt([^]|))$ Then ^(|I )should see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^(|I )should not see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^the (Pltelementgt[^]) element should contain (Pltvaluegt([^]|))$ Then ^the (Pltelementgt[^]) element should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see an (Pltelementgt[^]) element$ Then ^(|I )should not see an (Pltelementgt[^]) element$ Then ^the (Pltfieldgt([^]|)) field should contain (Pltvaluegt([^]|))$ Then ^the (Pltfieldgt([^]|)) field should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see (Pltnumgtd+) (Pltelementgt[^]) elements$ Then ^print current URL$ Then ^print last response$
bull ExampleThen I should be on ldquoMaybank Gold Card 2rdquo
What to test
Scenario
Given I am on ldquocredit-cardrdquo
When I hover on ldquorating-iconrdquo
Then I should see ldquo3 cashbackrdquo
ScenarioGiven I am on ldquocredit-cardrdquoWhen I check ldquopetrol-filterrdquoAnd I press ldquoFilterrdquoThen I should see [Petrol] cardAnd I should not see [Groceries] cardAnd I should not see [Travel] cardAnd I should not see [Shopping] cardAnd I should not see [Bills] card
Output
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green
![Page 6: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/6.jpg)
BDD StepsThink
Red Bar
Green Bar
Refactor
Test Framework Browser Driver
amp
ScenarioGiven [Context]And [More context]
When (I do) [Action]And [Other Action]
Then (I should see) [Outcome]And [More Outcomes]
Itrsquos called Gherkin
btw
Given
bull Will almost always be the URL of the page to test Given ^(|I )am on (|the )homepage$ Given ^(|I )am on (Pltpagegt[^]+)$
bull ExampleGiven I am on ldquocredit-cardrdquo
Whenbull Any user action - press a button fill a the textbox
select a select box When ^(|I )go to (Pltpagegt[^]+)$ When ^(|I )reload the page$ When ^(|I )move backward one page$ When ^(|I )move forward one page$ When ^(|I )press (Pltbuttongt([^]|))$ When ^(|I )follow (Pltlinkgt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with (Pltvaluegt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with$ When ^(|I )fill in (Pltvaluegt([^]|)) for (Pltfieldgt([^]|))$ When ^(|I )fill in the following$ When ^(|I )select (Pltoptiongt([^]|)) from (Pltselectgt([^]|))$ When ^(|I )check (Pltoptiongt([^]|))$ When ^(|I )uncheck (Pltoptiongt([^]|))$ When ^(|I )attach the file (P[^]) to ldquo(Pltfieldgt([^]|))$
bull Example When I press ldquoMore Infordquo
Thenbull What should be seen happen on the page Then ^(|I )should be on (Pltpagegt[^]+)$ Then ^(|I )should be on (|the )homepage$ Then ^the response status code should be (Pltcodegtd+)$ Then ^the response status code should not be (Pltcodegtd+)$ Then ^(|I )should see (Plttextgt([^]|))$ Then ^(|I )should not see (Plttextgt([^]|))$ Then ^(|I )should see text matching (Pltpatterngt([^]|))$ Then ^(|I )should not see text matching (Pltpatterngt([^]|))$ Then ^the response should contain (Plttextgt([^]|))$ Then ^the response should not contain (Plttextgt([^]|))$ Then ^(|I )should see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^(|I )should not see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^the (Pltelementgt[^]) element should contain (Pltvaluegt([^]|))$ Then ^the (Pltelementgt[^]) element should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see an (Pltelementgt[^]) element$ Then ^(|I )should not see an (Pltelementgt[^]) element$ Then ^the (Pltfieldgt([^]|)) field should contain (Pltvaluegt([^]|))$ Then ^the (Pltfieldgt([^]|)) field should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see (Pltnumgtd+) (Pltelementgt[^]) elements$ Then ^print current URL$ Then ^print last response$
bull ExampleThen I should be on ldquoMaybank Gold Card 2rdquo
What to test
Scenario
Given I am on ldquocredit-cardrdquo
When I hover on ldquorating-iconrdquo
Then I should see ldquo3 cashbackrdquo
ScenarioGiven I am on ldquocredit-cardrdquoWhen I check ldquopetrol-filterrdquoAnd I press ldquoFilterrdquoThen I should see [Petrol] cardAnd I should not see [Groceries] cardAnd I should not see [Travel] cardAnd I should not see [Shopping] cardAnd I should not see [Bills] card
Output
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green
![Page 7: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/7.jpg)
Test Framework Browser Driver
amp
ScenarioGiven [Context]And [More context]
When (I do) [Action]And [Other Action]
Then (I should see) [Outcome]And [More Outcomes]
Itrsquos called Gherkin
btw
Given
bull Will almost always be the URL of the page to test Given ^(|I )am on (|the )homepage$ Given ^(|I )am on (Pltpagegt[^]+)$
bull ExampleGiven I am on ldquocredit-cardrdquo
Whenbull Any user action - press a button fill a the textbox
select a select box When ^(|I )go to (Pltpagegt[^]+)$ When ^(|I )reload the page$ When ^(|I )move backward one page$ When ^(|I )move forward one page$ When ^(|I )press (Pltbuttongt([^]|))$ When ^(|I )follow (Pltlinkgt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with (Pltvaluegt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with$ When ^(|I )fill in (Pltvaluegt([^]|)) for (Pltfieldgt([^]|))$ When ^(|I )fill in the following$ When ^(|I )select (Pltoptiongt([^]|)) from (Pltselectgt([^]|))$ When ^(|I )check (Pltoptiongt([^]|))$ When ^(|I )uncheck (Pltoptiongt([^]|))$ When ^(|I )attach the file (P[^]) to ldquo(Pltfieldgt([^]|))$
bull Example When I press ldquoMore Infordquo
Thenbull What should be seen happen on the page Then ^(|I )should be on (Pltpagegt[^]+)$ Then ^(|I )should be on (|the )homepage$ Then ^the response status code should be (Pltcodegtd+)$ Then ^the response status code should not be (Pltcodegtd+)$ Then ^(|I )should see (Plttextgt([^]|))$ Then ^(|I )should not see (Plttextgt([^]|))$ Then ^(|I )should see text matching (Pltpatterngt([^]|))$ Then ^(|I )should not see text matching (Pltpatterngt([^]|))$ Then ^the response should contain (Plttextgt([^]|))$ Then ^the response should not contain (Plttextgt([^]|))$ Then ^(|I )should see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^(|I )should not see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^the (Pltelementgt[^]) element should contain (Pltvaluegt([^]|))$ Then ^the (Pltelementgt[^]) element should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see an (Pltelementgt[^]) element$ Then ^(|I )should not see an (Pltelementgt[^]) element$ Then ^the (Pltfieldgt([^]|)) field should contain (Pltvaluegt([^]|))$ Then ^the (Pltfieldgt([^]|)) field should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see (Pltnumgtd+) (Pltelementgt[^]) elements$ Then ^print current URL$ Then ^print last response$
bull ExampleThen I should be on ldquoMaybank Gold Card 2rdquo
What to test
Scenario
Given I am on ldquocredit-cardrdquo
When I hover on ldquorating-iconrdquo
Then I should see ldquo3 cashbackrdquo
ScenarioGiven I am on ldquocredit-cardrdquoWhen I check ldquopetrol-filterrdquoAnd I press ldquoFilterrdquoThen I should see [Petrol] cardAnd I should not see [Groceries] cardAnd I should not see [Travel] cardAnd I should not see [Shopping] cardAnd I should not see [Bills] card
Output
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green
![Page 8: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/8.jpg)
ScenarioGiven [Context]And [More context]
When (I do) [Action]And [Other Action]
Then (I should see) [Outcome]And [More Outcomes]
Itrsquos called Gherkin
btw
Given
bull Will almost always be the URL of the page to test Given ^(|I )am on (|the )homepage$ Given ^(|I )am on (Pltpagegt[^]+)$
bull ExampleGiven I am on ldquocredit-cardrdquo
Whenbull Any user action - press a button fill a the textbox
select a select box When ^(|I )go to (Pltpagegt[^]+)$ When ^(|I )reload the page$ When ^(|I )move backward one page$ When ^(|I )move forward one page$ When ^(|I )press (Pltbuttongt([^]|))$ When ^(|I )follow (Pltlinkgt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with (Pltvaluegt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with$ When ^(|I )fill in (Pltvaluegt([^]|)) for (Pltfieldgt([^]|))$ When ^(|I )fill in the following$ When ^(|I )select (Pltoptiongt([^]|)) from (Pltselectgt([^]|))$ When ^(|I )check (Pltoptiongt([^]|))$ When ^(|I )uncheck (Pltoptiongt([^]|))$ When ^(|I )attach the file (P[^]) to ldquo(Pltfieldgt([^]|))$
bull Example When I press ldquoMore Infordquo
Thenbull What should be seen happen on the page Then ^(|I )should be on (Pltpagegt[^]+)$ Then ^(|I )should be on (|the )homepage$ Then ^the response status code should be (Pltcodegtd+)$ Then ^the response status code should not be (Pltcodegtd+)$ Then ^(|I )should see (Plttextgt([^]|))$ Then ^(|I )should not see (Plttextgt([^]|))$ Then ^(|I )should see text matching (Pltpatterngt([^]|))$ Then ^(|I )should not see text matching (Pltpatterngt([^]|))$ Then ^the response should contain (Plttextgt([^]|))$ Then ^the response should not contain (Plttextgt([^]|))$ Then ^(|I )should see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^(|I )should not see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^the (Pltelementgt[^]) element should contain (Pltvaluegt([^]|))$ Then ^the (Pltelementgt[^]) element should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see an (Pltelementgt[^]) element$ Then ^(|I )should not see an (Pltelementgt[^]) element$ Then ^the (Pltfieldgt([^]|)) field should contain (Pltvaluegt([^]|))$ Then ^the (Pltfieldgt([^]|)) field should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see (Pltnumgtd+) (Pltelementgt[^]) elements$ Then ^print current URL$ Then ^print last response$
bull ExampleThen I should be on ldquoMaybank Gold Card 2rdquo
What to test
Scenario
Given I am on ldquocredit-cardrdquo
When I hover on ldquorating-iconrdquo
Then I should see ldquo3 cashbackrdquo
ScenarioGiven I am on ldquocredit-cardrdquoWhen I check ldquopetrol-filterrdquoAnd I press ldquoFilterrdquoThen I should see [Petrol] cardAnd I should not see [Groceries] cardAnd I should not see [Travel] cardAnd I should not see [Shopping] cardAnd I should not see [Bills] card
Output
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green
![Page 9: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/9.jpg)
Given
bull Will almost always be the URL of the page to test Given ^(|I )am on (|the )homepage$ Given ^(|I )am on (Pltpagegt[^]+)$
bull ExampleGiven I am on ldquocredit-cardrdquo
Whenbull Any user action - press a button fill a the textbox
select a select box When ^(|I )go to (Pltpagegt[^]+)$ When ^(|I )reload the page$ When ^(|I )move backward one page$ When ^(|I )move forward one page$ When ^(|I )press (Pltbuttongt([^]|))$ When ^(|I )follow (Pltlinkgt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with (Pltvaluegt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with$ When ^(|I )fill in (Pltvaluegt([^]|)) for (Pltfieldgt([^]|))$ When ^(|I )fill in the following$ When ^(|I )select (Pltoptiongt([^]|)) from (Pltselectgt([^]|))$ When ^(|I )check (Pltoptiongt([^]|))$ When ^(|I )uncheck (Pltoptiongt([^]|))$ When ^(|I )attach the file (P[^]) to ldquo(Pltfieldgt([^]|))$
bull Example When I press ldquoMore Infordquo
Thenbull What should be seen happen on the page Then ^(|I )should be on (Pltpagegt[^]+)$ Then ^(|I )should be on (|the )homepage$ Then ^the response status code should be (Pltcodegtd+)$ Then ^the response status code should not be (Pltcodegtd+)$ Then ^(|I )should see (Plttextgt([^]|))$ Then ^(|I )should not see (Plttextgt([^]|))$ Then ^(|I )should see text matching (Pltpatterngt([^]|))$ Then ^(|I )should not see text matching (Pltpatterngt([^]|))$ Then ^the response should contain (Plttextgt([^]|))$ Then ^the response should not contain (Plttextgt([^]|))$ Then ^(|I )should see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^(|I )should not see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^the (Pltelementgt[^]) element should contain (Pltvaluegt([^]|))$ Then ^the (Pltelementgt[^]) element should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see an (Pltelementgt[^]) element$ Then ^(|I )should not see an (Pltelementgt[^]) element$ Then ^the (Pltfieldgt([^]|)) field should contain (Pltvaluegt([^]|))$ Then ^the (Pltfieldgt([^]|)) field should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see (Pltnumgtd+) (Pltelementgt[^]) elements$ Then ^print current URL$ Then ^print last response$
bull ExampleThen I should be on ldquoMaybank Gold Card 2rdquo
What to test
Scenario
Given I am on ldquocredit-cardrdquo
When I hover on ldquorating-iconrdquo
Then I should see ldquo3 cashbackrdquo
ScenarioGiven I am on ldquocredit-cardrdquoWhen I check ldquopetrol-filterrdquoAnd I press ldquoFilterrdquoThen I should see [Petrol] cardAnd I should not see [Groceries] cardAnd I should not see [Travel] cardAnd I should not see [Shopping] cardAnd I should not see [Bills] card
Output
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green
![Page 10: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/10.jpg)
Whenbull Any user action - press a button fill a the textbox
select a select box When ^(|I )go to (Pltpagegt[^]+)$ When ^(|I )reload the page$ When ^(|I )move backward one page$ When ^(|I )move forward one page$ When ^(|I )press (Pltbuttongt([^]|))$ When ^(|I )follow (Pltlinkgt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with (Pltvaluegt([^]|))$ When ^(|I )fill in (Pltfieldgt([^]|)) with$ When ^(|I )fill in (Pltvaluegt([^]|)) for (Pltfieldgt([^]|))$ When ^(|I )fill in the following$ When ^(|I )select (Pltoptiongt([^]|)) from (Pltselectgt([^]|))$ When ^(|I )check (Pltoptiongt([^]|))$ When ^(|I )uncheck (Pltoptiongt([^]|))$ When ^(|I )attach the file (P[^]) to ldquo(Pltfieldgt([^]|))$
bull Example When I press ldquoMore Infordquo
Thenbull What should be seen happen on the page Then ^(|I )should be on (Pltpagegt[^]+)$ Then ^(|I )should be on (|the )homepage$ Then ^the response status code should be (Pltcodegtd+)$ Then ^the response status code should not be (Pltcodegtd+)$ Then ^(|I )should see (Plttextgt([^]|))$ Then ^(|I )should not see (Plttextgt([^]|))$ Then ^(|I )should see text matching (Pltpatterngt([^]|))$ Then ^(|I )should not see text matching (Pltpatterngt([^]|))$ Then ^the response should contain (Plttextgt([^]|))$ Then ^the response should not contain (Plttextgt([^]|))$ Then ^(|I )should see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^(|I )should not see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^the (Pltelementgt[^]) element should contain (Pltvaluegt([^]|))$ Then ^the (Pltelementgt[^]) element should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see an (Pltelementgt[^]) element$ Then ^(|I )should not see an (Pltelementgt[^]) element$ Then ^the (Pltfieldgt([^]|)) field should contain (Pltvaluegt([^]|))$ Then ^the (Pltfieldgt([^]|)) field should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see (Pltnumgtd+) (Pltelementgt[^]) elements$ Then ^print current URL$ Then ^print last response$
bull ExampleThen I should be on ldquoMaybank Gold Card 2rdquo
What to test
Scenario
Given I am on ldquocredit-cardrdquo
When I hover on ldquorating-iconrdquo
Then I should see ldquo3 cashbackrdquo
ScenarioGiven I am on ldquocredit-cardrdquoWhen I check ldquopetrol-filterrdquoAnd I press ldquoFilterrdquoThen I should see [Petrol] cardAnd I should not see [Groceries] cardAnd I should not see [Travel] cardAnd I should not see [Shopping] cardAnd I should not see [Bills] card
Output
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green
![Page 11: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/11.jpg)
Thenbull What should be seen happen on the page Then ^(|I )should be on (Pltpagegt[^]+)$ Then ^(|I )should be on (|the )homepage$ Then ^the response status code should be (Pltcodegtd+)$ Then ^the response status code should not be (Pltcodegtd+)$ Then ^(|I )should see (Plttextgt([^]|))$ Then ^(|I )should not see (Plttextgt([^]|))$ Then ^(|I )should see text matching (Pltpatterngt([^]|))$ Then ^(|I )should not see text matching (Pltpatterngt([^]|))$ Then ^the response should contain (Plttextgt([^]|))$ Then ^the response should not contain (Plttextgt([^]|))$ Then ^(|I )should see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^(|I )should not see (Plttextgt([^]|)) in the (Pltelementgt[^]) element$ Then ^the (Pltelementgt[^]) element should contain (Pltvaluegt([^]|))$ Then ^the (Pltelementgt[^]) element should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see an (Pltelementgt[^]) element$ Then ^(|I )should not see an (Pltelementgt[^]) element$ Then ^the (Pltfieldgt([^]|)) field should contain (Pltvaluegt([^]|))$ Then ^the (Pltfieldgt([^]|)) field should not contain (Pltvaluegt([^]|))$ Then ^(|I )should see (Pltnumgtd+) (Pltelementgt[^]) elements$ Then ^print current URL$ Then ^print last response$
bull ExampleThen I should be on ldquoMaybank Gold Card 2rdquo
What to test
Scenario
Given I am on ldquocredit-cardrdquo
When I hover on ldquorating-iconrdquo
Then I should see ldquo3 cashbackrdquo
ScenarioGiven I am on ldquocredit-cardrdquoWhen I check ldquopetrol-filterrdquoAnd I press ldquoFilterrdquoThen I should see [Petrol] cardAnd I should not see [Groceries] cardAnd I should not see [Travel] cardAnd I should not see [Shopping] cardAnd I should not see [Bills] card
Output
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green
![Page 12: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/12.jpg)
What to test
Scenario
Given I am on ldquocredit-cardrdquo
When I hover on ldquorating-iconrdquo
Then I should see ldquo3 cashbackrdquo
ScenarioGiven I am on ldquocredit-cardrdquoWhen I check ldquopetrol-filterrdquoAnd I press ldquoFilterrdquoThen I should see [Petrol] cardAnd I should not see [Groceries] cardAnd I should not see [Travel] cardAnd I should not see [Shopping] cardAnd I should not see [Bills] card
Output
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green
![Page 13: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/13.jpg)
Scenario
Given I am on ldquocredit-cardrdquo
When I hover on ldquorating-iconrdquo
Then I should see ldquo3 cashbackrdquo
ScenarioGiven I am on ldquocredit-cardrdquoWhen I check ldquopetrol-filterrdquoAnd I press ldquoFilterrdquoThen I should see [Petrol] cardAnd I should not see [Groceries] cardAnd I should not see [Travel] cardAnd I should not see [Shopping] cardAnd I should not see [Bills] card
Output
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green
![Page 14: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/14.jpg)
ScenarioGiven I am on ldquocredit-cardrdquoWhen I check ldquopetrol-filterrdquoAnd I press ldquoFilterrdquoThen I should see [Petrol] cardAnd I should not see [Groceries] cardAnd I should not see [Travel] cardAnd I should not see [Shopping] cardAnd I should not see [Bills] card
Output
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green
![Page 15: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/15.jpg)
Output
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green
![Page 16: Behavior Driven Development - How To Start with Behat](https://reader034.vdocuments.net/reader034/viewer/2022052618/54b740284a795966598b476f/html5/thumbnails/16.jpg)
Recap
bull Think about the behaviours you want
bull Write scenarios that describe those behaviours
bull Start a failing test
bull Write code for it to pass
bull Restart test = green