From fe1f3e129e8407924501ec509c2bdd32d866865e Mon Sep 17 00:00:00 2001 From: mmyllynen <4696381+dire@users.noreply.github.com> Date: Thu, 5 Oct 2023 13:04:39 +0300 Subject: [PATCH] UHF-6187: Added mock cookies. --- .gitignore | 5 +-- backstop_data/backstop_dynamic_config.js | 3 +- backstop_data/fast/engine_scripts/onBefore.js | 31 ++++++++++++++++++- backstop_data/full/engine_scripts/onBefore.js | 31 ++++++++++++++++++- 4 files changed, 65 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index c88353521..6ddb622e7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,6 @@ dist/**/*.map yarn.lock # BackstopJS -backstop_data/fast -backstop_data/full +backstop_data/*/bitmaps_reference +backstop_data/*/bitmaps_test +backstop_data/*/html_report diff --git a/backstop_data/backstop_dynamic_config.js b/backstop_data/backstop_dynamic_config.js index 0d211ea73..698ddfca0 100644 --- a/backstop_data/backstop_dynamic_config.js +++ b/backstop_data/backstop_dynamic_config.js @@ -414,7 +414,7 @@ function getConfig(hostname, type) { ], 'mergeImgHack': true, 'onBeforeScript': 'onBefore.js', - // 'onReadyScript': 'puppet/onReady.js', + // 'onReadyScript': 'onReady.js', 'paths': { 'bitmaps_reference': `backstop_data/${type}/bitmaps_reference`, 'bitmaps_test': `backstop_data/${type}/bitmaps_test`, @@ -434,6 +434,7 @@ function getConfig(hostname, type) { 'asyncCompareLimit': 100, 'debug': false, 'debugWindow': false, + 'hostname': `${hostname}`, } }; } diff --git a/backstop_data/fast/engine_scripts/onBefore.js b/backstop_data/fast/engine_scripts/onBefore.js index 2f21d408c..bdd1978da 100644 --- a/backstop_data/fast/engine_scripts/onBefore.js +++ b/backstop_data/fast/engine_scripts/onBefore.js @@ -1,3 +1,32 @@ -module.exports = async (page, scenario, vp, isReference) => { +module.exports = async (page, scenario, vp, isReference, browserContext, config) => { await page.emulateMedia({ reducedMotion: 'reduce' }); + const { hostname } = config; + + // Add cookies to browser + browserContext.addCookies([ + { + 'name': 'cookie-agreed-version', + 'value': '1.1.0', + 'domain': hostname, + 'path': '/', + 'httpOnly': false, + 'secure': false + }, + { + 'name': 'cookie-agreed', + 'value': '2', + 'domain': hostname, + 'path': '/', + 'httpOnly': false, + 'secure': false + }, + { + 'name': 'cookie-agreed-categories', + 'value': '%5B%22essential%22%2C%22preference%22%2C%22statistics%22%2C%22marketing%22%2C%22chat%22%5D', + 'domain': hostname, + 'path': '/', + 'httpOnly': false, + 'secure': false + } + ]); }; diff --git a/backstop_data/full/engine_scripts/onBefore.js b/backstop_data/full/engine_scripts/onBefore.js index 2f21d408c..bdd1978da 100644 --- a/backstop_data/full/engine_scripts/onBefore.js +++ b/backstop_data/full/engine_scripts/onBefore.js @@ -1,3 +1,32 @@ -module.exports = async (page, scenario, vp, isReference) => { +module.exports = async (page, scenario, vp, isReference, browserContext, config) => { await page.emulateMedia({ reducedMotion: 'reduce' }); + const { hostname } = config; + + // Add cookies to browser + browserContext.addCookies([ + { + 'name': 'cookie-agreed-version', + 'value': '1.1.0', + 'domain': hostname, + 'path': '/', + 'httpOnly': false, + 'secure': false + }, + { + 'name': 'cookie-agreed', + 'value': '2', + 'domain': hostname, + 'path': '/', + 'httpOnly': false, + 'secure': false + }, + { + 'name': 'cookie-agreed-categories', + 'value': '%5B%22essential%22%2C%22preference%22%2C%22statistics%22%2C%22marketing%22%2C%22chat%22%5D', + 'domain': hostname, + 'path': '/', + 'httpOnly': false, + 'secure': false + } + ]); };