是否可以在 Cucumber 中指定某种“OR”(替代)子句?
即如果我对某个事件有两个有效响应,如果其中任何一个发生,我希望我的测试能够通过。
类似的事情:
"When I press a button"
"Then I should see the text 'Boo'"
"Or I should see the text 'Foo'"
我的特定场景是登录屏幕。当我尝试使用一些随 secret 码登录时,如果服务器正在工作,我应该看到一条错误消息“密码无效”,如果服务器不工作,我应该看到一条消息“网络错误”。
最佳答案
您无法真正使用 Gherkin 定义 OR 功能,但您可以传入一个列表并检查列表中的值之一是否与返回的值匹配。
定义列表:
Then the greeting service response will contain one of the following messages
|Hello how are you doing?|
|Welcome to the front door!|
|How has your day been?|
|Come right on in!|
检查 list :
@Then("the get messages service response will contain one of the following messages")
public void text_matching_one_of_the_following(List<String> greetingMessages){
boolean success = false;
for(String message : greetingMessages){
assertTrue(textMatchesResponse(message));
}
}
关于 cucumber "OR"条款?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25422279/