黄瓜 4 个可选词?

Cucumber 4 Optional Words?

@Then("a topic is (not) displayed on the chat icon of the menu")

基本上我希望 not 是可选的(如果可能的话)?以前是(是|不是)。

添加 is|is not 是捕获组的一部分,在 stepdef 中作为字符串输入。

如果你想使用正则表达式,你的字符串应该以 ^ and/or 开始,以 $ 结束。否则 Cucumber 会将它们视为 Cucumber expressions。所以:

@Then("^a topic (is|is not) displayed on the chat icon of the menu$")
public void a_topic_is_displayed(String isDisplayed){

}

如果您确实想使用 Cucumber 表达式,则必须在参数类型中捕获修饰符。所以:

@Then("a topic {isOrIsNot} displayed on the chat icon of the menu")
public void a_topic_is_displayed(boolean isDisplayed){

}

然后您将注册一个参数类型以将字符串转换为布尔值:

typeRegistry.defineParameterType(new ParameterType<>(
    "isOrIsNot",                     // name
    "is|is not",                     // regexp
    boolean.class,                   // type
    (String arg) -> "is".equals(arg) // transformer function
))