【问题标题】:How to make "the" optional in my cucumber BDD Step Definitions?如何在我的黄瓜 BDD 步骤定义中使“the”可选?
【发布时间】:2016-10-28 19:31:33
【问题描述】:

我想匹配以下任一 BDD:

Then the response status should be "200"
Then response status should be "200"

我想将“the”设为可选。我希望这两个规则映射到相同的步骤。

这是我的尝试,但它不起作用:

@Then("^(?:the | )response status should be \"([^\"]*)\"$")
public void the_response_status_should_be(String arg1) {
    ...
}

【问题讨论】:

    标签: cucumber bdd cucumber-jvm gherkin cucumber-java


    【解决方案1】:

    这可能有效..."^(?:the )*response status should be \"([^\"]*)\"$"

    【讨论】:

    • 这不起作用,但添加 ?: 确实有效!我会编辑你的答案;D
    【解决方案2】:

    使用 Cucumber 表达式可以很容易地完成,只需将可选文本用括号括起来,如下所示:

    (the )response status should be "200"
    

    Read more...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多