【问题标题】:cucumber AmbiguousStepDefinitionsException黄瓜 AmbiguousStepDefinitionsException
【发布时间】:2019-12-28 04:54:19
【问题描述】:

在以下情况下,我收到了 AmbiguousStepDefinitionsException,我找不到任何原因导致此问题。请帮忙!

场景

 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 ([^\\\"]*) stars hotel filter is clicked$")
    public void theStarStarsHotelFilterIsClicked(String star) {
        hotelPage.activateStarsFilter(star);
    }

    @Then("^all hotels are ([^\\\"]*) stars$")
    public void allHotelsAreStarStars(String star) throws InterruptedException {
        hotelPage.checkHotelStars(star);
    }

    @When("^the ([^\\\"]*) filter is clicked$")
    public void thePriceOrderFilterIsClicked(String priceOrder) {
        hotelPage.activatePriceFilter(priceOrder);
    }

错误

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 ([^\"]*) stars hotel filter is clicked$ in HotelSearchesSteps.theStarStarsHotelFilterIsClicked(String)

【问题讨论】:

    标签: java automation cucumber


    【解决方案1】:

    异常很明显:

    “点击了 5 星酒店过滤器” 匹配

    @When("^the ([^\\\"]*) filter is clicked$")

    这似乎不是你的本意。也许将第一个表达式更改为:

    @When("^the (\\d+) stars hotel filter is clicked$")

    对第二个表达式做同样的事情。让它更具体。

    【讨论】:

    • 请教我 ([^\\"]* 和 (\d+) 是什么意思,新手。谢谢!
    • 非常感谢
    • 感谢@DawoodibnKareem 建议在代码周围使用反引号。我还不小心删除了您的评论 - 抱歉!
    • 不,我删除了我的评论。在您采取行动之后将其留在那里是没有意义的。
    • @Fran - 简而言之,"([^\\\"]*)" 表示“任何不包含双引号字符的字符串(包括空字符串)”,"(\\d+)" 表示“任何一个或多个数字的序列”。因此,如果您希望输入是数字,则使用后者是有意义的。
    猜你喜欢
    • 2019-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    相关资源
    最近更新 更多