index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
author | Catalin Mititiuc <webdevcat@proton.me> | 2024-05-24 15:59:17 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-05-24 15:59:17 -0700 |
commit | a80728f16f90616d93dcc9ed932528b35e2ef62d (patch) | |
tree | 3155abf47790f01c8fe87e374f30926cdd763b16 /test/integration/page.test.js | |
parent | d729079cdf63a4382e3e3225295784124e0a4d5d (diff) |
WIP: mock selenium response
Diffstat (limited to 'test/integration/page.test.js')
-rw-r--r-- | test/integration/page.test.js | 71 |
1 files changed, 62 insertions, 9 deletions
diff --git a/test/integration/page.test.js b/test/integration/page.test.js index e4739b0..f708c4f 100644 --- a/test/integration/page.test.js +++ b/test/integration/page.test.js @@ -1,4 +1,6 @@ -const { Builder, By } = require('selenium-webdriver'), +const { ProvideResponseParameters } = require('selenium-webdriver/bidi/provideResponseParameters'); + +const { Builder, By, until } = require('selenium-webdriver'), chrome = require('selenium-webdriver/chrome.js'), getNetworkInstance = require('selenium-webdriver/bidi/network.js'), { AddInterceptParameters } = require('selenium-webdriver/bidi/addInterceptParameters'), @@ -10,8 +12,10 @@ const { Builder, By } = require('selenium-webdriver'), { tmpdir } = require('os'), puppeteer = require('puppeteer'); -const DIR = path.resolve(tmpdir(), 'test-dir'); +const { HttpResponse } = require('selenium-webdriver/devtools/networkinterceptor'); +const fs = require('node:fs/promises'); +const DIR = path.resolve(tmpdir(), 'test-dir'); chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox'); chromeOptions.enableBidi(); @@ -53,17 +57,66 @@ it('loads the page', async () => { it.only('selects an off-board soldier', async () => { // it.only.each(Array(10).fill(null))('selects an off-board soldier', async () => { - const id = await driver.getWindowHandle(); - const network = await getNetworkInstance(driver, id); - await network.beforeRequestSent(function (event) { - console.log('request url', event.request.url); - }); + // const id = await driver.getWindowHandle(); + // const network = await getNetworkInstance(driver, id); // const intercept = await network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT)); + // await network.beforeRequestSent(async event => { + // console.log('request url', event.request.url); + // await network.provideResponse(new ProvideResponseParameters(event.request)); + // }); + + // await network.responseStarted(async event => { + // if (event.response.url.includes('scenario')) + // console.log('response', event.response); + // }); + + // await network.responseStarted(async (event) => { + // if (event.response.url.includes('scenario')) { + // console.log('event', event); + // console.log('request', event.request); + // console.log('response', event.response.result); + // } + // }); + + // await network.beforeRequestSent(async (event) => { + // if (event.request.url.includes('scenario')) { + // console.log('event', event); + // console.log('request', event.request.request); + // await network.provideResponse(new ProvideResponseParameters(event.request.request)); + // // await network.failRequest(event.request.request); + // } + // }); + + const connection = await driver.createCDPConnection('page') + const url = 'http://localhost:3005/assets/images/scenario-side_show.svg'; + const httpResponse = new HttpResponse(url); + + // httpResponse.body = `<?xml version="1.0" standalone="no"?> + // <svg viewBox="-150 -150 300 300" xmlns="http://www.w3.org/2000/svg"> + // <circle cx="0" cy="0" r="50" fill="violet" /> + // </svg>`; + + httpResponse.body = await fs.readFile('./test/integration/fixtures/scenario-test.svg', 'utf8'); + httpResponse.addHeaders('Content-Type', 'image/svg+xml'); + + await driver.onIntercept(connection, httpResponse, async function () { + console.log('intercepted'); + // await driver.switchTo().frame(await driver.findElement(By.css('object'))); + // console.log(await driver.getPageSource()); + }); + await driver.get('http://localhost:3005'); + // expect(await driver.getTitle()).toEqual('Infantry Combat Solo Basic'); + + await driver.wait(until.elementIsVisible(driver.findElement(By.css('object'))), 1000); + // await driver.wait(until.elementLocated(By.css('#dice')), 1000); + takeScreenshot(driver); // await driver.switchTo().frame(await driver.findElement(By.css('object'))); + // console.log(await driver.getPageSource()); + // const testDir = path.dirname(expect.getState().testPath); // await writeFile(path.join(testDir, `scenario.svg`), ` // <?xml version="1.0" standalone="no"?> @@ -91,18 +144,18 @@ it.only('selects an off-board soldier', async () => { // 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 driver.findElement(By.css('#dice')); // await counter.click(); // expect(await counter.getAttribute('class')).toEqual(expect.stringContaining('selected')); + // await takeScreenshot(driver); }); afterEach(async () => { |