Reputation: 53
Below is the code:
Background: Navigate to mail from inbox
Given I login into gmail as valid user
When I click on mail from Inbox
Then mail should be open
Scenario: Delete mail from Inbox
When I open mail from Inbox page
And I click on Delete icon
Then mail should be deleted
Scenario: Sent mail from Draft box
When I open mail from Draft box
And I click on Sent button
Then mail should be sent
So here I want that background should be executed only once for this feature file. Once background steps gets executed and navigated to Inbox page then scenario should be executed one after another. Once all scenarios from that feature file are executed then browser should be closed.
Right now it is executing background step then moving to first scenario executing it and being on same browser, it still goes to execute steps from background.
Upvotes: 3
Views: 2802
Reputation: 5825
You are looking for the BeforeFeature hook with a scoping to this one feature file.
So you need a hook like this:
[BeforeFeature()]
[Scope(Feature = "feature title")]
public static void SetupInbox()
{
/// your automation code
}
This is only executed once per feature file.
Also be aware that depending on your test runner, the order of scenario execution is not the same order in your feature file.
Also we are highly discourage that you are writing scenarios that are depending on each other. Like unit tests, scenarios should be able to be executed on their own.
Full disclosure: I am the Community Manager and long-time contributor to SpecFlow
Upvotes: 1