Web Dev Solutions

Catalin Mititiuc

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'); };