【发布时间】:2019-12-29 11:04:44
【问题描述】:
在以下情况下,我收到了 AmbiguousStepDefinitionsException,我不明白如何解决这个问题。请帮忙!
场景
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 |
步骤文件
@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));
}
错误
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)
有什么想法吗?谢谢!
【问题讨论】:
-
此模式
^the (.*?) filter is clicked$将匹配两种方案。您也许可以使第一个模式不那么通用the (\w+) filter is clicked
标签: java regex automation cucumber