How to match these steps unambiguously in Cucumber-JVM?

冷暖自知 提交于 2019-12-11 03:33:34

问题


Is there any way to match the following steps unambiguously?

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

I have implemented them as:

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

When Cucumber evaluates the second step it says that it is ambiguous because it could have matched either of the two step definitions, even though it has the extra words 'with param'.

Thanks in advance.


回答1:


And I should have 2 alerts with param 71

is matched by both steps because

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

matches anything that begins with

^I should have (\\d+) alerts

Terminate that step definition with $ and it will no longer match steps which keep going:

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


来源:https://stackoverflow.com/questions/24699284/how-to-match-these-steps-unambiguously-in-cucumber-jvm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!