My Behat Scenario Outline的步骤定义返回undefined

问题描述 投票:0回答:1

我正在使用Behat v3.0为我的代码创建测试,但我在我的功能文件的场景大纲中有几个步骤仍未定义。

我的场景大纲的一个示例:

Scenario Outline: Send email validation messages
    Given I have the email <email>
    When I send the email
    Then the response status code should be "500"
    And I get a message from the <variable> variable that reads <message>

    Examples:
        | email | variable | message                                  |
        |       | email    | The email field is required.             |
        | -1    | email    | The email must be a valid email address. |
        | email | email    | The email must be a valid email address. |

我使用了http://docs.behat.org/en/stable/guides/1.gherkin.html#scenario-outlines的文档。

为了定义步骤,我在FeatureContext.php中有两个问题步骤的步骤定义方法:“我有电子邮件<email>”和“我从变量读取消息<message>”:

/**
 * @Given I have the email :email
 */
public function iHaveTheEmail($email)
{
    // Save the email address
}

/**
 * @Then I get a message from the :variable variable that reads :message
 */
public function iGetAMessageFromTheVariableThatReads($variable, $message)
{
    // Check the response for the validation errors
}

我使用了http://docs.behat.org/en/v3.0/guides/2.definitions.html的文档

运行Behat的输出坚持认为这些步骤仍未定义。只有带有与示例列表关联的参数的步骤才会出现此问题。 “响应状态代码应为'500'”步骤按预期工作。

我找不到在Scenario Outline中定义步骤的具体示例,而且Behat的文档通常很少。

我可以用Behat v2.5中的正则表达式注释来定义步骤,但这是唯一的解决方案吗?

php bdd behat gherkin
1个回答
1
投票

你应该为你的参数使用引号:

Scenario Outline: Send email validation messages
    Given I have the email "<email>"
    When I send the email
    Then the response status code should be "500"
    And I get a message from the "<variable>" variable that reads "<message>"

或者您可以使用正则表达式,例如Mink Extension:

https://github.com/Behat/MinkExtension/blob/master/src/Behat/MinkExtension/Context/MinkContext.php#L38

© www.soinside.com 2019 - 2024. All rights reserved.