1

我有两个步骤,例如:

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)

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

4

2 回答 2

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

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

于 2015-08-19T05:09:27.490 回答
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
于 2018-10-11T14:06:35.300 回答