WIP: intercept request in test
This commit is contained in:
8
test/integration/fixtures/index.html
Normal file
8
test/integration/fixtures/index.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Infantry Combat Solo Basic</title>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,11 +1,20 @@
|
||||
const { Builder, By } = require('selenium-webdriver'),
|
||||
chrome = require('selenium-webdriver/chrome.js'),
|
||||
getNetworkInstance = require('selenium-webdriver/bidi/network.js'),
|
||||
{ AddInterceptParameters } = require('selenium-webdriver/bidi/addInterceptParameters'),
|
||||
{ InterceptPhase } = require('selenium-webdriver/bidi/interceptPhase'),
|
||||
{ expect, it } = require('@jest/globals'),
|
||||
chromeOptions = new chrome.Options(),
|
||||
{ mkdir, writeFile, symlink, unlink } = require('node:fs/promises'),
|
||||
path = require('path');
|
||||
path = require('path'),
|
||||
{ tmpdir } = require('os'),
|
||||
puppeteer = require('puppeteer');
|
||||
|
||||
const DIR = path.resolve(tmpdir(), 'test-dir');
|
||||
|
||||
|
||||
chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');
|
||||
chromeOptions.enableBidi();
|
||||
|
||||
let driver;
|
||||
|
||||
@@ -18,7 +27,6 @@ beforeEach(async () => {
|
||||
|
||||
// console.log('manage', await driver.manage());
|
||||
|
||||
await driver.get('http://localhost:3005');
|
||||
});
|
||||
|
||||
it('loads the page', async () => {
|
||||
@@ -42,17 +50,59 @@ it('loads the page', async () => {
|
||||
// console.log('client', await driver.executeScript(`return document.querySelect('object');`));
|
||||
});
|
||||
|
||||
it('selects an off-board soldier', async () => {
|
||||
it.only('selects an off-board soldier', async () => {
|
||||
// it.only.each(Array(10).fill(null))('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);
|
||||
const id = await driver.getWindowHandle();
|
||||
const network = await getNetworkInstance(driver, id);
|
||||
await network.beforeRequestSent(function (event) {
|
||||
console.log('request url', event.request.url);
|
||||
});
|
||||
|
||||
await counter.click();
|
||||
// const intercept = await network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT));
|
||||
|
||||
expect(await counter.getAttribute('class')).toEqual(expect.stringContaining('selected'));
|
||||
await driver.get('http://localhost:3005');
|
||||
// await driver.switchTo().frame(await driver.findElement(By.css('object')));
|
||||
|
||||
// const testDir = path.dirname(expect.getState().testPath);
|
||||
// await writeFile(path.join(testDir, `scenario.svg`), `
|
||||
// <?xml version="1.0" standalone="no"?>
|
||||
// <svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
|
||||
// </svg>
|
||||
// `);
|
||||
|
||||
|
||||
// const browser = await puppeteer.launch();
|
||||
|
||||
// // Create a page
|
||||
// const page = await browser.newPage();
|
||||
|
||||
// await page.setRequestInterception(true);
|
||||
|
||||
// page.on('request', interceptedRequest => {
|
||||
// console.log('intercept req url', interceptedRequest.url());
|
||||
// interceptedRequest.continue();
|
||||
// });
|
||||
|
||||
// // Go to your site
|
||||
// await page.goto('http://localhost:3005');
|
||||
|
||||
|
||||
// await browser.close();
|
||||
|
||||
|
||||
|
||||
// console.log('test dir', testDir);
|
||||
|
||||
// const selector = '.counter[data-allegiance="attacker"][data-number="1"]',
|
||||
// svg = await driver.findElement(By.css('svg')),
|
||||
// counter = await driver.findElement(By.css(selector), svg);
|
||||
|
||||
// takeScreenshot(driver);
|
||||
|
||||
// await counter.click();
|
||||
|
||||
// expect(await counter.getAttribute('class')).toEqual(expect.stringContaining('selected'));
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
5
test/integration/scenario.svg
Normal file
5
test/integration/scenario.svg
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
|
||||
</svg>
|
||||
|
||||
|
After Width: | Height: | Size: 123 B |
Reference in New Issue
Block a user