Scenario-equivalent background

I am new to SpecFlow and set up several test functions / scripts that are designed for authenticated users of different types of roles. I do this through browser automation with Coypu.

So, I have a background step in this function to configure user registration in this type of roles.

Background: Given I am logged in as a ...some role I'm interested in... 

After each script in this function, I want to register the user again (otherwise, the step of entering the background mode will not work for the next scenario - I support the same instance of the Coypu browser open between tests).

I found the [AfterScenario] annotation that I could use, but since it covers all the scripts in all the functions (as far as I understand ...), this will affect the scripts for unverified users.

I could cover [AfterScenario] with [Scope(Feature="Some Feature")] , I suppose, but I expect that you will need to enter / exit before and after a number of functions that I'm testing, and I'm not interested in indicating all this with a bunch of magic lines.

So, I am wondering if there is something that I can add to the Feature file, like the equivalent of Background, but run after each script in this function. (Or, alternatively, maybe the on / off method for each scenario is not the best way to do something?)

+6
source share
1 answer

There is no "Postground" function in specflow, but you can achieve something similar with tag filters .

In most of our projects, we use tags to indicate scenarios that have specific set / break logic. Then we use BeforeScenario / AfterScenario hooks to execute the logic:

 [BeforeScenario("authentication")] public void BeforeAuthenticationScenario() { //... } [AfterScenario("authentication")] public void AfterAuthenticationScenario() { //... } 

And you can mark individual scripts or entire functions:

 @authentication Feature: Some feature requires authentication @authentication Scenario: Some scenario requires authentication 

So, in your code you will have only one magic line β€œauthentication”, and in your functions you can apply declarative logic using a tag.

+10
source

Source: https://habr.com/ru/post/917783/


All Articles