Say I have:
@Given("first name is $firstName")
@Given("first name is $firstName and last name is $lastName")
The following step would be marked as ambiguous:
Given first name is John and last name is Smith
Without using quotes to surround the first parameter, how can I fix this step so it only matches the second one? Using quotes to surround both the parameters separately also has the same ambiguity issue.
Is there a limit on how long each parameter is? Are there certain characters that can't be passed in?
You can solve this by using step priorities, as documented here: http://jbehave.org/reference/stable/prioritising-steps.html
Your problem would be solved by setting a higher priority to the variant with two parameters:
@Given("first name is $firstName")
@Given(value = "first name is $firstName and last name is $lastName", priority = 1)
I tried your example and with this combination, the two steps were separated.
(Edit: my initial solution had quotes for the parameters, but it works without as well)
I think this scenario can be write this way:
Given first name is John
And last name is Smith
And the steps:
@Given("first name is $firstName")
@And("last name is $lastName")
You can create the person object first an set the name and the last name in the "@Given" steps.
If you need add another property, like email, you just need create another step:
@And("the email is $email")
public addEmail(String email) {
person.setEmail(email);
}
So this problem not gonna happen and you code will be more reusable.
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