黄瓜方案大纲和具有通用步骤定义的示例

时间:2014-03-25 16:10:05

标签: cucumber cucumber-jvm

我有一个Feature文件,如下所示:

Scenario Outline: Create ABC

  Given I open the application

  When I enter username as <username>

  And I enter password as <password>

  Then I enter title as <title>

  And press submit


Examples:

| username | password | title |

| Rob      | xyz1      | title1 |

| Bob      | xyz1      | title2 |

这要求我对每个值都有步骤定义。我可以改为

通用步骤定义,可以为

中的每个用户名或密码或标题值进行映射

示例部分。

,而不是说

@When("^I enter username as Rob$")
public void I_enter_username_as_Rob() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

我可以输入

@When("^I enter username as <username>$")
public void I_enter_username_as_username(<something to use the value passed>) throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

2 个答案:

答案 0 :(得分:28)

您应该使用此格式

Scenario Outline: Create ABC

    Given I open the application
    When I enter username as "<username>"
    And I enter password as "<password>"
    Then I enter title as "<title>"
    And press submit

哪会产生

@When("^I enter username as \"([^\"]*)\"$")
public void I_enter_username_as(String arg1) throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}

arg1现在将传递您的用户名/值。

答案 1 :(得分:1)

Cucumber会自动在控制台中提供缺少的步骤。只需做一个干运行,缺少的步骤将显示在控制台中。

{{1}}

See for more Cucumber options