Move takeScreenshot() function into a test helper file
This commit is contained in:
parent
2df718998a
commit
7e5aedeb0a
@ -3,6 +3,7 @@ console.log('Jest config file read.');
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
globalSetup: './test/integration/setup.cjs',
|
globalSetup: './test/integration/setup.cjs',
|
||||||
globalTeardown: './test/integration/teardown.cjs',
|
globalTeardown: './test/integration/teardown.cjs',
|
||||||
|
setupFiles: ['./test/integration/helpers.cjs'],
|
||||||
testPathIgnorePatterns: ['/node_modules/', 'test/unit'],
|
testPathIgnorePatterns: ['/node_modules/', 'test/unit'],
|
||||||
testTimeout: 5000,
|
testTimeout: 5000,
|
||||||
};
|
};
|
||||||
|
11
test/integration/helpers.cjs
Normal file
11
test/integration/helpers.cjs
Normal file
@ -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');
|
||||||
|
};
|
@ -1,9 +1,7 @@
|
|||||||
const { Builder } = require('selenium-webdriver'),
|
const { Builder } = require('selenium-webdriver'),
|
||||||
chrome = require('selenium-webdriver/chrome.js'),
|
chrome = require('selenium-webdriver/chrome.js'),
|
||||||
chromeOptions = new chrome.Options(),
|
chromeOptions = new chrome.Options(),
|
||||||
{ expect, it } = require('@jest/globals'),
|
{ expect, it } = require('@jest/globals');
|
||||||
{ mkdir, writeFile } = require('node:fs/promises'),
|
|
||||||
path = require('path');
|
|
||||||
|
|
||||||
chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');
|
chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');
|
||||||
chromeOptions.enableBidi();
|
chromeOptions.enableBidi();
|
||||||
@ -22,11 +20,3 @@ it('loads the page', async () => {
|
|||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await driver.quit();
|
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');
|
|
||||||
}
|
|
||||||
|
@ -2,8 +2,7 @@ const { Builder, By, until } = require('selenium-webdriver'),
|
|||||||
chrome = require('selenium-webdriver/chrome.js'),
|
chrome = require('selenium-webdriver/chrome.js'),
|
||||||
chromeOptions = new chrome.Options(),
|
chromeOptions = new chrome.Options(),
|
||||||
{ expect, it } = require('@jest/globals'),
|
{ expect, it } = require('@jest/globals'),
|
||||||
{ mkdir, writeFile, readFile } = require('node:fs/promises'),
|
{ readFile } = require('node:fs/promises'),
|
||||||
path = require('path'),
|
|
||||||
{ HttpResponse } = require('selenium-webdriver/devtools/networkinterceptor');
|
{ HttpResponse } = require('selenium-webdriver/devtools/networkinterceptor');
|
||||||
|
|
||||||
chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');
|
chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');
|
||||||
@ -182,11 +181,3 @@ it('selects a trooper by clicking on its record and deselects it by clicking on
|
|||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await driver.quit();
|
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');
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user