testing - 如何编写此 BDD 脚本?

标签 testing automation bdd requirements

我的应用程序中有一个退出按钮,我想为其编写一个故事。它的行为是这样的:

  1. 如果我在我正在编辑的表单中填写了内容,然后单击退出按钮,它会弹出一条确认消息,让我知道有未保存的内容,如果我确定要退出该页面。
  2. 如果我正在编辑的表单中没有填写任何内容,然后单击退出按钮,确认消息将不会出现,我会立即退出表单。

我目前的情况是这样的:

Given as a User on New Profile page
And I fill in the customer name = "Bob"
When I click on the Exit button
And I click on the "Ok" in the confirmation dialog
Then I will be redirected to the landing page.

我的问题是关于的部分,当我填写客户名称=“Bob”时,只涵盖了其中一个字段。我如何以简洁的方式编写故事,如果填写或选择了任何字段(下拉菜单),就会显示确认对话框?其次,我的故事是否正确?

最佳答案

您可以将场景大纲与用虚拟值填充字段的参数化步骤结合使用。

Scenario Outline: The user is taken to the landing page after exiting new user profile
    Given I am registering as a new user
    And I have filled in the "<Profile Field>" field
    And I have chosen to exit the current page
    When I confirm I want to abandon my unsaved changes
    Then I should be redirected to the landing page

Examples:
    | Profile Field |
    | Name          |
    | Phone Number  |
    | ...           |

您没有发布场景标题,它与每个步骤的措辞一样重要,所以我补上了。重要的是关注行为:

Scenario Outline: The user is taken to the landing page after exiting new user profile

步骤Given I am registering as a new user应该导航到新的用户个人资料页面。

步骤Given I have filled in the "<Profile Field>" field应该接受一个参数,您可以在其中命名要填写的字段。此步骤的定义应该使用虚拟信息填充该字段,或者盲目地在下拉列表中选择一个选项。

步骤Given I have chosen to exit the current page应单击退出按钮。请注意,没有提及“点击”任何内容。您应该避免在步骤中使用听起来像是关于如何使用用户界面的说明的语言,而是使用业务术语关注应用程序的行为。

对于 When I confirm I want to abandon my unsaved changes 同样的事情.它没有提到点击任何东西。它只关注行为(选择放弃您的更改)。步骤定义应该知道如何单击确认对话框中的“确定”按钮。确认对话框甚至存在的事实应该只通过步骤定义知道。

最后,Then I should be redirected to the landing page对用户最终到达的位置做出断言。我喜欢在我的 Then 中加入“应该”这个词脚步。如果发现在 Then 时更容易查明测试失败步骤失败。在我的步骤中,“应该”之后出现的条件通常是失败的事情。

关于testing - 如何编写此 BDD 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58442527/

相关文章:

ruby - 关于 Ruby 1.9.x 的测试框架是否达成共识?

testing - 在 jenkins 项目上构建许多 dockerfile

cucumber - 如何在我的 cucumber BDD 步骤定义中使 "the"可选?

sql-server - 我需要用于数据库单元测试的好工具

java - Spring/Junit 访问兄弟类

javascript - Chai-as-promised 不提取文本值

python - 如何在 python 中一次读取多个 csv 文件?

java - 断言失败后如何不停止执行?

testing - 在功能自动化中处理输入和输出?

java - 如何从要获取步骤定义java代码的功能文件中获取场景名称