I'm trying to run a feature file like this:
Feature: my feature
Background:
When I do something
And I choose from a <list>
Scenario Outline: choice A
And I click on <something> after the choice A is clicked
Examples:
| list | something |
| a | 1 |
| b | 2 |
| c | 3 |
But what happens is when the second Background step runs, in the step definition, list
is a String with the value <list>
, and the first Scenario line something
is 1
, so can Background not use the variables from Examples? Putting a copy of Examples before Scenario Outline does not work.
A Background allows you to add some context to the scenarios that follow it. It can contain one or more Given steps, which are run before each scenario, but after any Before hooks. A Background is placed before the first Scenario / Example , at the same level of indentation.
The Background keyword is applied to replicate the same steps before all Scenarios within a Feature File. It should be used for defining simple steps unless we are forced to bring the application to a state which requires complicated steps to be carried out. As requested by the stakeholders of the project.
There is nothing special you have to do to combine these all in a single feature file. Declare and use them like you do while declaring multiple scenarios in a feature file. Background will be common for all scenarios and scenario outline. Also, Scenarios and Scenario Outline will be independent of each other.
Background in Cucumber is used to define a step or series of steps that are common to all the tests in the feature file. It allows you to add some context to the scenarios for a feature where it is defined. A Background is much like a scenario containing a number of steps.
The answer to your question is: no. Background is not a scenario outline. It does not take values from Examples, which is exclusively for the Scenario Outline where it is included. Let's suposse you have several Scenario Outlines. Each of them should have its own Examples sections and it is not shared between them. Consequently, it is not shared with Background either. That is why it does not work when you move Examples before Scenario Outline, as you mentioned in your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With