Cucumber中不明确的步骤定义

Cucumber中不明确的步骤定义,cucumber,cucumber-java,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.AmbiguousStepDefini

我有两个步骤:

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)

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

以下是步骤定义的外观:

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正则表达式也会是一样的。

以下是步骤定义的样子:

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正则表达式也会一样。

如果您的步骤定义regex对于功能文件中的两个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

如果您的步骤定义正则表达式对于要素文件中的两个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

请提供步骤定义好吗?你到底是如何定义它们的?很明显,你不止一次地实现了这个特定的步骤,或者你正在使用一些正则表达式来表示这两个步骤,它们可能都属于同一个步骤。。。分享您的步骤定义代码有助于理解您的错误。请提供您的步骤定义好吗?你到底是如何定义它们的?很明显,你不止一次地实现了这个特定的步骤,或者你正在使用一些正则表达式来表示这两个步骤,它们可能都属于同一个步骤。。。共享步骤定义代码将有助于理解您做错了什么