Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
blob: 1e69db14493f62089977ee91f684853ddbac53f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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;


// 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');
}