Background is the prerequisites to run before all the scenarios in a feature file.
When we write a Feature in Specflow framework, we write multiple Scenarios. All scenarios start with a specific point, so it's better to write down all common or repeated steps in one place instead of altogether scenarios.
Only one Background per feature file is allowed.
The Background can contain one or more test steps.
Background should be top of all the Scenarios.
Syntax :
Background: Delete the existing customers in the application
Given user connect the database
And delete the customer records
Customer.feature
Feature: To test the withdrawal,deposit and transaction feature
Background: Delete the existing customers in the application
Given user connect the database
And delete the customer records
Scenario: verify user able to add the customer
Given user navigate the url in the browser
When user select the manager login
And add the customers with mandatory fields
If the Scenario Outline is used then Background will run for all the set of data before.
Feature: To test the withdrawal,deposit and transaction feature
Background: Delete the existing customers in the application
Given user connect the database
And delete the customer records
Scenario Outline:
Given user navigate the url in the browser
When user select the manager login
And add the customer with "", "", ""
Then verify the success message with customer Id
Then verify the added customer displayed in Customers Tab
Examples:
|username |lastname |postcode |
|Tester | tester | 32334 |
|Develop | Develop | 32334 |
|Designer | Designer | 32334 |
Output:
Background steps are executed...
User Navigate the URL ...
Manager Login Selected ...
Username - Tester, Lastname - tester, Pincode - 32334
Success message displayed
Added customer displayed in Customer Tab
Background steps are executed...
User Navigate the URL ...
Manager Login Selected ...
Username - Develop, Lastname - Develop, Pincode - 32334
Success message displayed
Added customer displayed in Customer Tab
Background steps are executed...
User Navigate the URL ...
Manager Login Selected ...
Username - Designer, Lastname - Designer, Pincode - 32334
Success message displayed
Added customer displayed in Customer Tab