You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36Lines changed: 36 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,6 +48,42 @@ to make IDE/linter happy
48
48
49
49
We had a pattern to import those explicitly, but for some reason it was messing up the watch mode on Linux :-( (#10)
50
50
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
+
51
87
### Sharing context
52
88
53
89
You can share context between step definitions using `cy.as()` alias.
0 commit comments