From 2efe947dc8e72495cead742c572512f1142c819c Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Tue, 9 Aug 2022 14:03:07 -0700 Subject: [PATCH] chore: avoid evaluates in screenshot on failure (#16386) --- packages/playwright-test/src/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/playwright-test/src/index.ts b/packages/playwright-test/src/index.ts index dd8d7f8c84..3df865716b 100644 --- a/packages/playwright-test/src/index.ts +++ b/packages/playwright-test/src/index.ts @@ -330,7 +330,9 @@ export const test = _baseTest.extend({ (page as any)[screenshottedSymbol] = true; const screenshotPath = path.join(_artifactsDir(), createGuid() + '.png'); temporaryScreenshots.push(screenshotPath); - await page.screenshot({ timeout: 5000, path: screenshotPath }).catch(() => {}); + // Pass caret=initial to avoid any evaluations that might slow down the screenshot + // and let the page modify itself from the problematic state it had at the moment of failure. + await page.screenshot({ timeout: 5000, path: screenshotPath, caret: 'initial' }).catch(() => {}); }; const screenshotOnTestFailure = async () => { @@ -432,7 +434,9 @@ export const test = _baseTest.extend({ await Promise.all(context.pages().map(async page => { if ((page as any)[screenshottedSymbol]) return; - await page.screenshot({ timeout: 5000, path: addScreenshotAttachment() }).catch(() => {}); + // Pass caret=initial to avoid any evaluations that might slow down the screenshot + // and let the page modify itself from the problematic state it had at the moment of failure. + await page.screenshot({ timeout: 5000, path: addScreenshotAttachment(), caret: 'initial' }).catch(() => {}); })); } }).concat(leftoverApiRequests.map(async context => {