Cucumber Selenium Java-Running Scenarios Outline with multiple examples

Rajesh Kumar picture Rajesh Kumar · Oct 9, 2017 · Viewed 7.9k times · Source

Can anyone help me to find solution for the below use case:

Currently I am working on Selenium Automation using Cucumber and I have the below Issue.

I need to automate scenario in web application.

Scenario Outline
Login as "<User>" and purchase items and checkout by selecting "<Option>".
Examples:
|User|
|Arun|
|Ajay|
|Ashok|
Examples
|Option|  
|one|
|two|
|Three|

Here the I need to see 9 times running the same scenario till (option 3) for each user.

I mean When Arun login he should checkout and select option one (EG: he place an order without description entered) and then again Arun should login and should checkout and select option two (this time he enters the description and place an order) and then again arun login as select option 3 (EG: Enters description and selects some checkbox and place an order).

This need to repeated for Ajay and Ashok as well. How do I achieve this in Cucumber. Can I use Multiple Examples for single Scenario Outline.

Or Is it possible to have Examples in Background.

This is one of the important use case I need to automate and been trying out with various options in Cucumber. But nothing works.

Thanks in Advance

Answer

Murthi picture Murthi · Oct 9, 2017

You can write the scenario outline as given below. it may be useful.

Scenario Outline: Login as <user> and Purchase item with the option <option>
When I login as <user>
And I enter the description <description> 
And I checkout the item using the option <option>

Examples:
|user|description|option|
|Arun |Some Desc|One  |
|Arun |         |One  |
|Arun |Some Desc|two  |
|Ajay |         |three|
|Ajay |Some Desc|two  |
|Ajay |Some Desc|three|
|Ashok|         |One  |
|Ashok|Some Desc|two  |
|Ashok|Some Desc|three|

This will run all the steps with different user, description and options.