Skip to content

Commit 8bf932d

Browse files
kayvanbreelgandecki
authored andcommitted
docs: Add background section to documentation (#117)
1 parent 2e2d64a commit 8bf932d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,42 @@ to make IDE/linter happy
4848

4949
We had a pattern to import those explicitly, but for some reason it was messing up the watch mode on Linux :-( (#10)
5050

51+
### Background section
52+
53+
Adding a background section to your feature will enable you to run steps before every scenario. For example, we have a counter that needs to be reset before each scenario. We can create a given step for resetting the counter.
54+
55+
```javascript
56+
let counter = 0;
57+
58+
given("counter has been reset", () => {
59+
counter = 0;
60+
});
61+
62+
when("counter is incremented", () => {
63+
counter += 1;
64+
});
65+
66+
then("counter equals {int}", value => {
67+
expect(counter).to.equal(value);
68+
});
69+
```
70+
71+
```
72+
Feature: Background Section
73+
74+
Background:
75+
Given counter has been reset
76+
77+
Scenario: Basic example #1
78+
When counter is incremented
79+
Then counter equals 1
80+
81+
Scenario: Basic example #2
82+
When counter is incremented
83+
When counter is incremented
84+
Then counter equals 2
85+
```
86+
5187
### Sharing context
5288

5389
You can share context between step definitions using `cy.as()` alias.

0 commit comments

Comments
 (0)