Skip to content

Commit

Permalink
Allow setup the cookies.json file globally
Browse files Browse the repository at this point in the history
  • Loading branch information
franrou committed Oct 17, 2024
1 parent 9bcd84b commit 298cb02
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/backstop.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
],
"onBeforeScript": "onBefore.js",
"onReadyScript": "onReady.js",
"cookiePath": "cookies.json",
"scenarios": [
{
"label": "Click an wait for selector example",
Expand Down
7 changes: 7 additions & 0 deletions examples/cookies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"domain": "domain",
"name": "cookie-name",
"value": "cookie-value"
}
]
2 changes: 1 addition & 1 deletion examples/engine_scripts/onBefore.js
Original file line number Diff line number Diff line change
@@ -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);
};
4 changes: 2 additions & 2 deletions loadCookies.js
Original file line number Diff line number Diff line change
@@ -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)) {
Expand Down

0 comments on commit 298cb02

Please sign in to comment.