编写包含用户决策提示的 SpecFlow 场景

发布于 2024-11-02 17:43:41 字数 368 浏览 1 评论 0原文

我是 SpecFlow 和 BDD 的新手,在编写需要用户做出选择的场景时遇到了障碍。基本上情况是这样的:

Scenario:  Deleting a record
Given I am on the edit record page
And I click the delete button
Then I should see a prompt asking for confirmation

我不知道如何继续下去。这里有两种测试路径,一种是当用户对确认说“确定”时,另一种是当用户说“取消”时。

我想说“如果我点击确定”,然后是“那么记录应该被删除”,等等。但似乎应该以更好的方式分解它。

你会如何重新表述这个场景?

I'm new to SpecFlow and BDD and I've hit a roadblock in writing a scenario that requires a user to make a choice. Essentially here is the scenario:

Scenario:  Deleting a record
Given I am on the edit record page
And I click the delete button
Then I should see a prompt asking for confirmation

I'm not sure how to proceed beyond this point. There are two paths to test here, one for when the user says "OK" to the confirmation, and one for when the user says "Cancel".

I want to say "And If I click OK" followed by "Then the record should be deleted", etc. But it seems like it should be broken up a better way.

How would you reword this scenario?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨后彩虹 2024-11-09 17:43:41

我建议在更高的层次上编写你的场景。在您的场景中避免使用按钮、单击和文本框,并尝试谈论用户想要完成的任务 - 您的系统的行为。然后,与页面的实际交互隐藏在步骤定义中。

所以在你的情况下,会是这样的;

假设我在记录页面上,

当我删除一条记录时

,那么我应该看到一条确认消息

,然后在 [When("I delete a record")] 的步骤定义中,您可以实现单击删除按钮和确定按钮“您确定吗”或删除记录所需的任何内容。

我希望这一点很清楚。写在我的手机上;)

I would recommend writing your scenarios on a higher level. Avoid buttons, clicks and textboxes in your scenarios and try to talk about what the user want to accomplish - the behaviour of your system. The actual interaction with the page is then hidden in the step definitions.

So in your case that will be something like;

Given I am on the record page

When I delete a record

Then I should see a confirmation message

In the step definition for [When("I delete a record")] you then implement the clicking on the delete button and the Ok-button for "are you sure" or whatever is needed to delete the record.

I hope this was clear. Wrote it on my phone ;)

娇妻 2024-11-09 17:43:41

这里实际上可能存在三种情况。第一个重点正如马库斯建议的那样:

Given I am on the record page
When I delete a record
Then I should see a confirmation message

但是确认对话框的行为是否也有场景?

Given I am presented with a confirmation message
When I confirm the action
Then the action proceeds

Given I am presented with a confirmation message
When I cancel the action
Then the action does not proceed

There might actually be three scenarios here. The first one focusses as Marcus suggests:

Given I am on the record page
When I delete a record
Then I should see a confirmation message

But are there also scenarios for the behaviour of the confirmation dialog?

Given I am presented with a confirmation message
When I confirm the action
Then the action proceeds

And

Given I am presented with a confirmation message
When I cancel the action
Then the action does not proceed
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文