首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cucumber中的词法错误是什么?

Cucumber中的词法错误是什么?
EN

Stack Overflow用户
提问于 2014-11-11 19:39:59
回答 6查看 22.9K关注 0票数 6

我试图运行一个简单的特征文件,但是我得到了异常:异常in thread "main“cucumber.runtime.CucumberException:解析特征文件时出错。

这是由: gherkin.lexer.LexingError: Lexing错误引起的

我正在尝试参数化一个When语句,并得到了这个异常:

代码语言:javascript
复制
Scenario: Login to Gmail

  Given User is on Gmail login page
  When User enters <userName> and <pwd>
  And Clicks on login button
  Then User should redirect to home page

  scenario outline(tried Examples as well but didn't worked): 
  |userName   | pwd |
  |ravivani10 | abc |
EN

回答 6

Stack Overflow用户

发布于 2014-11-12 00:40:23

场景大纲的正确语法是以关键字Scenario Outline:开头,并使用 examples :关键字列出示例。

代码语言:javascript
复制
Scenario Outline: Login to Gmail
  Given User is on Gmail login page
  When User enters <userName> and <pwd>
  And Clicks on login button
  Then User should redirect to home page
Examples:
  | userName   | pwd |
  | ravivani10 | abc |
票数 7
EN

Stack Overflow用户

发布于 2017-02-17 01:40:32

我也有同样的问题,但是我使用了正确的语法。原来我的格式化是错的,是的,你没看错:格式化。我的场景是这样的:

代码语言:javascript
复制
Scenario Outline: Confirm that hitting the endpoint returns the expected data
    Given uri url/to/a/service/to/test/param/{interval} and method GET
    And system user
    When I call the web service
    Then I expect that 'http status is' '200'
    And the following rules must apply to the response
        | element                     | expectation         | value                |
        | $                           | is not null         |                      |
        | objectType                  | value =             | Volume               |
        | objectData                  | is not null         |                      |
        | objectData                  | count =             | 1                    |
        | objectData[0].value         | is not null         |                      |
        | objectData[0].value         | data type is        | float                |
        | objectData[0].value         | value =             | <value>              |
    Examples:
        | interval | value     |
        | int1     | 355.77    |
        | int2     | 332.995   |
        | int3     | 353.71125 |

以上测试将失败,并显示Lexing错误。现在,看看我的测试中的示例片段的缩进(它在Scenario Ouline中缩进了一层)。

如果我缩进我的测试,如下所示(与Scenario大纲相同级别):

代码语言:javascript
复制
Scenario Outline: Confirm that hitting the endpoint returns the expected data
    Given uri url/to/a/service/to/test/param/{interval} and method GET
    And system user
    When I call the web service
    Then I expect that 'http status is' '200'
    And the following rules must apply to the response
        | element                     | expectation         | value                |
        | $                           | is not null         |                      |
        | objectType                  | value =             | Volume               |
        | objectData                  | is not null         |                      |
        | objectData                  | count =             | 1                    |
        | objectData[0].value         | is not null         |                      |
        | objectData[0].value         | data type is        | float                |
        | objectData[0].value         | value =             | <value>              |
Examples:
    | interval | value     |
    | int1     | 355.77    |
    | int2     | 332.995   |
    | int3     | 353.71125 |

以上测试将通过。对我来说太傻了,但这就是它的工作原理。

票数 4
EN

Stack Overflow用户

发布于 2017-04-11 23:23:21

这可能是由于在每行数据的末尾没有最终的|造成的。这不是行动的原因,但可能会对其他人有所帮助。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26864021

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档