【发布时间】:2019-08-11 04:49:36
【问题描述】:
我有一个 Cucumber 步骤,如下所示:
When I enter the credentials for the user
还有一个说
When I enter the correct credentials for the user
对应的步骤定义为:
@When("I enter the ([^\"]*) for the user$")
public void stepDefinition(String cred){
//code
}
@When("I enter the correct ([^\"]*) for the user$")
public void otherStepDefinition(String cred){
//other code
}
但是我的第二个黄瓜步骤(“我为用户输入正确的凭据”)与第一步的定义相匹配,只是在凭据中添加了“正确”一词。
- 我该如何解决这个问题?
- 我是正则表达式的新手。是否可以从“何时”步骤中排除“正确”部分,以便我可以有一个可以用“正确”部分“扩展”的基本步骤?
【问题讨论】:
-
尝试
@When("I enter the (\\S*) for the user$")作为第一条规则 -
更改订单。
-
@WiktorStribiżew 这行得通!你能解释一下为什么吗?并将其作为答案发布,以便我接受。
-
添加了更多选项的答案。
标签: regex automated-tests cucumber bdd