Last active
June 18, 2018 08:26
-
-
Save paulbjensen/5678129755587594bb1dc53e25e6007b to your computer and use it in GitHub Desktop.
The hooks.js file for Cucumber, part of an article on Medium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dependencies | |
const { After, Before, AfterAll } = require('cucumber'); | |
const scope = require('./support/scope'); | |
Before(async () => { | |
// You can clean up database models here | |
}); | |
After(async () => { | |
// Here we check if a scenario has instantiated a browser and a current page | |
if (scope.browser && scope.context.currentPage) { | |
// if it has, find all the cookies, and delete them | |
const cookies = await scope.context.currentPage.cookies(); | |
if (cookies && cookies.length > 0) { | |
await scope.context.currentPage.deleteCookie(...cookies); | |
} | |
// close the web page down | |
await scope.context.currentPage.close(); | |
// wipe the context's currentPage value | |
scope.context.currentPage = null; | |
} | |
}); | |
AfterAll(async () => { | |
// If there is a browser window open, then close it | |
if (scope.browser) await scope.browser.close(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment