()
| 131 | |
| 132 | let result; |
| 133 | const puppetCommands = async () => { |
| 134 | // --- BEFORE SCRIPT --- |
| 135 | const onBeforeScript = scenario.onBeforeScript || config.onBeforeScript; |
| 136 | if (onBeforeScript) { |
| 137 | const beforeScriptPath = path.resolve(engineScriptsPath, onBeforeScript); |
| 138 | if (fs.existsSync(beforeScriptPath)) { |
| 139 | await require(beforeScriptPath)(page, scenario, viewport, isReference, browser, config); |
| 140 | } else { |
| 141 | logger.warn('reset', 'WARNING: script not found: ' + beforeScriptPath); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | // --- OPEN URL --- |
| 146 | let url = scenario.url; |
| 147 | if (isReference && scenario.referenceUrl) { |
| 148 | url = scenario.referenceUrl; |
| 149 | } |
| 150 | |
| 151 | const gotoParameters = scenario?.engineOptions?.gotoParameters || config?.engineOptions?.gotoParameters || {}; |
| 152 | await page.goto(translateUrl(url, logger), gotoParameters); |
| 153 | |
| 154 | await injectBackstopTools(page); |
| 155 | |
| 156 | // --- WAIT FOR READY EVENT --- |
| 157 | if (readyEvent) { |
| 158 | await page.evaluate(`window._readyEvent = '${readyEvent}'`); |
| 159 | |
| 160 | await readyPromise; |
| 161 | |
| 162 | clearTimeout(readyTimeoutTimer); |
| 163 | |
| 164 | // can't use logger here -- this executes on the page |
| 165 | await page.evaluate(_ => console.info('readyEvent ok')); |
| 166 | } |
| 167 | |
| 168 | // --- WAIT FOR SELECTOR --- |
| 169 | if (scenario.readySelector) { |
| 170 | await page.waitForSelector(scenario.readySelector, { |
| 171 | timeout: readyTimeout |
| 172 | }); |
| 173 | } |
| 174 | // |
| 175 | |
| 176 | // --- DELAY --- |
| 177 | if (scenario.delay > 0) { |
| 178 | await page.waitForTimeout(scenario.delay); |
| 179 | } |
| 180 | |
| 181 | // --- REMOVE SELECTORS --- |
| 182 | if (_.has(scenario, 'removeSelectors')) { |
| 183 | const removeSelectors = async () => { |
| 184 | return Promise.all( |
| 185 | scenario.removeSelectors.map(async (selector) => { |
| 186 | await page |
| 187 | .evaluate((sel) => { |
| 188 | document.querySelectorAll(sel).forEach(s => { |
| 189 | s.style.cssText = 'display: none !important;'; |
| 190 | s.classList.add('__86d'); |
no test coverage detected