Using Background title as Background in cucumber

♀尐吖头ヾ 提交于 2019-12-13 20:29:36

问题


Let's say I use Background feature which has the below steps:

Background: My pre-requisites
Given Step one
When Step Two
Then Step Three
....
Then Step Fifteen

So basically my Background has 15 common steps that is required for a set of scenario to run.

My question is : Is it possible to use the Background title My pre-requisites in other feature files, instead of writing down all the 15 steps as Background? Or is there any other way to handle this more gracefully.


回答1:


You can create a before hook to code the background logic and reuse it across any feature file. Even tag the hook so u can filter out scenarios where u do not want the before hook to run.




回答2:


Alongside the existing answer, you could also write a new step that compresses the functionality of the 15 steps into one or two steps that express what you are setting up.

The questions revolving around it are these:

Does the business need to know how the user will interact with the site to get to the point where you are ready to begin the test?

Can you bypass how the user will interact with the site to get there without information surrounding the test getting lost in translation between the dev team and the business?

For the former, I would go with a Background. The latter, I would go with a Hook.

For example:

  • I need to register a user in order to log in as them in my test. The Givens will start at me logging in, so I'll register the user through an API in a Hook.

  • I need to register a user in order to test the functionality of a new user on exiting the form, and various items surrounding registration, so I'll register the user, starting with some Background steps.



来源:https://stackoverflow.com/questions/51202574/using-background-title-as-background-in-cucumber

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!