无法识别步骤定义

Step definition not recognized

我正在使用量角器和黄瓜进行端到端测试。 场景大纲如下:

Scenario Outline: Visit HomeScreen
Given I am on the homescreen
When I do nothing
Then I should see the element with id <elemid>    

Examples:
|elemid|
|scan-sample-image|
|how-to-run|
|navigation-button|

我对 "then" 部分的步骤定义如下:

this.Then(/^I should see the element with id \<elemid\>$/, function(id){
//some code      
});

但是当我调用量角器时,我看到了这个:

Scenario: Visit HomeScreen
V Given I am on the homescreen
V When I do nothing
? Then I should see the element with id scan-sample-image

Scenario: Visit HomeScreen
V Given I am on the homescreen
V When I do nothing
? Then I should see the element with id how-to-run

Scenario: Visit HomeScreen
V Given I am on the homescreen
V When I do nothing
? Then I should see the element with id navigation-button

"Then" 未被识别。 我的错误在哪里?

个人还没有认真地使用过 cucumber,但是你的 Then 定义不应该有这个带有 捕获组 的正则表达式:

/^I should see the element with id (.*?)$/

将此 /^I go to "([^"]*)"$/ 添加到您试图从功能文件中捕获参数的位置。您的代码将是

this.Then(/^I should see the element with id "([^"]*)"$/, function(id){
//some code      
});

您的 Gherkin 语法不正确,菱形括号周围应该有引号

尝试更改以下行

Then I should see the element with id <elemid>    

Then I should see the element with id "<elemid>"    

然后生成步骤,应该变成这样,

this.Then(/^I should see the element with id (.*)$/, function(id){
   //some code      
});