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
You can set up multiple test targets in your SpecFlow runner profile, and it will run the tests once for each defined target. This allows us to automatically run the same test suite multiple times, with different set-up values.
Each scenario outline can have multiple tables with examples. The parameters in scenario outlines allow test runners to paste the examples from the table into the outline.
Example keyword can only be used with the Scenario Outline Keyword. Scenario Outline - This is used to run the same scenario for 2 or more different sets of test data. E.g. In our scenario, if you want to register another user you can data drive the same scenario twice.
Use scenario outlines to group examples that share the same structure, and put common data in the scenario instead of the example tables. Use background sections to expose contextual information for examples that do not share the same structure.
The Examples
keyword:
Scenario Outline: outline
Given I am a user
When I enter <x> as an amount
Then the result should be <result>
Examples:
|x|result|
|1|3 |
|1|1 |
Is for when you want the entire test to take different parameters. It sounds like you want to feed repeating parameters at the When
step.
The easier approach that won't require implementation of a StepArgumentTransformation
is to simply use a table in the when:
When I enter the following amounts
|Amount|
|2 |
|3 |
|4 |
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 StepArgumentTransformation
and Examples:
feeding in a comma-list of numbers:
Examples:
|x |result|
|1 |1 |
|1,2,3|6 |
You might be able to make use make use of an approach patrickmcgraw suggested on an answer to my question:
SpecFlow/Cucumber/Gherkin - Using tables in a scenario outline
So basically you could take the input x as a normal input string split it on a delimiter in this case ',' and then iterate over it performing your actions i.e. something like below (I haven't tested this code).
[When(@"I enter (.*) as an amount")]
public void IEnterAsAnAmount(string x)
{
var amounts = x.Split(',');
foreach (var amount in amounts)
{
// etc...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With