From 3459ed68cfdca2168424c21e5248d7d200c6dcd1 Mon Sep 17 00:00:00 2001 From: Eric Zieger Date: Tue, 3 Jul 2018 15:04:24 +0200 Subject: [PATCH] adds use of elementHandle.screenshot instead of page.screenshot and check for visibility of preview element --- src/utils/page.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/utils/page.js b/src/utils/page.js index 386ba23..6bcc0fa 100644 --- a/src/utils/page.js +++ b/src/utils/page.js @@ -90,11 +90,21 @@ async function takeNewScreenshotOfPreview (page, preview, index, actionState, { await triggerAction(page, el, actionState) const boundingBoxEl = preview.previewSelector ? await page.$(preview.previewSelector) : el - const boundingBox = await boundingBoxEl.boundingBox() + + const isVisible = await page.evaluate((element) => { + if (!element) { + return false + } + const style = window.getComputedStyle(element) + return style && style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0' + }, boundingBoxEl) const path = await getRelativeFilepath(preview, index, actionState, dir) debug('Storing screenshot of %s in %s', chalk.blue(preview.name), chalk.cyan(path)) - await page.screenshot({ clip: boundingBox, path }) + + if (isVisible) { + await boundingBoxEl.screenshot({ path }) + } } async function getRelativeFilepath (preview, index, actionState, dir) {