1
votes

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

3

3 Answers

1
votes

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.

0
votes

An idea would be something like this:

Scenario Outline: Login with purchase and checkout
  Given I am on the login page
  When I log in as "<User>"
  And I purchase items
  Then I can checkout using the "<Option>"

Examples:
| User | Option |
| Arun | one    |
| Arun | two    |
| Arun | three  |
| Ajay | one    |
| Ajay | two    |
| Ajay | three  |
| Ashok| one    |
| Ashok| two    |
| Ashok| three  |

This will run each option for each user. I don't know how your code looks, but using the above format should be easy to adapt. Check out the documentation as well as how to write good Gherkin

0
votes

Your step, and the Scenario Outline seem to be doing too much.

If the users have expressly different permissions, or the method of getting to the checkout changes for each of the 3 users, then of course, 9 scenarios may be necessary for the test, if not however, you may only have to write 3 scenarios to test this.

The way I would write this test:

Background:
   Given I am logged in as "Arun"
     And I have gone to the checkout after selecting various products
   When I purchase the items

Scenario Outline: Checkout descriptions
   Then I should be able to checkout <with?> a description

 Examples:
   | with?   |
   | with    |
   | without |

Scenario: Checkout with description and accept the terms of service*
   Then I should be able to checkout with a description
     And I should be able to accept the terms of service*

* Replace "accept the terms of service" with the meaning behind your selecting of the check boxes.

Gherkin is there to bridge the conversational gap between the development team and the business, so making sure that the language used is understandable by a non-technical business person is essential. Leave implementation details out of the feature file, as it is all about describing how the system behaves.

Edit

If there is real business benefit in running the test across the 2 other users (and it isn't solely being run to set up test data, which should be done in a before hook), then perhaps you would need to do something more like this:

Scenario Outline: Checkout descriptions
   Given I am logged in as "<user>"
     And I have gone to the checkout after selecting various products
   When I purchase the items
   Then I should be able to checkout <with?> a description

 Examples:
   | user  | with?   |
   | Arun  | with    |
   | Ajay  | with    |
   | Ashok | with    |
   | Arun  | without |
   | Ajay  | without |
   | Ashok | without |

Scenario Outline: Checkout with description and accept the terms of service*
   Given I am logged in as "<user>"
     And I have gone to the checkout after selecting various products
   When I purchase the items
   Then I should be able to checkout with a description
     And I should be able to accept the terms of service*

 Examples:
   | user  |
   | Arun  |
   | Ajay  |
   | Ashok |