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

时间:2018-09-02 12:48:29

标签: cucumber cucumber-jvm cucumberjs cucumber-java cucumber-junit

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

所以假设我有如下示例:

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);
}

现在,在上面的步骤中,我创建了两个不必要的变量,我这样做是因为我的黄瓜报告应该在when语句的两个位置获取名称。
如果我只输入一个变量,那么黄瓜将抛出错误。

如果您需要任何进一步的信息或我什么都不见,请告诉我。

1 个答案:

答案 0 :(得分:2)

在正则表达式-(?:.*?)中将非捕获组用于任何组。方法中仅需要一个参数。

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