From a0126c4f4434188d549d5953c9299f48991cea2d Mon Sep 17 00:00:00 2001 From: Labhansh Agrawal Date: Tue, 23 Nov 2021 11:51:35 +0530 Subject: [PATCH] Use desktopCapturer instead of capturePage for e2e screenshot of whole window instead of just the page body --- test/index.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/index.ts b/test/index.ts index b88c28aa..15370d7e 100644 --- a/test/index.ts +++ b/test/index.ts @@ -37,11 +37,15 @@ test.before(async () => { test.after(async () => { await app - .evaluate(({BrowserWindow}) => - BrowserWindow.getFocusedWindow() - ?.capturePage() - .then((img) => img.toPNG().toString('base64')) - ) + .evaluate(async ({BrowserWindow, desktopCapturer, screen}) => { + // eslint-disable-next-line prefer-const + let {width, height, ...position} = BrowserWindow.getFocusedWindow()!.getBounds(); + const {scaleFactor} = screen.getDisplayNearestPoint(position); + width *= scaleFactor; + height *= scaleFactor; + const sources = await desktopCapturer.getSources({types: ['window'], thumbnailSize: {width, height}}); + return sources[0].thumbnail.toPNG().toString('base64'); + }) .then((img) => Buffer.from(img || '', 'base64')) .then(async (imageBuffer) => { await fs.writeFile(`dist/tmp/${process.platform}_test.png`, imageBuffer);