Web Dev Solutions

Catalin Mititiuc

const { Builder, By } = require('selenium-webdriver'), chrome = require('selenium-webdriver/chrome.js'), { Command } = require('selenium-webdriver/lib/command.js'), { expect, it } = require('@jest/globals'), { mkdir, writeFile } = require('node:fs/promises'), path = require('path'), chromeOptions = new chrome.Options(); chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox'); let driver; // beforeAll(async () => { // }); beforeEach(async () => { // console.log('setup'); // driver = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build(); driver = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build(); }); it.each(Array(100).fill(null))('looper', async () => { // it('looper', async () => { // console.log('test'); // const driver = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build(); // await driver.get("http://localhost:3005").catch(e => console.log(e));; // await driver.quit(); await driver.get("http://localhost:3005").catch(e => console.log(e)); const title = await driver.getTitle(); expect(title).toEqual('Infantry Combat Solo Basic'); // await driver.switchTo().defaultContent(); }); it('debugger', async () => { // it.only('loads the page', async () => { // console.log('test'); // const driver = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build(); // await driver.get("http://localhost:3005").catch(e => console.log(e));; // await driver.quit(); await driver.get("http://localhost:3005").catch(e => console.log(e)); const title = await driver.getTitle(); expect(title).toEqual('Infantry Combat Solo Basic'); // await driver.switchTo().defaultContent(); debugger; }); // it.only.each(Array(10).fill(null))('selects an off-board soldier', async () => { // it('selects an off-board soldier', async () => { // await driver.switchTo().frame(await driver.findElement(By.css('object'))); // const selector = '.counter[data-allegiance="attacker"][data-number="1"]', // svg = await driver.findElement(By.css('svg')), // counter = await driver.findElement(By.css(selector), svg); // await counter.click(); // // await takeScreenshot(driver); // expect(await counter.getAttribute('class')).toEqual(expect.stringContaining('selected')); // // await driver.switchTo().defaultContent(); // }); afterEach(async () => { // console.log('teardown'); // const session = await this.driver.getSession(); // const sessionId = session.getId(); // const executor = await this.driver.getExecutor(); // await executor.execute(new Command('close').setParameter('sessionId', sessionId)); await driver.quit(); }); // afterAll(async () => { // // console.log('executor', driver.getExecutor()); // const session = await driver.getSession(); // const sessionId = session.getId(); // const executor = await driver.getExecutor(); // await executor.execute(new Command('close').setParameter('sessionId', sessionId)); // await driver.quit(); // }); async function takeScreenshot(driver) { const dir = './test/screenshots'; const fileName = '"' + path.relative(process.cwd(), __filename) + ' ' + expect.getState().currentTestName + ` ${new Date()}".png`; // console.log(fileName.replaceAll('/', '-')); const image = await driver.takeScreenshot(); await mkdir(dir, { recursive: true }); await writeFile(`${dir}/${fileName.replaceAll('/', '-')}`, image, 'base64'); }