黄瓜 AmbiguousStepDefinitionsException Java
cucumber 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+ 单词字符 (\w+)
,只能匹配小写字符 ([a-z]+)
或使用替代 (ascending|descending)
使其具体化。
例如保留捕获组:
the (\w+) filter is clicked
需要修改gherkin步骤及对应的步骤定义
1)
From: When the <priceOrder> filter is clicked
To: When the "<priceOrder>" filter is clicked
步骤定义为:
@When("^the \"([^\"]*)\" filter is clicked$")
public void theFilterIsClicked(String arg0) {
// Write code here that turns the phrase above into concrete actions
}
2)
From: Then prices are ordered by <priceOrder>
To: Then prices are ordered by "<priceOrder>"
步骤定义为:
@Then("^prices are ordered by \"([^\"]*)\"$")
public void pricesAreOrderedBy(String arg0) {
// Write code here that turns the phrase above into concrete actions
}
3)
From: When the <star> stars hotel filter is clicked
To: When the "<star>" stars hotel filter is clicked
步骤定义为:
@When("^the \"([^\"]*)\" stars hotel filter is clicked$")
public void theStarsHotelFilterIsClicked(String arg0) {
// Write code here that turns the phrase above into concrete actions
}
4)
From: Then all hotels are <star> stars
To: Then all hotels are "<star>" stars
步骤定义为:
@Then("^all hotels are \"([^\"]*)\" stars$")
public void allHotelsAreStars(String arg0) {
// Write code here that turns the phrase above into concrete actions
}
我遇到以下情况时出现 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+ 单词字符 (\w+)
,只能匹配小写字符 ([a-z]+)
或使用替代 (ascending|descending)
使其具体化。
例如保留捕获组:
the (\w+) filter is clicked
需要修改gherkin步骤及对应的步骤定义
1)
From: When the <priceOrder> filter is clicked
To: When the "<priceOrder>" filter is clicked
步骤定义为:
@When("^the \"([^\"]*)\" filter is clicked$")
public void theFilterIsClicked(String arg0) {
// Write code here that turns the phrase above into concrete actions
}
2)
From: Then prices are ordered by <priceOrder>
To: Then prices are ordered by "<priceOrder>"
步骤定义为:
@Then("^prices are ordered by \"([^\"]*)\"$")
public void pricesAreOrderedBy(String arg0) {
// Write code here that turns the phrase above into concrete actions
}
3)
From: When the <star> stars hotel filter is clicked
To: When the "<star>" stars hotel filter is clicked
步骤定义为:
@When("^the \"([^\"]*)\" stars hotel filter is clicked$")
public void theStarsHotelFilterIsClicked(String arg0) {
// Write code here that turns the phrase above into concrete actions
}
4)
From: Then all hotels are <star> stars
To: Then all hotels are "<star>" stars
步骤定义为:
@Then("^all hotels are \"([^\"]*)\" stars$")
public void allHotelsAreStars(String arg0) {
// Write code here that turns the phrase above into concrete actions
}