In a nutshell, what I need is to create a Scenario Outline with a step that is repeatable without having to type it in using multiple AND’s as I am currently doing below:
Scenario Outline: outline
Given I am a user
When I enter <x> as an amount
And I enter <x2> as an amount
Then the result should be <result>
Scenarios:
|x|x2|result|
|1|2 |3 |
|1|0 |1 |
However, I would like to do something like the following:
Scenario Outline: outline
Given I am a user
When I enter <Repeat: x> as an amount
Then the result should be <result>
Scenarios:
|x |result|
|1,2,3|6 |
|1,2 |3 |
Basically, I want the “I enter as an amount” to run 3 and 2 times respectively.
The closest I have found to this question is How do I re-run a cucumber scenario outline with different parameters? , but I wanted to double check before giving up and using a StepArgumentTransformation with a comma separated list or something similar.
The final answer that I went with is something more like this:
Scenario Outline: outline
Given I am a user
When I enter the following amounts
| Amount1 | Amount 2| Amount3|
| <Amt1> | <Amt2> | <Amt3> |
Then the result should be <result>
Scenarios:
|Amt1 |Amt2 |Amt3 |result|
|1 |2 |3 |6 |
There does not seem to be a good way to leave a value blank though, but this is pretty close to the solution I was looking for
The
Exampleskeyword:Is for when you want the entire test to take different parameters. It sounds like you want to feed repeating parameters at the
Whenstep.The easier approach that won’t require implementation of a
StepArgumentTransformationis to simply use a table in the when:Then simply iterate all the rows in table to get your arguments. This avoids needing to have an interim method for the transformation.
Alternatives include using more steps or by parameter parsing, so as you say, use the
StepArgumentTransformation.Of course, if you need to test multiple repeating items, you could use both
StepArgumentTransformationandExamples:feeding in a comma-list of numbers: