File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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'
Original file line number Diff line number Diff line change 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+ ```
Original file line number Diff line number Diff line change @@ -121,6 +121,7 @@ code {
121121pre code {
122122 font-size : inherit;
123123 color : inherit;
124+ padding : 0 ;
124125}
125126
126127@media (max-width : 769px ) {
You can’t perform that action at this time.
0 commit comments