Skip to content

Commit 6ad6a2d

Browse files
author
Igor Muchychka
committed
fix: document session handling pattern
1 parent d2cd6fe commit 6ad6a2d

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

site/data/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
# Patterns
2929

30+
@import './patterns/session-handling.md'
3031
@import './patterns/feature-background.md'
3132
@import './patterns/scenario-outlines.md'
3233
@import './patterns/page-objects.md'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Session handling
2+
3+
If you test a site which uses cookies, localStorage or sessionStorage its a good practise to clear them after each test case.
4+
Not doing so will make the test cases not isolated.
5+
Which can lead to not reliable, failing test where would be very hard to find the root cause of the issue.
6+
Creating a new webdriver session for every test case is not necessary.
7+
A proper cleanup and page refresh should be sufficient in most cases.
8+
As starter you can use the following support code.
9+
10+
```javascript
11+
const { client } = require('nightwatch-cucumber');
12+
const { defineSupportCode } = require('cucumber');
13+
14+
defineSupportCode(({ After }) => {
15+
After(() => client.execute(`
16+
localStorage.clear();
17+
sessionStorage.clear();
18+
`).deleteCookies().refresh());
19+
});
20+
```

site/template/res/main.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ code {
121121
pre code {
122122
font-size: inherit;
123123
color: inherit;
124+
padding: 0;
124125
}
125126

126127
@media (max-width: 769px) {

0 commit comments

Comments
 (0)