Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
blob: c18beb96d48f956011094bc3b4839505c726ea25 (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
const { Builder, By } = require('selenium-webdriver'),
  chrome = require('selenium-webdriver/chrome.js'),
  { expect, it } = require('@jest/globals'),
  chromeOptions = new chrome.Options();

let driver;

chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');

beforeEach(async () => {
  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('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();

  expect(await counter.getAttribute('class')).toEqual(expect.stringContaining('selected'));
});

afterEach(async () => await driver.quit());