diff --git a/examples/backstop.json b/examples/backstop.json index 552dd34..f603e0f 100644 --- a/examples/backstop.json +++ b/examples/backstop.json @@ -19,6 +19,7 @@ ], "onBeforeScript": "onBefore.js", "onReadyScript": "onReady.js", + "cookiePath": "cookies.json", "scenarios": [ { "label": "Click an wait for selector example", diff --git a/examples/cookies.json b/examples/cookies.json new file mode 100644 index 0000000..25d38d6 --- /dev/null +++ b/examples/cookies.json @@ -0,0 +1,7 @@ +[ + { + "domain": "domain", + "name": "cookie-name", + "value": "cookie-value" + } +] diff --git a/examples/engine_scripts/onBefore.js b/examples/engine_scripts/onBefore.js index 3550280..a45ec39 100644 --- a/examples/engine_scripts/onBefore.js +++ b/examples/engine_scripts/onBefore.js @@ -1,4 +1,4 @@ module.exports = async (page, scenario, vp, ir, Engine, config) => { - await require(config.backstopjsAddons.path + '/loadCookies')(page, scenario); + await require(config.backstopjsAddons.path + '/loadCookies')(page, scenario, config); await require(config.backstopjsAddons.path + '/userAgentByViewport')(page, scenario, vp); }; diff --git a/loadCookies.js b/loadCookies.js index 85b90cd..974800f 100644 --- a/loadCookies.js +++ b/loadCookies.js @@ -1,8 +1,8 @@ const fs = require('fs'); -module.exports = async (page, scenario) => { +module.exports = async (page, scenario, config) => { let cookies = []; - const cookiePath = scenario.cookiePath; + const cookiePath = scenario.cookiePath ?? config.cookiePath; // READ COOKIES FROM FILE IF EXISTS if (fs.existsSync(cookiePath)) {