In general, Copying and pasting scenarios which has different values but same scenario is waste of time.In order to minimize this, Scenario outline could be used.
For example : These two scenarios are similar but having different values.
Scenario: Eat 5 out of 12 Given there are 12 cucumbers When I eat 5 cucumbers Then I should have 7 cucumbers Scenario: Eat 5 out of 20 Given there are 20 cucumbers When I eat 5 cucumbers Then I should have 15 cucumbers
Scenario Outline: Eating
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers
Examples:
| start | eat | left |
| 12 | 5 | 7 |
| 20 | 5 | 15 |
The Scenario outline steps provide a template which never runs directly. A Scenario Outline will run once for each row.The Scenario Outline uses placeholders, which contains anything present in ‘< >’ in the Scenario Outline’s steps.This will always skip the first row.So the first row should be headings. In this example ‘start’ ‘eat’ ‘left’ are headings.
For example:
Given <I'm a placeholder and I'm ok>
So by using this method we can avoid duplication of writing scenarios in feature files.Cucumber turns each example—each table row—into a concrete scenario before looking for matching step definitions.In most cases, I recommend starting with concrete scenarios and refactoring to scenario outlines once you have a few scenarios working with the correct step definitions.