Fran :
I'm getting an AmbiguousStepDefinitionsException with the following case, I don't understand how to solve this problem. Please help!
scenario
Scenario Outline: Testing the price ordering filter
When the <priceOrder> filter is clicked
Then prices are ordered by <priceOrder>
Examples:
| priceOrder |
| ascending |
| descending |
Scenario Outline: Testing the stars hotel filter
When the <star> stars hotel filter is clicked
Then all hotels are <star> stars
Examples:
| star |
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
step file
@When("^the (.*?) filter is clicked$")
public void thePriceOrderFilterIsClicked(String priceOrder) {
hotelPage.activatePriceFilter(priceOrder);
}
@When("^the (\\d+) stars hotel filter is clicked$")
public void theStarStarsHotelFilterIsClicked(int star) {
hotelPage.activateStarsFilter(String.valueOf(star));
}
@Then("^all hotels are (\\d+) stars$")
public void allHotelsAreStarStars(int star) throws InterruptedException {
hotelPage.checkHotelStars(String.valueOf(star));
}
error
cucumber.runtime.AmbiguousStepDefinitionsException: ✽.When the 5 stars hotel filter is clicked(hotelSearches.feature:16) matches more than one step definition:
^the (.*?) filter is clicked$ in HotelSearchesSteps.thePriceOrderFilterIsClicked(String)
^the (\d+) stars hotel filter is clicked$ in HotelSearchesSteps.theStarStarsHotelFilterIsClicked(int)
Any idea? Thanks!
The fourth bird :
The pattern that you use This pattern ^the (.*?) filter is clicked$
matching until the first occurrence of filter which will match both scenario's.
If you want the first scenario matched the <priceOrder> filter is clicked
and the <priceOrder>
can be for example ascending or descending, you could match 1+ word characters (\w+)
, only lowercase chars ([a-z]+)
or use an alternation (ascending|descending)
to make it specific.
For example keeping the capturing group:
the (\w+) filter is clicked