代码之家  ›  专栏  ›  技术社区  ›  Shubham Jain

如何忽略cucumber中相同值的stepdefinition变量声明

  •  3
  • Shubham Jain  · 技术社区  · 6 年前

    对于相同的值,如何忽略cucmber中的StepDefinition变量声明?

    所以假设我有如下例子:

    Scenario Outline: Looking up the definition of fruits
        Given the user is on the Wikionary home page
        When the user <name> 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 |
    

    @When("^the user (.*?) looks up the definition of the word (.*?)$")
    public void when(String name, String name2){
      System.out.println(name);
      System.out.println(name2);
    }
    

    现在在上面的步骤中,我已经创建了两个不必要的变量,我这样做是因为我的cucumber报告应该在when语句中的两个位置获得名称。

    请让我知道如果你需要任何进一步的信息或如果我遗漏了什么。

    1 回复  |  直到 6 年前
        1
  •  3
  •   Grasshopper    6 年前

    在regex中使用非捕获组- (?:.*?) 任何一组。方法中只需要一个参数。

    https://agileforall.com/just-enough-regular-expressions-for-cucumber/