Using a background step like an Outline Step

蓝咒 提交于 2020-01-25 09:49:04

问题


I would like to be able to define a set of run rules that will run for every scenario in the file. and the easiest place to put these would be in the background but they would need to have an examples table much like a scenario outline.

    Feature: Example Feature File
    In order to perform as task 
    As I user 
    I want this test to work 

Background: 
 Given I have used <data> in my test 
 Examples: 
 | data           | 
 | test string    | 
 | test String  2 | 


Scenario Outline: Running a test
Given I have prepared the test data 
When I run the test 
Then The test should pass 

Can anyone think of a way i can make this work ( or something similar) as ive got over 200 tests and im a little loathed to add this to each one of them


回答1:


Unfortunately you need to put this in each scenario. You cannot provide example data for the background.




回答2:


One way to do that is using createSet and createInstance in background. If you have data in tables , you can use assist helpers . They both support table structure and you can use them in Background

The other way is to implement above table in Beforescenario hook . You can further categorize using tag scoping

In both cases , you will have to implement passing data using properties or context or some other way. You can read about featureContext

While implementing, keep in mind though that Background will run before first step in each scenario but after any Before hook

Imo, it is still worth implementing even if it takes a bit more effort than having to include data in each scenario.



来源:https://stackoverflow.com/questions/58992647/using-a-background-step-like-an-outline-step

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