()
| 188 | |
| 189 | let result; |
| 190 | const playwrightCommands = async () => { |
| 191 | // --- BEFORE SCRIPT --- |
| 192 | const onBeforeScript = scenario.onBeforeScript || config.onBeforeScript; |
| 193 | if (onBeforeScript) { |
| 194 | const beforeScriptPath = path.resolve(engineScriptsPath, onBeforeScript); |
| 195 | if (fs.existsSync(beforeScriptPath)) { |
| 196 | await require(beforeScriptPath)(page, scenario, viewport, isReference, browserContext, config); |
| 197 | } else { |
| 198 | console.warn('WARNING: script not found: ' + beforeScriptPath); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | // --- OPEN URL --- |
| 203 | let url = scenario.url; |
| 204 | if (isReference && scenario.referenceUrl) { |
| 205 | url = scenario.referenceUrl; |
| 206 | } |
| 207 | |
| 208 | const gotoParameters = scenario?.engineOptions?.gotoParameters || config?.engineOptions?.gotoParameters || {}; |
| 209 | await page.goto(translateUrl(url), gotoParameters); |
| 210 | |
| 211 | await injectBackstopTools(page); |
| 212 | |
| 213 | // --- WAIT FOR READY EVENT --- |
| 214 | if (readyEvent) { |
| 215 | await page.evaluate(`window._readyEvent = '${readyEvent}'`); |
| 216 | |
| 217 | await readyPromise; |
| 218 | |
| 219 | clearTimeout(readyTimeoutTimer); |
| 220 | |
| 221 | await page.evaluate(_ => console.info('readyEvent ok')); |
| 222 | } |
| 223 | |
| 224 | // --- WAIT FOR SELECTOR --- |
| 225 | if (scenario.readySelector) { |
| 226 | await page.waitForSelector(scenario.readySelector, { |
| 227 | timeout: readyTimeout |
| 228 | }); |
| 229 | } |
| 230 | |
| 231 | // --- DELAY --- |
| 232 | if (scenario.delay > 0) { |
| 233 | await page.waitForTimeout(scenario.delay); |
| 234 | } |
| 235 | |
| 236 | // --- REMOVE SELECTORS --- |
| 237 | if (_.has(scenario, 'removeSelectors')) { |
| 238 | const removeSelectors = async () => { |
| 239 | return Promise.all( |
| 240 | scenario.removeSelectors.map(async (selector) => { |
| 241 | await page |
| 242 | .evaluate((sel) => { |
| 243 | document.querySelectorAll(sel).forEach(s => { |
| 244 | s.style.cssText = 'display: none !important;'; |
| 245 | s.classList.add('__86d'); |
| 246 | }); |
| 247 | }, selector); |
no test coverage detected