Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-05-02 08:54:59 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-05-02 08:54:59 -0700
commite639bedadc81706a522ffe7658fea75300d082f7 (patch)
treedd3a1fbb84743e6686bfb3b0edde42403656d22e /test
parent6b32bde0bc85ed029a0645e712e26e1a70888bb6 (diff)
Clean up test
Diffstat (limited to 'test')
-rw-r--r--test/integration/page.test.js77
1 files changed, 14 insertions, 63 deletions
diff --git a/test/integration/page.test.js b/test/integration/page.test.js
index 1e69db1..7a987f7 100644
--- a/test/integration/page.test.js
+++ b/test/integration/page.test.js
@@ -1,91 +1,42 @@
const { Builder, By } = require('selenium-webdriver'),
chrome = require('selenium-webdriver/chrome.js'),
- { Command } = require('selenium-webdriver/lib/command.js'),
{ expect, it } = require('@jest/globals'),
+ chromeOptions = new chrome.Options(),
{ mkdir, writeFile } = require('node:fs/promises'),
- path = require('path'),
- chromeOptions = new chrome.Options();
+ path = require('path');
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();
+ await driver.get("http://localhost:3005");
});
-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('loads the page', async () => {
+ expect(await driver.getTitle()).toEqual('Infantry Combat Solo Basic');
});
+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);
-// 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);
+ await counter.click();
-// expect(await counter.getAttribute('class')).toEqual(expect.stringContaining('selected'));
-// // await driver.switchTo().defaultContent();
-// });
+ expect(await counter.getAttribute('class')).toEqual(expect.stringContaining('selected'));
+});
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 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');