后台步骤是否只能与 Cypress 功能文件中的某些测试场景相关?
下面是我的赛普拉斯测试框架中的一个功能:
Background:
Given User is on the Customer Management landing Page
Scenario: #6 Filter by Customer Name
When User search for "Jane Doe" in the field Search Customer Name
Then the search by Customer Name returns only the information related to that customer
上面的场景 #6 搜索特定用户和用户。验证其信息是否显示在 UI 上。
我面临的问题是,有时我从中获取数据的数据库会删除所有数据,所以如果我运行此测试&没有返回数据(Jane Doe 不存在),那么测试将失败。
我想要做的是添加一个步骤,我可以执行以下操作:
- 检查“Jane Doe”用户是否存在
- 如果“Jane Doe”存在,则不执行任何操作。
- 如果“Jane Doe”不存在,请创建该用户,以便我可以在场景#6 中搜索它们。
我面临的问题是这个功能文件中有多个场景。
即使“Jane Doe”用户仅在一个特定的测试场景中使用,将此步骤添加到 Background
是否有意义:
Background:
Given "Jane Doe" user exists
And User is on the Customer Management landing Page
“Jane Doe”用户仅与一个测试相关场景在这里。
Below is a feature in my Cypress test framework:
Background:
Given User is on the Customer Management landing Page
Scenario: #6 Filter by Customer Name
When User search for "Jane Doe" in the field Search Customer Name
Then the search by Customer Name returns only the information related to that customer
Scenario #6 above searches for a specific user & validates their information is displayed on the UI.
The issue I'm facing is that sometimes the database which I'm getting data from removes all data, so if I run this test & there's no data returned (Jane Doe doesn't exist), then the test will fail.
What I want to do is add a step where I can do the following:
- Check if "Jane Doe" user exists
- If "Jane Doe" exists, do nothing.
- If "Jane Doe" doesn't exist, create the user, so I can search for them in Scenario #6.
The problem I'm facing is that there are multiple scenario's in this feature file.
Does it make sense to add this step to the Background
like so, even if the "Jane Doe" user is only used in one specific test scenario:
Background:
Given "Jane Doe" user exists
And User is on the Customer Management landing Page
The "Jane Doe" user is only related to one test scenario here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您需要两个背景,那么您就有充分的理由创建一个新的功能文件。因此,从我在您的帖子中看到的
经验法则:需要两个背景,您需要一个新功能。
If you have a need for two backgrounds then you have a very good reason to make a new feature file. So from what I've seen in your post
Rule of thumb: Need two backgrounds, you need a new feature.
为什么不在该单一场景中简单地添加您需要的设置步骤呢?背景应该适用于功能中的所有内容,但有时您需要更多细节来充实一个特定的测试。
例子:
Why not simply add the setup steps you need in that single scenario? Background should apply to everything within the feature, but sometimes you need a little more detail to flesh out one particular test.
Example:
如果不同的场景需要不同的背景,可以使用Rule进行分组
If you need different Backgrounds for different scenarios, you can group them using Rule