How to match these steps unambiguously in Cucumber

2019-07-19 10:46发布

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条回答
Fickle 薄情
2楼-- · 2019-07-19 11:39
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$")
查看更多
登录 后发表回答