我正在使用behaat 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中为两个问题步骤定义了步骤定义方法:"我有电子邮件
/**
* @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中找不到定义步骤的具体示例,而且文档对于behavior来说通常是稀疏的。
我可能能够像在Behat v2.5中那样用regex注释定义步骤,但这是唯一的解决方案吗?
你的参数应该使用引号:
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