java - 黄瓜 AmbiguousStepDefinitionsException Java
问题描述
在以下情况下,我得到了一个 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)
任何想法?谢谢!
解决方案
您使用This pattern ^the (.*?) filter is clicked$
匹配的模式,直到第一次出现将匹配两个场景的过滤器。
如果您希望匹配第一个场景the <priceOrder> filter is clicked
并且<priceOrder>
可以例如升序或降序,您可以匹配 1+ word characters (\w+)
,仅小写字符([a-z]+)
或使用交替(ascending|descending)
来使其具体化。
例如保留捕获组:
the (\w+) filter is clicked
推荐阅读
- vb.net - 在水晶报表中创建子报表总计和总计
- reactjs - syncfusion 输入字段未连接到状态
- python - 以前可以点击的元素现在不能点击了?
- python - 检查 DynamoDB 表是否为空
- android - 如何设置圆形图像视图的高度?
- javascript - 如何调试导致 window.confirm 反复闪烁的原因?(jquery-ujs)
- c - 如何在处理不断增长的输入文件时安全地退出循环?
- java - 如何在recyclerview中显示图像?
- java - 是什么减慢了我的应用程序响应速度?
- facebook-graph-api - 更新/创建 /page/menu 或 /page/menu