问题
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