Selenium webdriver 如何将java@repeatable与cucumber一起使用

Selenium webdriver 如何将java@repeatable与cucumber一起使用,selenium-webdriver,cucumber,cucumber-jvm,cucumber-java,cucumber-junit,Selenium Webdriver,Cucumber,Cucumber Jvm,Cucumber Java,Cucumber Junit,在cucumber中,对于相同的业务逻辑,我有不同的字符串。 所以我试图找到一种方法,用一个函数标记多个小黄瓜字符串 我正在尝试下面的方法,但我无法理解如何用cucumber来表达它 例如: Scenario Outline: Looking up the definition of fruits the user is on the Wikionary home page for fruits When the user looks up the definition of

在cucumber中,对于相同的业务逻辑,我有不同的字符串。 所以我试图找到一种方法,用一个函数标记多个小黄瓜字符串

我正在尝试下面的方法,但我无法理解如何用cucumber来表达它

例如:

Scenario Outline: Looking up the definition of fruits
    the user is on the Wikionary home page for fruits
    When the user looks up the definition of the word <name>
    Then they should see the definition 'An edible fruit produced by the pear tree, similar to an apple but elongated towards the stem.'
    Examples:
    | name |
    | pear | 

Scenario Outline: Looking up the definition of orange
    Given the user is on the Wikionary home page for orange
    When the user looks up the definition of the word <name>
    Then they should see the definition 'An edible fruit produced by the pear tree, similar to an apple but elongated towards the stem.'
    Examples:
    | name |
    | pear | 
场景大纲:查找水果的定义
用户位于Wikiorial的水果主页上
当用户查找单词的定义时
然后,他们应该看到“梨树产生的可食用果实,类似于苹果,但向树干延伸。”
示例:
|名字|
|梨
场景大纲:查找橙色的定义
假设用户在orange的Wikiorial主页上
当用户查找单词的定义时
然后,他们应该看到“梨树产生的可食用果实,类似于苹果,但向树干延伸。”
示例:
|名字|
|梨
在上面的陈述中给出的是不同的,但业务功能是相同的。 我如何用repeatable with java来标记它

或者除了将字符串与|


任何周围的工作都会有帮助

有这样一个步骤定义-它应该匹配任何类似的步骤,也应该匹配非捕获

    @Given("^the user is on the Wikionary home page for (?:\\w+)$")
    public void given() {
        System.out.println("givn");
    }


这将采用不同的参数。但这将彻底破坏小黄瓜步骤文本,使其完全胡言乱语。使用此选项会非常不舒服。

您只能为上述两种情况编写一次步骤定义Java代码。它将自动为两种不同的情况运行相同的步骤定义代码:

Scenario Outline: Looking up the definition of fruits
Given the user is on the Wikionary home page for "fruits"

Scenario Outline: Looking up the definition of orange
Given the user is on the Wikionary home page for "orange"
对于上述@给定语句,您只能编写一个步骤定义方法,它将根据不同的参数配置自动为两个场景执行:

@Given("the user is on the Wikionary home page for (.*))
public void given(String fruitName) 
{
        System.out.println(fruitName);
 }

为什么不将step def的模式更改为-^用户在Wikiorial主页上的(橙色|水果)$-这是一个示例grasshopper。。主字符串可以完全不同。。这就是问题当管道对我不起作用时,如果我也试着把整个字符串。。。管道或ORU可以尝试使用非捕获组--(?:\\w+)。。。无需在方法中为此添加参数(?\\w+)表示任何字符串。。。如果它能为我工作,蚱蜢:)。。。如果我也拿示例数据来说,它的工作原理是一样的吗?谢谢蚱蜢。。。。但是,如果我只想使用(?:\\w+)$,那么我的所有给定值都应该命中该函数,而且如果我也想传递参数,那么我得到了你想要的。。。所有给定的步骤都必须调用相同的stepdefinition方法,而不仅仅是不同的结束词。我认为这是不可能的,因为我不区分给定注释、当时注释和何时注释。它们有点像标记注释。只有模式匹配才能决定调用什么方法。完成此操作的唯一方法是在步骤文本和正则表达式模式中使用固定文本,后跟“*”以匹配实际步骤。您可以有多个方法,使用相同的文本获取零个、一个、两个等数量的参数。似乎是一个黑客,但将工作感谢蚱蜢我会给你的建议尝试。我知道这一点。。。问题是用不同的给定语句标记一步定义,这些语句具有完全不同的语句/字符串。。。我想我需要在这里引用我的例子
@Given("the user is on the Wikionary home page for (.*))
public void given(String fruitName) 
{
        System.out.println(fruitName);
 }