How can I repeat the steps in the specflow script abstract

In short, I need to create a script diagram with a step that can be repeated without entering it using several And, as I am doing now:

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 “I entered as quantity” to run 3 and 2 times, respectively.

The closest I found to this question is How to re-run the outline of a cucumber script with different parameters? but I wanted to double check before giving up and using StepArgumentTransformation with a comma separated list or something similar.

The last answer I went with is something more:

 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 seems to be no good way to leave the value blank, but this is pretty close to the solution I was looking for

+6
source share
3 answers

Keyword Examples :

 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 | 

It goes when you want the whole test to take different parameters. It looks like you want to feed the duplicate options in the When step.

A simpler approach that does not require the implementation of StepArgumentTransformation is to simply use a table when:

 When I enter the following amounts |Amount| |2 | |3 | |4 | 

Then just iterate over all the rows in the table to get your arguments. This avoids the need for a temporary conversion method.

Alternatives include using more steps or parsing parameters, so as you say, use StepArgumentTransformation .

Of course, if you need to test multiple duplicate elements, you can use both StepArgumentTransformation and Examples: by supplying a comma-separated list of numbers:

 Examples: |x |result| |1 |1 | |1,2,3|6 | 
+6
source

You might be able to use the patrickmcgraw approach suggested to answer my question:

SpecFlow / Cucumber / Gherkin - Using Tables in a Script Schema

Thus, basically you can take input x as a regular input line, dividing it by a separator in this case, "," and then repeat its execution, for example, something like below (I have not tested this code).

 [When(@"I enter (.*) as an amount")] public void IEnterAsAnAmount(string x) { var amounts = x.Split(','); foreach (var amount in amounts) { // etc... } } 
+1
source

This works for me and looks more readable:

 Scenario: common scenarios goes here one time followed by scenario outline. Given I am a user Scenario Outline: To repeat a set of actions in the same page without logining in everytime. When I enter <x> as an amount Then the result should be <result> Examples: |x|result| |1|2| |2|4| |4|8| 
0
source

Source: https://habr.com/ru/post/898400/


All Articles