Move takeScreenshot() function into a test helper file

This commit is contained in:
2025-06-16 22:41:31 -07:00
parent effb3c9e21
commit 1a4fc73442
4 changed files with 14 additions and 21 deletions

View File

@@ -1,9 +1,7 @@
const { Builder } = require('selenium-webdriver'),
chrome = require('selenium-webdriver/chrome.js'),
chromeOptions = new chrome.Options(),
{ expect, it } = require('@jest/globals'),
{ mkdir, writeFile } = require('node:fs/promises'),
path = require('path');
{ expect, it } = require('@jest/globals');
chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');
chromeOptions.enableBidi();
@@ -22,11 +20,3 @@ it('loads the page', async () => {
afterEach(async () => {
await driver.quit();
});
async function takeScreenshot(driver) {
const dir = './test/screenshots';
const fileName = path.relative(process.cwd(), __filename) + ' "' + expect.getState().currentTestName + `" ${new Date().toISOString()}.png`;
const image = await driver.takeScreenshot();
await mkdir(dir, { recursive: true });
await writeFile(`${dir}/${fileName.replaceAll('/', '-')}`, image, 'base64');
}