How to implement a scenario in Gherkin where I see the need of an IF Else logic?

65 views
Skip to first unread message

UV

unread,
May 8, 2018, 12:22:09 PM5/8/18
to Behaviour Driven Development
I am business analyst/ PO who is trying to utilize Gherkin for the first time. I have the following scenario (and mostly these types only) where the expected behavior is 

Given I a registered user
And I am on a landing page
When I select an option to...(say search and connect with my client agent)
Then the system prompts me to turn on geo location (thru my app)
Now based on the accept or deny for the above prompt, the system presents different screens for a user to move forward.....
If I accept, system displays map and specific search
If I deny, system displays another way to search...

How do I implement such a scenario?? Pls any quick help is appreciated as I have a deadline to meet.

Thanks

George Dinwiddie

unread,
May 8, 2018, 1:30:01 PM5/8/18
to behaviordriv...@googlegroups.com
UV
There is no branching in scenarios. You need two scenarios for the two
different cases (and probably a third for the case when geolocation is
already enabled).

- George

--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------

UV

unread,
May 8, 2018, 3:23:01 PM5/8/18
to Behaviour Driven Development
Thanks George. But does that mean, I should have scenarios like - 

Scenario 1: Connect/ Search an Agent when user Accepts geo location turn on request
Given ...I am registered user
And  i m on landing page
And I accept the system prompt for turning on geo location
When...I tap on Search
then...

Scenario 2:  Connect/ Search an Agent when user Denies geo location turn on request

Scenario 3: Connect/ Search an Agent when Geo location is already on

Pls confirm the scenarios and one of the And statemnet for Given in scenario 1 (bold)

Thanks

UV

unread,
May 8, 2018, 3:23:01 PM5/8/18
to Behaviour Driven Development
I am business analyst/ PO who is trying to utilize Gherkin for the first time. I have the following scenario (and mostly these types only) where the expected behavior is 

Given I am a registered user
And I am on a landing page
When I select an option to...(say search and connect with my client agent)
Then the system prompts me to turn on geo location (thru my app)
Now based on the accept or deny for the above prompt, the system presents different screens for a user to move forward.....
If I accept, system displays map and specific search
If I deny, system displays another way to search...

How do I implement such a scenario?? Pls any quick help is appreciated as I have a deadline to meet.

thanks

UV

unread,
May 8, 2018, 3:23:01 PM5/8/18
to Behaviour Driven Development
And another point, as such the Scenario 1 once user Accepts to turn on Geo, is actually the same as the Scenario 3 where the geo location is already on...So can I refer Scenario 3 in scenario 1 or I am all messing this up!

Thanks

On Tuesday, May 8, 2018 at 1:30:01 PM UTC-4, George Dinwiddie wrote:

Adam Sroka

unread,
May 8, 2018, 3:26:18 PM5/8/18
to behaviordriv...@googlegroups.com
Yeah, you’re on the right track. You could also probably pull the bit about being registered and on the landing page into the background so that you don’t have to repeat it in every scenario. 

--
You received this message because you are subscribed to the Google Groups "Behaviour Driven Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to behaviordrivendevelopment+unsub...@googlegroups.com.
To post to this group, send email to behaviordrivendevelopment@googlegroups.com.
Visit this group at https://groups.google.com/group/behaviordrivendevelopment.
For more options, visit https://groups.google.com/d/optout.

Adam Sroka

unread,
May 8, 2018, 3:28:31 PM5/8/18
to behaviordriv...@googlegroups.com
Presumably there is no need to prompt the user if the geolocation is already on. If that’s the case then it’s a different scenario, because it is a different interaction. If you prompt them anyway then it would be redundant. 

George Dinwiddie

unread,
May 8, 2018, 4:19:01 PM5/8/18
to behaviordriv...@googlegroups.com
UV,

On 5/8/18 2:24 PM, UV wrote:
> Thanks George. But does that mean, I should have scenarios like -
>
> Scenario 1: Connect/ Search an Agent when user Accepts geo location turn
> on request
> Given ...I am registered user
> And  i m on landing page
> *And I accept the system prompt for turning on geo location*
> When...I tap on Search
> then...

Yes, that's much better. I would make accepting the prompt be the When
clause, though, since that's the central point of this scenario.

As a couple of other hints, I would avoid using the first person. As you
build up a number of scenarios, it's easier if you refer to the user in
a way that identifies their role. This could be "registered user" -- the
downside is that's a bit long. You can also use a name, since an
unregistered user won't be known by name to the system. This distinction
is too fine for some people.

What do you think about this:

Scenario: User accepts prompt to turn on geolocation
Given a registered user, Bob, has geolocation turned off
And Bob visits the landing page
When Bob accepts the system prompt to turn on geolocation
Then the system displays the map

Note that if there is no system prompt, the scenario will still fail.
Have it report something like "no system prompt to accept" when that
happens.

>
> Scenario 2:  Connect/ Search an Agent when user Denies geo location turn
> on request

Scenario: User declines prompt to turn on geolocation
Given a registered user, Bob, has geolocation turned off
And Bob visits the landing page
When Bob declines the system prompt to turn on geolocation
Then the system displays an alternate search capability

>
> Scenario 3: Connect/ Search an Agent when Geo location is already on

Scenario: User already has geolocation turned on
Given a registered user, Bob, has geolocation turned on
When Bob visits the landing page
Then the system displays the map

These are all scenarios about the geolocation feature. You'll want
additional scenarios for the search functionality.

Scenario: Searching via the map
Given Bob visits the search map
When Bob selects ... on the map and searches
Then the system ...

Note that the Given here needs to do whatever it takes to get to the
search map. The easiest is probably to turn on geolocation and go to the
landing page, but how you get there isn't important to the map search
capability.

UV

unread,
May 8, 2018, 4:29:03 PM5/8/18
to Behaviour Driven Development
Thanks Adam. 

The user is prompted only when the Geo location is off. So that's why rest of the system behavior in Scenario 1 should work same as that in Scenario 3, correct?
And if yes, then I should refer rest of the steps of Scenario 1 in Scenario 3...is that fine?  
To post to this group, send email to behaviordriv...@googlegroups.com.

Adam Sroka

unread,
May 8, 2018, 4:41:57 PM5/8/18
to behaviordriv...@googlegroups.com
I’m not sure what you mean by “referring” to the other scenario. Under the hood you will be using the same step definitions, but in the Gherkin they are independent scenarios. 

To unsubscribe from this group and stop receiving emails from it, send an email to behaviordrivendevelopment+unsubsc...@googlegroups.com.
To post to this group, send email to behaviordriv...@googlegroups.com.
Visit this group at https://groups.google.com/group/behaviordrivendevelopment.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Behaviour Driven Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to behaviordrivendevelopment+unsub...@googlegroups.com.
To post to this group, send email to behaviordrivendevelopment@googlegroups.com.

UV

unread,
May 8, 2018, 5:01:56 PM5/8/18
to Behaviour Driven Development
Oh boy, Many thanks George. I believe after reading the below, now actually I am starting to grasp this thing better. I believe this requires some shift in the mindset on how to approach writing a user story. Most of the times, I used to simply write stories describing all the actions and possibilities related to that user story as a sequential flow(including any IF/Else where reqd.)

What you mention all makes sense to me. Let me ask few quick things. The below scenario for Search provides a far better understanding of what all need to be included. 

Scenario: Searching via the map 
   Given Bob visits the search map 
   When Bob selects ... on the map and searches 
   Then the system ... 

Note that the Given here needs to do whatever it takes to get to the 
search map. The easiest is probably to turn on geolocation and go to the 
landing page, but how you get there isn't important to the map search 
capability.
 
 My main aim or feature in the app is - User to find an agent in an office/branch so that user can connect with that agent.
Now this require 
1. Search for an agent
and 
2. Actually connecting with an agent (thru the connect option) once you have searched and selected one of the agents.

SO you are saying that 
1. Search - should have all the 3 scenarios of geolocation - 2 of those ending at the display of the map for Geo on (with search results displayed default on the map based on our rules) and then the scenario of Search itself which entails user's further interaction with the map to find what they were looking for?
And Scenario 2 (deny Geo On) which allows for alternate search capability  via Search tool bar, Do I need a separate Search scenario explaining that search? or Can i include that within the Scenario 2?

And then a separate user story for actually Connecting with an agent with applicable scenarios?

pls let me know.. This has surely been a great discussion for me.

George Dinwiddie

unread,
May 8, 2018, 7:45:53 PM5/8/18
to behaviordriv...@googlegroups.com
UV

On 5/8/18 5:01 PM, UV wrote:
> Oh boy, Many thanks George. I believe after reading the below, now
> actually I am starting to grasp this thing better. I believe this
> requires some shift in the mindset on how to approach writing a user
> story. Most of the times, I used to simply write stories describing all
> the actions and possibilities related to that user story as a sequential
> flow(including any IF/Else where reqd.)

Yeah, I understand where you're coming from. And you'll still need all
those detailed actions, but they should live down in the step
definitions or code called from the step definitions because they're
instructions to the computer rather than to a person. I think the proper
level for the gherkin is easier to understand when you actually talk to
a business person who wants the system to be built.

>
> What you mention all makes sense to me. Let me ask few quick things. The
> below scenario for Search provides a far better understanding of what
> all need to be included.
>
> Scenario: Searching via the map
>    Given Bob visits the search map
>    When Bob selects ... on the map and searches
>    Then the system ...
>
> Note that the Given here needs to do whatever it takes to get to the
> search map. The easiest is probably to turn on geolocation and go to the
> landing page, but how you get there isn't important to the map search
> capability.
>  My main aim or feature in the app is - User to find an agent in an
> office/branch so that user can connect with that agent.
> Now this require
> 1. Search for an agent
> and
> 2. Actually connecting with an agent (thru the connect option) once you
> have searched and selected one of the agents.

There's a third thing you've mentioned, which is requesting the user
turn on geolocation if it's not already on.

>
> SO you are saying that
> 1. Search - should have all the 3 scenarios of geolocation - 2 of those
> ending at the display of the map for Geo on (with search results
> displayed default on the map based on our rules) and then the scenario
> of Search itself which entails user's further interaction with the map
> to find what they were looking for?
> And Scenario 2 (deny Geo On) which allows for alternate search
> capability  via Search tool bar, Do I need a separate Search scenario
> explaining that search? or Can i include that within the Scenario 2?

Writing scenarios for the computer is a little different from writing
scenarios for a person. In addition to being more descriptive (what to
do, rather than detailing how to do it), you're better off having more
but smaller scenarios, each doing only one thing. This will help
identify the problem when things don't work. It also helps make the
scenarios more maintainable.

So I suggest 3 scenarios (user allows geolocation, user denies
geolocation, and geolocation already enabled) for the geolocation
feature. The happy path of geolocation turned on might verify that the
map is in the right place.

Then another 2 or more scenarios for search (searching with geolocation
and searching without geolocation). You might have more for things that
could possibly go wrong when searching. Maybe there is no agent that
matches the search criteria.

>
> And then a separate user story for actually Connecting with an agent
> with applicable scenarios?

Yes, another scenario for connecting with an agent, no matter how the
search was performed. It shouldn't be necessary to check this with
geolocation search and your other search, but you should ask a
programmer if there might be a difference. Duplication of logic in the
code can require duplication of work in the test scenarios.

>
> pls let me know.. This has surely been a great discussion for me.

I'm glad it's helped!

- George
> --
> You received this message because you are subscribed to the Google
> Groups "Behaviour Driven Development" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to behaviordrivendeve...@googlegroups.com
> <mailto:behaviordrivendeve...@googlegroups.com>.
> To post to this group, send email to
> behaviordriv...@googlegroups.com
> <mailto:behaviordriv...@googlegroups.com>.
Reply all
Reply to author
Forward
0 new messages