Web Dev Solutions

Catalin Mititiuc

From 7e5aedeb0a1ffa727005c98d80044429bf20ff45 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Tue, 28 May 2024 17:46:32 -0700 Subject: Move takeScreenshot() function into a test helper file --- test/integration/helpers.cjs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 test/integration/helpers.cjs (limited to 'test/integration/helpers.cjs') diff --git a/test/integration/helpers.cjs b/test/integration/helpers.cjs new file mode 100644 index 0000000..5643bfd --- /dev/null +++ b/test/integration/helpers.cjs @@ -0,0 +1,11 @@ +const { mkdir, writeFile } = require('node:fs/promises') + , path = require('path') + ; + +global.takeScreenshot = async (driver) => { + const dir = './test/screenshots'; + const fileName = path.relative(process.cwd(), __filename) + ' "' + global.expect.getState().currentTestName + `" ${new Date().toISOString()}.png`; + const image = await driver.takeScreenshot(); + await mkdir(dir, { recursive: true }); + await writeFile(`${dir}/${fileName.replaceAll('/', '-')}`, image, 'base64'); +}; -- cgit v1.2.3