Tuesday, May 5, 2015

Background in Cucumber

Background in Cucumber is used to define a step or series of steps that are common across tests or scenarios within the feature file. 

A Background steps is run before every scenario in the feature file.

For example, two scenarios are listed below:

Scenario 1: Purchase order creation
Step 1: Launch the eCommerce website
Step 2: Login into website
Step 3: Search for a product
Step 4: Add to Cart
Step 5: Payment
Step 6: Submit order

Scenario 2: Update existing Purchase order
Step 1: Launch the eCommerce website
Step 2: Login into website
Step 3: Search for existing order
Step 4: Add new product
Step 5: Submit order

Step 1 and Step 2 are common steps in these two scenarios. So It recommends defining these common steps under the Background section, which will be run for each scenario in the feature file. 

Feature: Standard Purchase order 

Background:
Given Launch the eCommerce website
And Login into website
Scenario: Purchase order creation
Then Search for a product
And Add to Cart
And Payment
When Submit order
Scenario: Update existing Purchase order
Then Search for existing order
And Add new product
When Submit order

No comments:

Post a Comment

Selenium 3 vs Selenium 4