behavior driven development - how to start with behat

16
Behaviour Driven Development (BDD)

Upload: imoneytech

Post on 15-Jan-2015

89 views

Category:

Engineering


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Behavior Driven Development - How To Start with Behat

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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