Web checks: one driver for Firefox (WebDriver BiDi) and Chromium / Chrome for Testing (DevTools protocol); the scenarios on it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
67c91b6e0d
commit
3afeee09c7
6 changed files with 307 additions and 158 deletions
|
|
@ -1,27 +1,26 @@
|
|||
// Runs a list of steps in the web version in headless Firefox and keeps screenshots —
|
||||
// for finding the places of buttons, and for the scenario checks built on it.
|
||||
// A session of the web version in a headless browser (browser.mjs: Firefox, or
|
||||
// Chromium with CP_BROWSER=chromium) over the site's layout (serve.py), and a runner of
|
||||
// step lists — for finding the places of buttons, and for the scenario checks.
|
||||
//
|
||||
// node apps/web/check/steps.mjs <app-dir> <out-dir> <steps.json>
|
||||
//
|
||||
// A step: {"url": "?lang=en"} | {"wait": ms} | {"click": [x, y], "double": true}
|
||||
// | {"key": "l", "mods": ["ctrl"]} | {"shot": "name.png"} | {"eval": "js expression"}
|
||||
// | {"key": "l", "mods": ["ctrl"], "times": 3} | {"shot": "name.png"} | {"eval": "js"}
|
||||
// | {"until": "js expression", "ms": 60000}
|
||||
import { spawn } from 'node:child_process';
|
||||
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import { join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { launch } from './firefox.mjs';
|
||||
import { sleep, tab } from './bidi.mjs';
|
||||
|
||||
export const KEYS = { ctrl: '', shift: '', alt: '', esc: '', right: '', left: '', enter: '' };
|
||||
import { open } from './browser.mjs';
|
||||
import { sleep } from './bidi.mjs';
|
||||
|
||||
export async function session(appDir, port = Number(process.env.CP_CHECK_PORT || 18767)) {
|
||||
const root = fileURLToPath(new URL('../../..', import.meta.url));
|
||||
const server = spawn('python3', ['-I', join(root, 'apps/web/check/serve.py'), resolve(appDir), join(root, 'website/static'), String(port)], { stdio: 'ignore' });
|
||||
const ff = await launch(port + 457);
|
||||
const b = await open(port + 457);
|
||||
const errors = [];
|
||||
const t = await tab(ff.browser, 1400, 860, (line) => {
|
||||
if (/panicked|RuntimeError|\[error\]/.test(line)) errors.push(line);
|
||||
const t = await b.tab(1400, 860, (line) => {
|
||||
if (/panicked|RuntimeError|\[error\]/.test(line) && !/favicon|404/.test(line)) errors.push(line);
|
||||
if (process.env.CONSOLE) console.log(line);
|
||||
});
|
||||
const base = `http://127.0.0.1:${port}/app/`;
|
||||
|
|
@ -32,17 +31,11 @@ export async function session(appDir, port = Number(process.env.CP_CHECK_PORT ||
|
|||
}
|
||||
if (step.wait) await sleep(step.wait);
|
||||
if (step.click) {
|
||||
const [x, y] = step.click;
|
||||
const acts = [{ type: 'pointerMove', x, y }];
|
||||
for (let i = 0; i < (step.double ? 2 : 1); i++) acts.push({ type: 'pointerDown', button: step.right ? 2 : 0 }, { type: 'pointerUp', button: step.right ? 2 : 0 });
|
||||
await t.actions([{ type: 'pointer', id: 'mouse', parameters: { pointerType: 'mouse' }, actions: acts }]);
|
||||
await t.click(step.click[0], step.click[1], step);
|
||||
await sleep(300);
|
||||
}
|
||||
if (step.key) {
|
||||
const mods = (step.mods || []).map((m) => KEYS[m]);
|
||||
const v = KEYS[step.key] || step.key;
|
||||
const acts = [...mods.map((m) => ({ type: 'keyDown', value: m })), { type: 'keyDown', value: v }, { type: 'keyUp', value: v }, ...mods.reverse().map((m) => ({ type: 'keyUp', value: m }))];
|
||||
for (let i = 0; i < (step.times || 1); i++) await t.actions([{ type: 'key', id: 'kb', actions: acts }]);
|
||||
await t.key(step.key, step.mods || [], step.times || 1);
|
||||
await sleep(300);
|
||||
}
|
||||
if (step.eval) console.log('eval:', JSON.stringify(await t.evaluate(step.eval)).slice(0, 2000));
|
||||
|
|
@ -50,8 +43,8 @@ export async function session(appDir, port = Number(process.env.CP_CHECK_PORT ||
|
|||
if (step.shot) writeFileSync(join(outDir, step.shot), await t.screenshot());
|
||||
};
|
||||
return {
|
||||
t, ff, errors, run,
|
||||
stop: async () => { await ff.stop(); server.kill(); },
|
||||
t, b, base, errors, run,
|
||||
stop: async () => { await b.stop(); server.kill(); },
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue