[英]Regex for step definiton in Cucumber
我正在尝试使用正则表达式将方法与我的步骤定义相匹配。 我希望该步骤与以下任何一项匹配并捕获数字组。
这是我使用的正则表达式 @Then(". \\bfuel\\b. \\bpercent\\b.* (\\d+)")
但它似乎不匹配或捕获值。 它说请执行缺少的步骤
@Then("the fuel percent should be {int}")
public void the_fuel_percent_should_be(Integer int1) {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
}
小黄瓜:
the fuel percent is '74'
the fuel percent should be '74' fuel
percent is '74'
爪哇:
@Then(".*fuel percent (is|should be) '(.*)'")
public void the_fuel_percent_should_be(String type, Integer int1) {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
}
正则表达式在线演示在这里。
您的步骤定义错误。 您需要将 {int} 更改为 (\\\\d+)。 (正则表达式 \\d+ 匹配数字)。 所以它看起来像这样:
@Then("(fuel|the fuel) percent (is|should be) (\\d+)")
匹配您提供的 3 个示例的正则表达式是:
.*fuel.*percent.*\d{1,3}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.