cucumber.runtime.AmbiguousStepDefinitionsException: ✽.Given I am an admin user(src/test/resources/features/alerts.feature:9) matches more than one step definition:
I am an admin in LoginStepDefinitions.iAmAnAdmin()
^I am an admin user$ in AlertsStepDefinitions.iAmAUser()
at cucumber.runtime.RuntimeGlue.stepDefinitionMatch
I am giving 2 different definitions. I am not sure why this error is coming up.
You're getting this error because
/I am an admin/ # in LoginStepDefinitions.iAmAnAdmin()
and
/^I am an admin user$/ # in AlertsStepDefinitions.iAmAUser()
both match
"I am an admin user" # at src/test/resources/features/alerts.feature:9
The first regexp matches everything that the second regexp does, so any step that matches the second regexp will match both and cause this error.
You can fix it by making the first regexp not a subset of the second regexp. One option is to change the first regexp to
/^I am an admin$/
I generally find it's a good idea to require step definitions to match the entire step (i.e. to begin with ^
and to end with $
) until I find a good reason not to. But it's up to you how to organize your steps so that they're all unambiguous and make sense to the reader.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With