Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration')
-rw-r--r--test/integration/page.test.js85
1 files changed, 73 insertions, 12 deletions
diff --git a/test/integration/page.test.js b/test/integration/page.test.js
index c18beb9..1e69db1 100644
--- a/test/integration/page.test.js
+++ b/test/integration/page.test.js
@@ -1,31 +1,92 @@
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;
-chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');
+
+// 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('loads the page', async () => {
- expect(await driver.getTitle()).toEqual('Infantry Combat Solo Basic');
+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('selects an off-board soldier', async () => {
- await driver.switchTo().frame(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();
+// 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);
- expect(await counter.getAttribute('class')).toEqual(expect.stringContaining('selected'));
+// 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();
});
-afterEach(async () => 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');
+}