2017-08-11 111 views
1

我正在使用量角器和黄瓜进行e2e测试。 该方案大纲是这样的:步骤定义不确认

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| 

的 “则” 部分是喜欢我的步骤定义:

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 

“那么”并不是被认可的。 我的错误在哪里?

回答

1

没有亲自使用cucumber严重的是,但不应该将Then定义有这样的正则表达式与捕获组代替:

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

与java相同的是'^我应该看到带有id的元素“([^ \”] *)\“$' –

+0

@alecxe:谢谢。这是解决方案。 :) – saab

+0

@Ashish Deshmukh:两个引号\“最终出现在同一个问题中,即方法未被识别 – saab

0

添加此/^I go to "([^"]*)"$/,你正试图赶上从功能参数文件。您的代码将是

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

你的小黄瓜语法不正确,应该有周围的迪蒙德括号报价

尝试改变以下线

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  
});