问题
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