Dan
Dan

Reputation: 9791

How to match these steps unambiguously in Cucumber-JVM?

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.

Upvotes: 2

Views: 527

Answers (1)

Dave Schweisguth
Dave Schweisguth

Reputation: 37617

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$")

Upvotes: 5

Related Questions