gpt4 book ai didi

java - cucumber 4 可选单词?

转载 作者:行者123 更新时间:2023-12-02 01:17:51 25 4
gpt4 key购买 nike

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

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

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

最佳答案

如果您想使用正则表达式,您应该以 ^ 开始字符串和/或以 $ 结束字符串。否则 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){

}

并且您需要注册一个参数类型以将字符串转换为 boolean 值:

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

关于java - cucumber 4 可选单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58240790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com