Sac*_*hin 0 java selenium cucumber-java
@Then("a topic is (not) displayed on the chat icon of the menu")
Run Code Online (Sandbox Code Playgroud)
基本上我希望如果可能的话不要是可选的?以前是(是|不是)。
添加 is|is not 是捕获组的一部分,在 stepdef 中作为字符串输入。
如果您想使用正则表达式,您应该以 开始字符串和^/或以 结束字符串$。否则 Cucumber 会将它们视为Cucumber 表达式。所以:
@Then("^a topic (is|is not) displayed on the chat icon of the menu$")
public void a_topic_is_displayed(String isDisplayed){
}
Run Code Online (Sandbox Code Playgroud)
如果您确实想使用 Cucumber 表达式,那么您必须捕获参数类型中的修饰符。所以:
@Then("a topic {isOrIsNot} displayed on the chat icon of the menu")
public void a_topic_is_displayed(boolean isDisplayed){
}
Run Code Online (Sandbox Code Playgroud)
并且您需要注册一个参数类型以将字符串转换为布尔值:
typeRegistry.defineParameterType(new ParameterType<>(
"isOrIsNot", // name
"is|is not", // regexp
boolean.class, // type
(String arg) -> "is".equals(arg) // transformer function
))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2340 次 |
| 最近记录: |