What is the background in Cucumber?
Background:
Now execute the above scenarios:
Based on requirements, it's up to you how you will use the background in the cucumber framework.
Please comment below to feedback or ask questions.
Background:
- The background is a keyword provided in Gherkin language.
- Generally, we can find many repeatable steps in all of the scenarios in a Feature.
- Since the steps are repeated in every scenario, we can group them under the background section.
- A Background is a set of steps that can be executed before each scenario but after @Before Hooks.
Feature: Demo on cucumber framework
Description: The purpose of this feature is explain Background keyword
Scenario: This is First Scenario
Given I navigated to Amazon Website
And I enter user name
And I enter password
And I click login button
When I navigated to Home Page
Then I searched for Samsung mobile
Scenario: This is second Scenario
Given I navigated to Amazon Website
And I enter user name
And I enter password
And I click login button
When I navigated to Home Page
Then I searched for Micromax mobile
Here, we observe there are repeated steps in the scenarios (First 5 steps in each scenario).
So, by using background keyword we can write only once, those repeated steps in background section.
Demo on cucumber backgroud keyword:
FirstFeatureFile.feature
Step Definitions for above scenarios are implemented as below:Feature: Demo on cucumber framework Description: The purpose of this feature is explain Background keyword Background: Given I navigated to Amazon Website And I enter user name And I enter password And I click login button When I navigated to Home Page
Scenario: This is First Scenario Then I searched for Samsung mobileScenario: This is second Scenario Then I searched for Micromax mobile
cucumber background keyword |
cucumber background keyword |
Cucumber background scenario execution |
Please comment below to feedback or ask questions.
No comments:
Post a Comment
Please comment below to feedback or ask questions.