Backgrounds
Background is run once per scenario (every scenario within that feature), i.e:
Feature: Hello World
Background:
Given I go to the homepage
When I search for "Hello, World!"
Scenario: See a result
Then I should see a result
Scenario: See multiple results
Then I should see a maximum of 10 results
Is the same as writing:
Feature: Hello World
Scenario: See a result
Given I go to the homepage
When I search for "Hello, World!"
Then I should see a result
Scenario: See multiple results
Given I go to the homepage
When I search for "Hello, World!"
Then I should see a maximum of 10 results
Scenarios relying on other Scenarios
Scenarios should not depend on each other at all. The order in which the tests are run should be able to change without compromising functionality of the tests.
This will mean setting up your tests on a per scenario basis. One example of this is with Backgrounds (as shown above), or getting to the same point during the "Given" steps.
If I were to do this with the example above:
Feature: Hello World
Scenario: See a result
Given I have searched for "Hello, World!"
Then I should see a result
Scenario: See multiple results
Given I have searched for "Hello, World!"
Then I should see a maximum of 10 results
Instead of doing something like this (struck it out so that it's clear not to do this one):
Feature: Hello World
Scenario: See a result
Given I have searched for "Hello, World!"
Then I should see a result
Scenario: See multiple results
Then I should see a maximum of 10 results