Here's a simple scenario outline:
Scenario Outline: Add two numbers
Given I have entered <firstNumber> into the calculator
And I have entered <secondNumber> into the calculator
When I press <button>
Then the result should be <expectedResult> on the screen
Scenarios:
| firstNumber | secondNumber | button | expectedResult |
| 1 | 2 | plus | 3 |
| 2 | 2 | plus | 4 |
| 4 | 5 | plus | 9 |
I'd like to run each of these sets of test data under multiple sets of other conditions. I can do like this:
Scenario Outline: Add two numbers
Given I have entered <firstNumber> into the calculator
And I have entered <secondNumber> into the calculator
When I press <button>
Then the result should be <expectedResult> on the screen
Scenarios:
| firstNumber | secondNumber | button | expectedResult |
| 1 | 2 | plus | 3 |
| 2 | 2 | plus | 4 |
| 4 | 5 | plus | 9 |
| 1 | 2 | add | 3 |
| 2 | 2 | add | 4 |
| 4 | 5 | add | 9 |
| 1 | 2 | + | 3 |
| 2 | 2 | + | 4 |
| 4 | 5 | + | 9 |
...or like this:
Scenario Outline: Add two numbers (plus)
Given I have entered <firstNumber> into the calculator
And I have entered <secondNumber> into the calculator
When I press plus
Then the result should be <expectedResult> on the screen
Scenarios:
| firstNumber | secondNumber | expectedResult |
| 1 | 2 | 3 |
| 2 | 2 | 4 |
| 4 | 5 | 9 |
Scenario Outline: Add two numbers (+)
Given I have entered <firstNumber> into the calculator
And I have entered <secondNumber> into the calculator
When I press +
Then the result should be <expectedResult> on the screen
Scenarios:
| firstNumber | secondNumber | expectedResult |
| 1 | 2 | 3 |
| 2 | 2 | 4 |
| 4 | 5 | 9 |
Scenario Outline: Add two numbers (add)
Given I have entered <firstNumber> into the calculator
And I have entered <secondNumber> into the calculator
When I press add
Then the result should be <expectedResult> on the screen
Scenarios:
| firstNumber | secondNumber | expectedResult |
| 1 | 2 | 3 |
| 2 | 2 | 4 |
| 4 | 5 | 9 |
...but both of those involve a lot of duplication. What I'd REALLY like to write is something like this:
Scenario Outline: Add two numbers
Given I have entered <firstNumber> into the calculator
And I have entered <secondNumber> into the calculator
When I press
| button |
| plus |
| + |
| add |
Then the result should be <expectedResult> on the screen
Scenarios:
| firstNumber | secondNumber | expectedResult |
| 1 | 2 | 3 |
| 2 | 2 | 4 |
| 4 | 5 | 9 |
...and have each Scenario execute "multiplicatively" against each of the values for "button".
Is there a good way to do this?
Here is one of the possible options.
In the step def split the
expectedResultsandbuttonswith,and then compare the array length. Once the array length match then get the item based on index from both the arrays and do one of the below 2 options.Option 1: Implement the logic directly in the step def.
Option 2: call the steps
When I press plusandThen the result should be <expectedResult> on the screensteps with in the step.