MCPcopy Create free account
hub / github.com/garris/BackstopJS / selectorShot

Function selectorShot

core/util/runPuppet.js:407–444  ·  view source on GitHub ↗
(s, path, logFilePath)

Source from the content-addressed store, hash-verified

405 } else {
406 // OTHER-SELECTOR screenshot
407 const selectorShot = async (s, path, logFilePath) => {
408 const el = await page.$(s);
409 if (el) {
410 const box = await el.boundingBox();
411 if (box) {
412 // Resize the viewport to screenshot elements outside of the viewport
413 if (config.useBoundingBoxViewportForSelectors !== false) {
414 const bodyHandle = await page.$('body');
415 const boundingBox = await bodyHandle.boundingBox();
416
417 await page.setViewport({
418 width: Math.max(viewport.width, Math.ceil(boundingBox.width)),
419 height: Math.max(viewport.height, Math.ceil(boundingBox.height))
420 });
421 }
422
423 const type = config.puppeteerOffscreenCaptureFix ? page : el;
424 const params = config.puppeteerOffscreenCaptureFix
425 ? {
426 captureBeyondViewport: false,
427 path,
428 clip: box
429 }
430 : { captureBeyondViewport: false, path };
431
432 await type.screenshot(params);
433 await writeScenarioLogs(config, logFilePath, logger);
434 } else {
435 logger.log('yellow', `Element not visible for capturing: ${s}`);
436 await writeScenarioLogs(config, logFilePath, logger);
437 return fs.copy(config.env.backstop + HIDDEN_SELECTOR_PATH, path);
438 }
439 } else {
440 logger.log('magenta', `Element not found for capturing: ${s}`);
441 await writeScenarioLogs(config, logFilePath, logger);
442 return fs.copy(config.env.backstop + SELECTOR_NOT_FOUND_PATH, path);
443 }
444 };
445
446 const selectorsShot = async () => {
447 for (let i = 0; i < selectors.length; i++) {

Callers 1

selectorsShotFunction · 0.70

Calls 1

writeScenarioLogsFunction · 0.85

Tested by

no test coverage detected