I have two cucumber step definition like as shown below
Map<String, Object> values = new HashMap<>();
:
:
@And("^(. ) has a value (false|true)$")
public void addValues(String key, Boolean value) {
values.put(key, value);
}
@And("^(. ) has a value (. )$")
public void addValues(String key, String value) {
values.put(key, value);
}
In the first step definition I want to set the value as boolean and in the second definition the value as String but some how I'm getting io.cucumber.core.runner.AmbiguousStepDefinitionsException
for the given statements
Given name has a value Manu
And isMajor has a value true
:
:
Can someone please tell me how to differentiate the step definition with the same statement but with different argument type
My cucumber version is 6.8.1
CodePudding user response:
The step isMajor has a value true
matches both regular expressions. So Cucumber can't figure out which method to call. If you make the other regular expression match any argument except true/false
your step definitions are no longer ambiguous.
You can probably do that with a negative lookahead but I'll leave that as exercise for some one else.
CodePudding user response:
Change this:
^(. ) has a value (. )$
to this:
^(. ) has a value ((?!true|false). )$
This will eliminate ambiguity.