如何重复Specflow Scenario Outline中的步骤

Jus*_*ony 6 specflow

简而言之,我需要的是创建一个Scenario Outline,其中包含一个可重复的步骤,而不必使用多个AND键入它,如下所示:

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     |
Run Code Online (Sandbox Code Playgroud)

但是,我想做类似以下的事情:

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     |
Run Code Online (Sandbox Code Playgroud)

基本上,我希望"我输入金额"分别运行3次和2次.

我发现这个问题的最接近的是如何重新运行具有不同参数的黄瓜场景轮廓?,但我想在放弃并使用带有逗号分隔列表或类似内容的StepArgumentTransformation之前仔细检查.

我最后的答案更像是这样的:

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     |
Run Code Online (Sandbox Code Playgroud)

似乎没有一个好的方法可以留空值,但这非常接近我正在寻找的解决方案

Ada*_*rth 6

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     |
Run Code Online (Sandbox Code Playgroud)

适用于您希望整个测试采用不同参数的时间.听起来你想在When步骤中提供重复参数.

不需要实现a的更简单的方法StepArgumentTransformation是简单地在when中使用表:

When I enter the following amounts
|Amount|
|2     |
|3     |
|4     |
Run Code Online (Sandbox Code Playgroud)

然后简单地迭代表中的所有行以获取您的参数.这避免了需要具有转换的临时方法.

替代方案包括使用更多步骤或通过参数解析,正如您所说,使用StepArgumentTransformation.

当然,如果你需要测试多个重复项,你可以使用它们StepArgumentTransformationExamples:输入逗号列表中的数字:

Examples:
|x    |result|
|1    |1     |
|1,2,3|6     |
Run Code Online (Sandbox Code Playgroud)