【问题标题】:Step definition not recognized无法识别步骤定义
【发布时间】:2017-08-11 14:15:33
【问题描述】:

我正在使用量角器和黄瓜进行 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|

我对“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

“然后”没有被识别。 我的错在哪里?

【问题讨论】:

    标签: protractor chai cucumberjs scenarios


    【解决方案1】:

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

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

    【讨论】:

    • 相同的java等价物是^I should see the element with id \"([^\"]*)\"$
    • @Ashish Deshmukh:两个引号 \" 最终出现相同的问题,即无法识别方法。
    • @alecxe:我也尝试过使用正则表达式,但是我在它周围使用了引号\",所以找不到方法!
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      您的 Gherkin 语法不正确,应在大括号内加引号

      尝试更改以下行

      Then I should see the element with id <elemid>    
      

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

      然后生成steps,应该会变成这样,

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-11-17
        • 1970-01-01
        • 2014-01-10
        • 2021-09-06
        • 1970-01-01
        • 2017-03-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多