【问题标题】:Capturing conditions in scenarios场景捕捉条件
【发布时间】:2021-06-07 18:50:29
【问题描述】:

如果我有成功场景的条件,我可以写成Given, And, And... Then button is enabled.,但我怎么写If either x,y, or z aren't set, the button remains disabled的否定场景。

下面是一个正面场景的例子:

Scenario: Enable the Add to Favorites button
When the consumer is viewing an item
And the consumer selects an item
And the consumer selects a size
And the consumer selects a quantity
Then the Add to Favorites button becomes enabled

可以(或应该)在一种情况下完成吗?由于所有成功的“按钮启用”场景都需要这 3 个元素,我会将它们添加到 Before() 挂钩吗?

感谢您的时间和关注。

【问题讨论】:

    标签: gherkin cucumberjs


    【解决方案1】:

    我会这样做:

    Scenario: Do not enable the Add to Favorites button without a selected item
    When the consumer is viewing an item
    And the consumer selects a size
    And the consumer selects a quantity
    Then the Add to Favorites button does not become enabled
    
    Scenario: Do not enable the Add to Favorites button without a selected size
    When the consumer is viewing an item
    And the consumer selects an item
    And the consumer selects a quantity
    Then the Add to Favorites button does not become enabled
    
    Scenario: Do not enable the Add to Favorites button without a selected quantity
    When the consumer is viewing an item
    And the consumer selects an item
    And the consumer selects a size
    Then the Add to Favorites button does not become enabled
    

    【讨论】:

      【解决方案2】:

      作为场景大纲的方法最好测试多个输入和输出。所以考虑相同的场景如下:

          Scenario Outline: Verify the "Add to Favorites" button state
              When the consumer is viewing an item
              And the item is "<itemCondition>"
              And the item size is "<sizeCondition>"
              And the item quantity is "<quantityCondition>"
              Then the "Add to Favorites" button becomes "<buttonState>"
              Examples: Conditions
                  | itemCondition | sizeCondition | quantityCondition | buttonState|
                  | Selected      | Selected      | Selected          | enabled    |
                  | Not Selected  | Not Selected  | Not Selected      | disabled   |
                  | Selected      | Not Selected  | Not Selected      | disabled   |
                  | Selected      | Selected      | Not Selected      | disabled  |
      

      【讨论】:

        【解决方案3】:

        所有的好反应!感谢您的输入。以下是我使用的表格:

        Feature: Add item to Favorites List
        
            As a consumer (guest or member) who is shopping on the App, I'd like the ability to favorite items that I maybe interested in.
        
        Rule: Any consumer, guest or member, can favorite an item after selecting pre-requisites (size/quantity/shipping)
        
        Scenario: Favorite an item - member
        Given I have logged in
        And I have searched the product inventory
        When I choose a desired item with specified pre-requisites
        Then the app should allow me to add it to my member favorites list
        
        Scenario: Favorite an item - guest
        Given I have not logged in
        And I have searched the product inventory
        When I choose a desired item with specified pre-requisites
        Then the app should allow me to add it to my guest favorites list
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-03-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-10-21
          • 2017-07-15
          相关资源
          最近更新 更多