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');
chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');
chromeOptions.enableBidi();
let driver;
beforeEach(async () => {
driver = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
});
it('loads the page', async () => {
await driver.get('http://localhost:3005');
expect(await driver.getTitle()).toEqual('Infantry Combat Solo Basic');
});
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');
}