From 397bdb7aee31c5a4f6114057059ecde79e31b46e Mon Sep 17 00:00:00 2001 From: Marcin Maruszewski Date: Fri, 4 Nov 2022 18:17:21 +0100 Subject: [PATCH] Allow to modify `gotoParameters` (#1444) * Allow to use custom params in page.goto() command. * Fix some minor coding standards issues. * Add information about new `gotoParameters` option. --- README.md | 4 +++- core/command/remote.js | 2 +- core/util/runPlaywright.js | 4 +++- core/util/runPuppet.js | 4 +++- .../backstop_data/engine_scripts/puppet/ignoreCSP.js | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 06fc0f08b..438ad9169 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,7 @@ selectorExpansion // See Targeting elements in the next section for more misMatchThreshold // Percentage of different pixels allowed to pass test requireSameDimensions // If set to true -- any change in selector size will trigger a test failure. viewports // An array of screen size objects your DOM will be tested against. This configuration will override the viewports property assigned at the config root. +gotoParameters // An array of settings passed to page.goto(url, parameters) function. ``` @@ -648,7 +649,8 @@ You can add more settings (or override the defaults) with the engineOptions prop ```json "engineOptions": { "ignoreHTTPSErrors": false, - "args": ["--no-sandbox", "--disable-setuid-sandbox"] + "args": ["--no-sandbox", "--disable-setuid-sandbox"], + "gotoParameters": { "waitUntil": "networkidle0" }, } ``` More info here: diff --git a/core/command/remote.js b/core/command/remote.js index 62d829ac3..1e0dd5f85 100644 --- a/core/command/remote.js +++ b/core/command/remote.js @@ -12,7 +12,7 @@ module.exports = { return new Promise(function (resolve, reject) { const port = getRemotePort(); const commandStr = `node ${ssws} ${projectPath} ${MIDDLEWARE_PATH} --config=${config.backstopConfigFileName}`; - const env = {'SSWS_HTTP_PORT': port}; + const env = {'SSWS_HTTP_PORT': port}; logger.log(`Starting remote with: ${commandStr} with env ${JSON.stringify(env)}`); diff --git a/core/util/runPlaywright.js b/core/util/runPlaywright.js index 3473ad949..3018bae24 100644 --- a/core/util/runPlaywright.js +++ b/core/util/runPlaywright.js @@ -135,7 +135,9 @@ async function processScenarioView (scenario, variantOrScenarioLabelSafe, scenar if (isReference && scenario.referenceUrl) { url = scenario.referenceUrl; } - await page.goto(translateUrl(url)); + + const gotoParameters = scenario?.engineOptions?.gotoParameters || config?.engineOptions?.gotoParameters || {}; + await page.goto(translateUrl(url), gotoParameters); await injectBackstopTools(page); diff --git a/core/util/runPuppet.js b/core/util/runPuppet.js index 85d0d57c9..d513fa918 100644 --- a/core/util/runPuppet.js +++ b/core/util/runPuppet.js @@ -138,7 +138,9 @@ async function processScenarioView (scenario, variantOrScenarioLabelSafe, scenar if (isReference && scenario.referenceUrl) { url = scenario.referenceUrl; } - await page.goto(translateUrl(url, logger)); + + const gotoParameters = scenario?.engineOptions?.gotoParameters || config?.engineOptions?.gotoParameters || {}; + await page.goto(translateUrl(url, logger), gotoParameters); await injectBackstopTools(page); diff --git a/examples/responsiveDemo/backstop_data/engine_scripts/puppet/ignoreCSP.js b/examples/responsiveDemo/backstop_data/engine_scripts/puppet/ignoreCSP.js index d243ea533..1dea285e4 100644 --- a/examples/responsiveDemo/backstop_data/engine_scripts/puppet/ignoreCSP.js +++ b/examples/responsiveDemo/backstop_data/engine_scripts/puppet/ignoreCSP.js @@ -36,7 +36,7 @@ module.exports = async function (page, scenario) { const cookies = cookiesList.map(cookie => `${cookie.name}=${cookie.value}`).join('; '); const headers = Object.assign(request.headers(), { cookie: cookies }); const options = { - headers: headers, + headers, body: request.postData(), method: request.method(), follow: 20,