黄瓜4个可选单词?

问题描述 投票:0回答:1
@Then("a topic is (not) displayed on the chat icon of the menu")

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

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

java selenium cucumber-java
1个回答
0
投票

如果要使用正则表达式,则应以^开头和/或以$结尾。否则,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
))
© www.soinside.com 2019 - 2024. All rights reserved.