我收到 AmbigouslyStepDefinitionsException 的日志:
cucumber.runtime.AmbiguousStepDefinitionsException: ✽.Given I am logged out(features/performance.feature:7) matches more than one step definition:
^I am logged out$ in PerformanceListSteps.i_am_logged_out()
^|I should be on |the list page$ in LoginSteps.i_should_be_on_the_list_page()
运行 cucumber 测试时。我对这种态度有点新鲜,我真的很高兴获得帮助。
最佳答案
问题出在第二个正则表达式模式上:
^|I should be on |the list page$
管道符号 (|
) 是一种变化。所以这个正则表达式基本上意味着它将匹配替代方案之一:
- 空字符串(位于第一个
|
的左侧) 我应该在
列表页面
匹配空字符串的正则表达式可以匹配 0 个字符,因此它将匹配任何字符串。这在某种程度上取决于实现,但在 Cucumber-JVM 的情况下,我确认如果我将类似的正则表达式模式添加到我的步骤定义之一,它会与项目中的所有步骤匹配。
解决方案
这里最好的解决方案是从正则表达式中删除管道,因为(通常)您希望正则表达式尽可能具体,只为进入步骤定义的变量留下变体。
所以您需要将正则表达式模式更改为:
^I should be on the list page$
它将与任何 Gherkin 关键字后面的语句相匹配(Given
/When
/Then
等),例如:
Then I should be on the list page
关于java - 在 Android 上使用 Cucumber 时出现 AmbigouslyStepDefinitionsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43761830/