cucumber - 当给定状态有多个验证时如何编写 Gherkin 场景
问题描述
我是黄瓜的新手——小黄瓜世界。我正在尝试编写一个功能文件。我计划测试一个静态网页,其中包含我需要验证的大量静态内容(比如说 100 个部分)。理想情况下,如果我根据对小黄瓜的理解开始写作,它看起来如下所示:
场景:测试参与页面内容
鉴于我是余额 > 10000 的用户
当我登陆我的订婚页面时
然后section1应该正确显示
并且 section2 应该正确显示
并且 section3 应该正确显示
并且 section4 应该正确显示
- 等等 - - -
并且 section100 应该正确显示。
这绝对看起来很难看。我怎样才能把它分解成多个场景。进入该页面后,我正在测试所有内容。我没有在页面上进行任何活动。登陆后,我只需要验证所有部分。
提前致谢
解决方案
有很多方法可以做到这一点,但假设这些部分共享元素和断言,场景大纲可能是您的最佳选择。
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"
推荐阅读
- c# - 通过 WNetAddConection API 保存凭据
- python - 低波动性投资组合构建
- java - 在 Calendar.getInstance() 模拟上获取 NotAMockException
- android - wordpress 和 android studio 之间的联系
- prometheus - 将布尔度量/表达式转换为计数器
- elasticsearch - 使用管道到管道通信时关闭 Logstash
- python - 在 Django 上测试表单
- c# - 从列表中删除
List 中存在行的位置 - ubuntu - 安装freeradius 2.2.8时生成文件错误#2 eap libeap rlm_eap all modules all src all
- .net - 如何修复 .Net Azure Function App 中的“由于对象的当前状态导致操作无效”错误?