Skip to content

Commit

Permalink
fix: document session handling pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Muchychka committed Nov 16, 2017
1 parent d2cd6fe commit 6ad6a2d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions site/data/index.md
Expand Up @@ -27,6 +27,7 @@

# Patterns

@import './patterns/session-handling.md'
@import './patterns/feature-background.md'
@import './patterns/scenario-outlines.md'
@import './patterns/page-objects.md'
Expand Down
20 changes: 20 additions & 0 deletions site/data/patterns/session-handling.md
@@ -0,0 +1,20 @@
## Session handling

If you test a site which uses cookies, localStorage or sessionStorage its a good practise to clear them after each test case.
Not doing so will make the test cases not isolated.
Which can lead to not reliable, failing test where would be very hard to find the root cause of the issue.
Creating a new webdriver session for every test case is not necessary.
A proper cleanup and page refresh should be sufficient in most cases.
As starter you can use the following support code.

```javascript
const { client } = require('nightwatch-cucumber');
const { defineSupportCode } = require('cucumber');

defineSupportCode(({ After }) => {
After(() => client.execute(`
localStorage.clear();
sessionStorage.clear();
`).deleteCookies().refresh());
});
```
1 change: 1 addition & 0 deletions site/template/res/main.css
Expand Up @@ -121,6 +121,7 @@ code {
pre code {
font-size: inherit;
color: inherit;
padding: 0;
}

@media (max-width: 769px) {
Expand Down

0 comments on commit 6ad6a2d

Please sign in to comment.