【问题标题】:How to write Gherkin scenarios when there are multiple validations for a given state当给定状态有多个验证时如何编写 Gherkin 场景
【发布时间】:2020-04-24 21:09:37
【问题描述】:

我是黄瓜的新手——小黄瓜世界。我正在尝试编写一个功能文件。我计划测试一个静态网页,其中包含我需要验证的大量静态内容(比如说 100 个部分)。 理想情况下,如果我根据对小黄瓜的理解开始写作,它看起来如下:

场景:测试参与页面内容

假设我是一个余额 >10000 的用户

当我登陆我的参与页面时

那么section1应该会正确显示

并且section2应该可以正确显示

并且section3应该可以正确显示

并且section4应该可以正确显示

--等等-----

并且section100应该可以正确显示。

这绝对看起来很难看。我怎样才能把它分解成多个场景。 进入该页面后,我正在测试所有内容。我没有在页面上进行任何活动。登陆后,我只需要验证所有部分。

提前致谢

【问题讨论】:

    标签: cucumber cucumber-jvm gherkin cucumberjs


    【解决方案1】:

    有多种方法可以做到这一点,但假设这些部分共享元素和断言,场景大纲可能是您的最佳选择。

    Scenario Outline: Verify the display of all sections on the Engagement Page
    Given I am a user with >10000 balance
    When I land of Engagement Page
    Then the header of <section> should read "<headerText>"
    And the icon of <section> should be displayed
    And the body of <section> should read "<bodyText>"
    
    Examples:
      | section   | headerText         | bodyText        |
      | Section 1 | This is Header #1  | This is Body #1 |
      | Section 2 | Header Text of #2  | Body Text of #2 |
    ... etc
    

    如果这些部分在结构上是独一无二的,那么您将面临为每个部分编写一个场景(或更多,取决于您的风格 - 我个人不喜欢在一个案例中包含多个断言):

    例如,section1 有标题、图标和正文,您最终会遇到以下三种情况:

    Scenario: Verify display of header in Section 1
    Given I am a user with >10000 balance
    When I land of Engagement Page
    Then the header of Section 1 should read "text"
    
    Scenario: Verify display of icon in Section 1
    Given I am a user with >10000 balance
    When I land of Engagement Page
    Then the icon of Section 1 should be displayed
    
    Scenario: Verify display of body text in Section 1
    Given I am a user with >10000 balance
    When I land of Engagement Page
    Then the body of Section 1 should read "text"
    

    如果您对每个测试的多个断言感到满意:

    Scenario: Verify display of Section 1
    Given I am a user with >10000 balance
    When I land of Engagement Page
    Then the header of Section 1 should read "text"
    And the icon of Section 1 should be displayed
    And the body of Section 1 should read "text"
    

    【讨论】:

    • 我想处理你提到的第二个例子。但我的问题基本上是所有验证都是当用户登陆该页面时。所以当我以第二个示例方式实现时,给定的以及从第二个场景开始的实现将根本没有代码,因为用户已经在那个页面上.是否可以给定那些,以及什么时候没有代码的步骤实现
    • 你会有测试依赖,这是一个主要的禁忌。然后,您可能想考虑使用包含重复步骤和代码的背景(它是 Gherkin 关键字 - Google 它的用途),用于检测您在执行任何操作之前是否已经处于给定的“设置”状态并跳过其余部分如果是,则为步骤代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多