Skip to main content

Use Backgrounds in Behat Feature File

Background allows you to add same context to all scenarios in a feature file. Background contains several steps which will be used in every scenario. 

When a Scenario will be executed, steps written in background section will be executed first.

Note: BeforeScenario Hooks will execute even before background.

Example:

In below feature file you can observe 2 lines in background section, these are repetitive for both scenario so those are written in background section and this will execute for both.

Background:
    Given I am on the homepage
    And I go to "/user/login"

  Scenario: Using the Browser History with Mink
    And print current URL
    Then I should see an "input[id='edit-submit'][value='Log in']" element
    And I reload the page 

  Scenario: Cookie Management using Mink
    And I accept Cookies
Video Tutorial
Tags

About

Elix is a premium wordpress theme for portfolio, freelancer, design agencies and a wide range of other design institutions.