【问题标题】:Cucumber "OR" clause?黄瓜“OR”子句?
【发布时间】:2014-08-21 09:04:04
【问题描述】:

是否可以在 Cucumber 中指定某种“OR”(替代)子句?

即如果我对某个事件有两个有效的响应,如果其中任何一个发生,我希望我的测试通过。

类似的东西:

"When I press a button"
"Then I should see the text 'Boo'"
"Or I should see the text 'Foo'"

我的特定场景是登录屏幕。当我尝试使用一些随机密码登录时,如果服务器正常工作,我应该会看到错误消息“密码无效”,否则会看到消息“网络错误”。

【问题讨论】:

    标签: cucumber automated-tests calabash


    【解决方案1】:

    您不能真正使用 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!|
    

    检查清单:

        @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));
            }
        } 
    

    【讨论】:

      【解决方案2】:

      不支持 OR。您可以使用 Given、When、Then、And 和 But。请参考http://docs.behat.org/en/v2.5/guides/1.gherkin.html

      但也许您可以使用 But 关键字来实现您正在寻找的东西。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-04-22
        • 2019-12-28
        • 1970-01-01
        • 2020-08-28
        • 2017-04-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多