Background in Cucumber
Background is used to make the feature file more readable and less complex by eliminating and grouping the common steps under the background keyword .
- Background should always be added before scenario & scenario outline
- It is always best practice to add pre-condition is background
- If there is a feature file and there are multiple scenarios which are having initial steps common then those can be moved to background.
- Background should be used wisely when actually it is required because for one scenario it may be required but it may not be required for another scenario in feature file as the background executes before every scenario in a feature file .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Feature: Demo of Background feature The purpose of this feature is to test the background functionality Background: Given I navigate to “automationpractice.cm” When I Click on "Sign In" button Then User should be Authentication screen Scenario: Verify Login Functionality Given I enter “username” and “password” When I click on “Sign In” Link Then User should be logged in successfully Scenario: Create an Account Given the email id to be registered When I submit on “Create an Account” button Then User should be navigated to Registration screen |