黄瓜中不明确的步骤定义

时间:2015-08-18 08:51:38

标签: cucumber cucumber-java

我有两个步骤:

When the user launches site with the base configuration with url parameter set to http://www.youtube.com
When the user launches site with the base configuration

这两个步骤分为两种不同的方案。 在运行自动化时,我得到以下错误:

Caused by: cucumber.runtime.AmbiguousStepDefinitionsException.

  When the user launches site with the base configuration with url parameter set to http://www.youtube.com(android-config.feature:37) matches more than one step definition:
  the user launches site with the base configuration in ConfigGlue.launches the base configuration()
  the user launches site with the base configuration with url parameter set to(.*) in ConfigGlue.the user launches the cnfiguration(String)

如何为这两个步骤使用相同的步骤定义。

2 个答案:

答案 0 :(得分:0)

以下是您的步骤定义的样子:

When(/^the user launches site with the base configuration( with url parameter set to (.*))?$/) do |custom, url|
  if custom
    p "Using custom url: #{url}"
  end
end

注意:那是Ruby。我猜Java正则表达式会是一样的。

答案 1 :(得分:0)

如果功能文件中的两个when条件的步骤定义正则表达式不同,则不应存在任何黄瓜歧义错误。您可以尝试在以下步骤定义中保持整个要素文件行不变。我在Ruby中使用如下所示,在Java中应该类似。

When("the user launches site with the base configuration with url parameter set to http://www.youtube.com") do
   # Write code here that turns the phrase above into concrete actions
end

When("the user launches site with the base configuration") do
   # Write code here that turns the phrase above into concrete actions
end

或如下所示:

When(/^the user launches site with the base configuration with url parameter set to http://www.youtube.com$/) do
   # Write code here that turns the phrase above into concrete actions
end

When(/^the user launches site with the base configuration$/) do
   # Write code here that turns the phrase above into concrete actions
end
相关问题