Cucumber 黄瓜:只重复一步几次

Cucumber 黄瓜:只重复一步几次,cucumber,bdd,cucumber-java,Cucumber,Bdd,Cucumber Java,如果我有这样一个场景: Scenario Outline: test Given I am on page X When I fill the <name> on field <fieldID> And I click on Ok button Then I should see something Examples: name | fieldID | "Jhon" | "name1"| "Max" | "name2" | "Paul" | "name3"|

如果我有这样一个场景:

Scenario Outline: test
Given I am on page X
When I fill the <name> on field <fieldID>
And I click on Ok button
Then I should see something

Examples:
name   | fieldID   |
"Jhon" | "name1"|
"Max" | "name2" |
"Paul" | "name3"|
场景大纲:测试
鉴于我在第X页
当我在球场上加油时
我点击Ok按钮
那我应该看看
示例:
名称|字段ID|
“Jhon”|“name1”|
“Max”|“name2”|
“保罗”|“名字3”|

我可以只运行“何时”步骤3次,然后单击“确定”吗?还是我必须写下所有3个不同的步骤?我需要这3个信息来单击“确定”,这与我使用不同的登录值测试3次的登录不同,您不需要3个不同的步骤,因为场景大纲将根据“示例:”中的数据自动生成不同的测试。在您的示例中,SpecFlow将生成3个不同的测试,因为“示例:”中有3行。简而言之,您只需要一个场景,它将执行n次,其中n是“示例:”中的行数。

您必须使用不同的参数编写三个步骤,如果使用场景大纲,则每个场景都会重复所有步骤。根据您的要求,您可以尝试以下步骤

Scenario: test
   Given I am on page X
   When  I fill the "John" on field "name1"
   When  I fill the "Max" on field "name2"
   When  I fill the "Paul" on field "name3"
   And   I click on Ok button
   Then  I should see something

您也可以编写您的场景,如:

Scenario Outline: test
Given I am on page X
When I fill in the following names
 name   | fieldID |
 "Jhon" | "name1" |
 "Max"  | "name2" |
 "Paul" | "name3" |
And I click on Ok button
Then I should see something
然后,该表将作为数组提供给When语句的steps实现


我想问的一个问题是,实际的名字真的重要吗?如果没有,那么您也可以在我填写3个名称时编写
,然后使用steps方法填写一些任意名称。

谢谢!你让我知道名字不重要,哈哈!两个答案合一