使用黄瓜中的不同数据多次运行同一步骤

时间:2019-09-10 12:52:34

标签: cucumber

在执行其他步骤之前,是否可以通过给定数据(产品和状态)多次运行“给定”步骤?我在下面尝试过,但是失败了

        while (true)
        {
            if (weekendDays.Contains(date.DayOfWeek) || 
                      holidayDates.Contains(date))
                date = date.AddDays(1);
            else
                break;
        }
        return date;

1 个答案:

答案 0 :(得分:1)

您正在混合使用方案大纲示例和数据表。 “示例”表位于“方案大纲”的所有步骤下方。

您可以改用DataTable并对其进行迭代以创建对象。

Scenario: Creating multiple products
 Given I have created the following products 
      |products   |  statuses     |
      |P1         |  In Progress  |
      |P1         |  Completed    |
      |P1         |  Stopped      |
    When I have navigated to products page
    Then I should see all products created

@Given("I have created the following products")
public void createMultipleProducts(DataTable data) {
     //Iterate the data and create each product
}