如何在Cucumber-JVM中明确地匹配这些步骤?

时间:2014-07-11 13:46:41

标签: java cucumber cucumber-jvm

有没有办法明确地匹配以下步骤?

And I should have 2 alerts
And I should have 2 alerts with param 71

我已将它们实现为:

@And("^I should have (\\d+) alerts")
@And("^I should have (\\d+) alerts with param (\\d+)")

当Cucumber评估第二步时,它表示它是模糊的,因为它可以匹配两个步骤定义中的任何一个,即使它有额外的单词' with param'。

提前致谢。

1 个答案:

答案 0 :(得分:5)

And I should have 2 alerts with param 71

由两个步骤匹配,因为

@And("^I should have (\\d+) alerts")

匹配开始

的任何内容
^I should have (\\d+) alerts

使用$终止该步骤定义,它将不再匹配继续执行的步骤:

@And("^I should have (\\d+) alerts$")