test(determinism): deterministic waits + stableShot screenshots; drop blind sleeps/ifs/retries

Make the Playwright e2e + kicad suites deterministic so screenshot flake stops
tracing to timing races.

- Blind page.waitForTimeout -> condition waits (expect.poll, web-first
  assertions, waitUntil) + readiness helpers (waitForWxApp, waitForCanvasApp).
  Remaining sleeps are documented interaction dwells (annotated).
- Defensive "if element exists" branches -> loud asserts; label-fallback chains
  -> normalized clickMenuItemByText. First-run wizard for/if loops removed by
  seeding calculator/gerbview/pcbnew HTMLs.
- Screenshots: new stableShot(page, name) settles the render in-page (canvas
  hash over rAF) then writes a raw PNG to test-results/ for the existing offline
  gate (tools/screenshots vs baseline-screenshots). Replaces toHaveScreenshot,
  which did inline compare + its own baselines and had decoupled the specs from
  the real gate. scale:'css' pinned.
- retries: 0 in both configs.
- Guard: tests/tools/lint-determinism.ts (npm run lint:determinism) bans blind
  sleeps / toHaveScreenshot / inline retries / swallowed catches in specs;
  documented exceptions carry a marker. Rules in tests/TESTING.md.

Assertions, coverage, and renders unchanged (semantic-equivalence reviewed;
captures pixel-identical modulo inherent timer/timestamp/3d-raytrace variance).
Both suites green at retries:0 (e2e 340, kicad 92); ~35-61% faster.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BVX1pHMvRPYHdp6ZfEawrk
This commit is contained in:
Viktor Vaczi 2026-07-07 10:50:24 +02:00
commit 4c3a4cacd4
102 changed files with 2867 additions and 3407 deletions

View file

@ -1,5 +1,5 @@
import { test, expect, type Page } from '@playwright/test';
import { waitForRegistry } from '../e2e/utils/element-tracker';
import { waitForWxApp, stableShot } from '../e2e/utils/element-tracker';
/**
* 0009-B footprint READ path: does the footprint editor browse + LOAD a real,
@ -18,22 +18,38 @@ import { waitForRegistry } from '../e2e/utils/element-tracker';
* The LIB_TREE's rendered dataviewitem Y is offset by a constant (the rows live
* below the column header); we calibrate that offset from the "Item" header +
* row pitch, then double-click true positions.
*
* Determinism: no blind waitForTimeout. Readiness via waitForWxApp + the app's
* own observables (kicadLibs, then the LIB_TREE's dataviewitem rows). Each
* navigation step waits for the state it produces — child rows after enumerate,
* the editor title after load — instead of sleeping; the static boot/expanded/
* loaded frames use stableShot.
*/
const SHOT = (name: string) => `test-results/fpbrowse-${name}.png`;
const LIB = 'Resistor_SMD';
async function bootFootprintEditor(page: Page): Promise<void> {
await page.goto('/p/demo/footprint_editor/');
await expect(page.locator('#canvas')).toBeVisible({ timeout: 180000 });
await waitForRegistry(page, 180000);
await waitForWxApp(page, { timeout: 180000 });
await page.waitForFunction(
() => !!window.wxElementRegistry && window.wxElementRegistry.findAll({}).length > 5,
null,
{ timeout: 180000 },
);
await page.waitForFunction(() => !!(window as any).kicadLibs, null, { timeout: 60000 });
await page.waitForTimeout(2000);
// Deterministic replacement for the fixed settle: the fp-lib-table is generated
// from kicadLibs and rendered into the LIB_TREE — wait until its footprint-lib
// rows (dataviewitems) actually exist, which is exactly what the downstream tree
// navigation + geom assertions require.
await expect
.poll(
() =>
page.evaluate(
() => window.wxElementRegistry.findAllRendered({ elementType: 'dataviewitem' }).length,
),
{ message: 'footprint lib tree rows rendered', timeout: 60000 },
)
.toBeGreaterThan(0);
}
/** Map a rendered tree row's offset Y to its true screen Y (see header note). */
@ -71,7 +87,7 @@ test('footprint editor browses + loads a real ingested footprint (read path / ve
page.on('pageerror', (e) => logs.push(`[pageerror] ${e.message}`));
await bootFootprintEditor(page);
await page.screenshot({ path: SHOT('01-boot'), scale: 'css' });
await stableShot(page, 'fpbrowse-01-boot.png');
const geom0 = await treeGeom(page);
logs.push(`[spec] tree geom: ${JSON.stringify(geom0)}`);
@ -79,14 +95,32 @@ test('footprint editor browses + loads a real ingested footprint (read path / ve
// Expand the footprint lib (FootprintEnumerate) by double-clicking its row.
const libClicked = await dblclickRow(page, new RegExp(`^${LIB}$`));
logs.push(`[spec] expanded lib: ${libClicked}`);
await page.waitForTimeout(2000);
await page.screenshot({ path: SHOT('02-expanded'), scale: 'css' });
// Enumerate is done when the footprint child rows (SMD fixtures carry "Metric")
// appear in the tree — that's what the next dblclick targets.
await expect
.poll(
() =>
page.evaluate(() =>
window.wxElementRegistry
.findAllRendered({ elementType: 'dataviewitem' })
.some((e: any) => /Metric/.test(e.label || '')),
),
{ message: 'footprint child rows present after FootprintEnumerate', timeout: 60000 },
)
.toBe(true);
await stableShot(page, 'fpbrowse-02-expanded.png');
// Open a footprint child (FootprintLoad → Parse). SMD fixtures carry "Metric".
const fpClicked = await dblclickRow(page, /Metric/);
logs.push(`[spec] opened footprint: ${fpClicked}`);
await page.waitForTimeout(2500);
await page.screenshot({ path: SHOT('03-loaded'), scale: 'css' });
// Load+Parse is done when the editor title reflects the opened footprint.
await expect
.poll(() => page.title(), {
message: 'editor title reflects opened footprint (FootprintLoad + Parse)',
timeout: 60000,
})
.toContain(LIB);
await stableShot(page, 'fpbrowse-03-loaded.png');
const title = await page.title();
logs.push(`[spec] title after open: ${title}`);

View file

@ -1,5 +1,5 @@
import { test, expect, type Page } from '@playwright/test';
import { waitForRegistry, clickByTooltip } from '../e2e/utils/element-tracker';
import { clickByTooltip, waitForWxApp, focusCanvas, stableShot } from '../e2e/utils/element-tracker';
// Mirrors @pcbjam/shared USER_HEADER (tests/ doesn't depend on the shared pkg).
const USER_HEADER = 'x-pcbjam-user';
@ -18,15 +18,8 @@ const SCOPE = 'default';
*/
const BACKEND = process.env.BACKEND_URL ?? 'http://localhost:3060';
const SHOT = (n: string) => `test-results/fpremote-${n}.png`;
const USER_LIB = 'my-symbols'; // slug of the boot-ensured "My Symbols" container
async function focusCanvas(page: Page): Promise<void> {
const box = await page.locator('#canvas').boundingBox();
if (box) await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
await page.waitForTimeout(300);
}
/** Click a LIB_TREE row by label, correcting the constant dataviewitem Y offset. */
async function clickTreeRow(page: Page, label: string): Promise<boolean> {
const hit = await page.evaluate((wanted) => {
@ -43,7 +36,7 @@ async function clickTreeRow(page: Page, label: string): Promise<boolean> {
}, label);
if (!hit) return false;
await page.mouse.click(hit.x, hit.y);
await page.waitForTimeout(300);
await page.waitForTimeout(300); // eslint-disable-line -- documented interaction dwell
return true;
}
@ -54,37 +47,37 @@ test('footprint editor save persists to the backend (remote write round-trip)',
page.on('pageerror', (e) => logs.push(`[pageerror] ${e.message}`));
await page.goto(`/default/projects/demo/-/footprint_editor?libowner=${owner}`);
await expect(page.locator('#canvas')).toBeVisible({ timeout: 180000 });
await waitForRegistry(page, 180000);
await page.waitForFunction(
() => !!window.wxElementRegistry && window.wxElementRegistry.findAll({}).length > 5,
null,
{ timeout: 180000 },
);
await waitForWxApp(page, { timeout: 180000 });
await page.waitForFunction(() => !!(window as any).kicadLibs, null, { timeout: 60000 });
await page.waitForTimeout(2000);
await page.screenshot({ path: SHOT('01-boot'), scale: 'css' });
await stableShot(page, 'fpremote-01-boot.png');
// Boot's ensure-user-lib created the writable container for this owner.
const ownerHeaders = { [USER_HEADER]: owner };
const libsRes = await fetch(`${BACKEND}/api/scopes/${SCOPE}/libs?kind=footprint`, { headers: ownerHeaders });
const libsBody = (await libsRes.json()) as { id: string; type: string }[];
let libsBody: { id: string; type: string }[] = [];
await expect
.poll(
async () => {
const libsRes = await fetch(`${BACKEND}/api/scopes/${SCOPE}/libs?kind=footprint`, { headers: ownerHeaders });
libsBody = libsRes.ok ? ((await libsRes.json()) as { id: string; type: string }[]) : [];
return libsBody.some((l) => l.type === 'user' && l.id === USER_LIB);
},
{ message: 'user lib created at boot', timeout: 30000, intervals: [500] },
)
.toBe(true);
logs.push(`[spec] libs: ${JSON.stringify(libsBody)}`);
expect(libsBody.some((l) => l.type === 'user' && l.id === USER_LIB), 'user lib created at boot').toBe(true);
// Select the writable USER lib (NOT an origin — origins would mirror, which the
// example backend doesn't implement) so New Footprint targets it.
expect(await clickTreeRow(page, 'My Symbols'), 'selected the user lib row').toBe(true);
await page.waitForTimeout(400);
await page.screenshot({ path: SHOT('02-lib-selected'), scale: 'css' });
await stableShot(page, 'fpremote-02-lib-selected.png');
// New Footprint → auto-saves into the writable lib (tryToSaveFootprintInLibrary).
expect(await clickByTooltip(page, 'New Footprint'), 'New Footprint clicked').toBe(true);
await page.waitForTimeout(1500);
await page.waitForTimeout(1500); // eslint-disable-line -- documented interaction dwell
// Belt-and-braces explicit save.
await focusCanvas(page);
await page.keyboard.press('Control+s');
await page.screenshot({ path: SHOT('03-created'), scale: 'css' });
await stableShot(page, 'fpremote-03-created.png');
// Poll the backend until a footprint item lands.
let items: { kind: string; name: string }[] = [];
@ -98,7 +91,7 @@ test('footprint editor save persists to the backend (remote write round-trip)',
{ timeout: 30000, intervals: [500] },
)
.toBeGreaterThan(0);
await page.screenshot({ path: SHOT('04-saved'), scale: 'css' });
await stableShot(page, 'fpremote-04-saved.png');
const saved = items.find((i) => i.kind === 'footprint')!;
logs.push(`[spec] backend footprint item: ${JSON.stringify(saved)}`);

View file

@ -1,5 +1,5 @@
import { test, expect, type Page } from '@playwright/test';
import { waitForRegistry, clickByTooltip } from '../e2e/utils/element-tracker';
import { clickByTooltip, waitForWxApp, focusCanvas, stableShot } from '../e2e/utils/element-tracker';
/**
* 0009-S footprint write-path spike: does the FOOTPRINT editor boot+render in
@ -18,26 +18,17 @@ import { waitForRegistry, clickByTooltip } from '../e2e/utils/element-tracker';
* save both work. THIS IS THE GATE before the backend (0009-A) is built.
*/
const SHOT = (name: string) => `test-results/fpwrite-${name}.png`;
async function bootFootprintEditor(page: Page): Promise<void> {
await page.goto('/p/demo/footprint_editor/?fpwrite=1');
// GATE part 1: the footprint editor frame renders in WASM (canvas + GL).
await expect(page.locator('#canvas')).toBeVisible({ timeout: 180000 });
await waitForRegistry(page, 180000);
// GATE part 1: the footprint editor frame renders in WASM (canvas + GL) and the
// wx element registry is populated (deterministic, fails loudly).
await waitForWxApp(page, { timeout: 180000 });
await page.waitForFunction(
() => !!window.wxElementRegistry && window.wxElementRegistry.findAll({}).length > 5,
null,
{ timeout: 180000 },
);
await page.waitForFunction(() => !!(window as any).kicadLibs, null, { timeout: 60000 });
await page.waitForTimeout(2000);
}
async function focusCanvas(page: Page): Promise<void> {
const box = await page.locator('#canvas').boundingBox();
if (box) await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
await page.waitForTimeout(300);
}
test('footprint editor save routes through the pcbjam_fp write bridge (main thread)', async ({ page }) => {
@ -46,7 +37,7 @@ test('footprint editor save routes through the pcbjam_fp write bridge (main thre
page.on('pageerror', (e) => logs.push(`[pageerror] ${e.message}`));
await bootFootprintEditor(page);
await page.screenshot({ path: SHOT('01-boot'), scale: 'css' });
await stableShot(page, 'fpwrite-01-boot.png');
// Spike provider is active.
expect(await page.evaluate(() => !!(window as any).__pcbjamSaved), 'spike marker present').toBe(true);
@ -59,37 +50,23 @@ test('footprint editor save routes through the pcbjam_fp write bridge (main thre
const h = rd.find((e: any) => e.elementType === 'columnheader' && e.label === 'Item');
return h ? { cx: h.centerX, cy: h.centerY, hgt: h.height } : null;
});
if (hdr) {
await page.mouse.click(hdr.cx, hdr.cy + hdr.hgt + 8); // focus the tree
await page.waitForTimeout(200);
await page.keyboard.press('Home');
await page.waitForTimeout(150);
await page.keyboard.press('ArrowDown');
await page.waitForTimeout(150);
await page.keyboard.press('ArrowUp');
await page.waitForTimeout(400);
} else {
logs.push('[spec] WARN: Item column header not found (tree may differ); proceeding');
}
await page.screenshot({ path: SHOT('02-lib-selected'), scale: 'css' });
expect(hdr, 'Item column header present').not.toBeNull();
await page.mouse.click(hdr!.cx, hdr!.cy + hdr!.hgt + 8); // focus the tree
await page.waitForTimeout(200); // eslint-disable-line -- documented interaction dwell: tree focus commit
await page.keyboard.press('Home');
await page.waitForTimeout(150); // eslint-disable-line -- documented interaction dwell: tree-nav keystroke commit
await page.keyboard.press('ArrowDown');
await page.waitForTimeout(150); // eslint-disable-line -- documented interaction dwell: tree-nav keystroke commit
await page.keyboard.press('ArrowUp');
await page.waitForTimeout(400); // eslint-disable-line -- documented interaction dwell: tree selection commit
await stableShot(page, 'fpwrite-02-lib-selected.png');
// New Footprint via the toolbar button. The fork action's FriendlyName is
// "New Footprint" (PCB_ACTIONS::newFootprint); the "..." variant is a fallback.
let clicked = await clickByTooltip(page, 'New Footprint');
if (!clicked) clicked = await clickByTooltip(page, 'New Footprint...');
if (!clicked) {
// Diagnostics: dump available tooltips so we can fix the label if needed.
const tips = await page.evaluate(() =>
window.wxElementRegistry
.findAll({})
.map((e: any) => e.tooltip)
.filter((t: string) => !!t),
);
logs.push(`[spec] New Footprint tooltip not found; tooltips: ${JSON.stringify(tips)}`);
}
// "New Footprint" (PCB_ACTIONS::newFootprint).
const clicked = await clickByTooltip(page, 'New Footprint');
expect(clicked, 'New Footprint toolbar button clicked').toBe(true);
await page.waitForTimeout(1500);
await page.screenshot({ path: SHOT('03-newfp-dialog'), scale: 'css' });
await page.waitForTimeout(1500); // eslint-disable-line -- documented interaction dwell: New Footprint dialog/creation commit
await stableShot(page, 'fpwrite-03-newfp-dialog.png');
// Diagnostics: what dialog/controls are present now.
const dlg = await page.evaluate(() => {
@ -106,16 +83,15 @@ test('footprint editor save routes through the pcbjam_fp write bridge (main thre
if (dlg.texts.length > 0) {
const nameField = dlg.texts[0];
await page.mouse.click(nameField.cx, nameField.cy);
await page.waitForTimeout(150);
await page.waitForTimeout(150); // eslint-disable-line -- documented interaction dwell: name field focus commit
await page.keyboard.press('Control+a');
await page.keyboard.press('Delete');
await page.keyboard.type(FP, { delay: 40 });
await page.waitForTimeout(300);
await page.screenshot({ path: SHOT('04-name-typed'), scale: 'css' });
await stableShot(page, 'fpwrite-04-name-typed.png');
await page.keyboard.press('Enter');
await page.waitForTimeout(1500);
await page.waitForTimeout(1500); // eslint-disable-line -- documented interaction dwell: dialog confirm / footprint creation commit
}
await page.screenshot({ path: SHOT('05-fp-created'), scale: 'css' });
await stableShot(page, 'fpwrite-05-fp-created.png');
logs.push(`[spec] title after create: ${await page.title()}`);
// Save: focus the canvas, Ctrl+S (the proven save trigger). The New Footprint
@ -133,7 +109,7 @@ test('footprint editor save routes through the pcbjam_fp write bridge (main thre
null,
{ timeout: 30000 },
);
await page.screenshot({ path: SHOT('06-saved'), scale: 'css' });
await stableShot(page, 'fpwrite-06-saved.png');
const { savedName, body } = await page.evaluate(() => {
const saved = (window as any).__pcbjamSaved as Record<string, string>;
@ -151,7 +127,7 @@ test('footprint editor save routes through the pcbjam_fp write bridge (main thre
// No post-save error dialog (the MEMFS placeholder-file fix for the footprint
// editor's setFPWatcher -> GetModificationTime stat).
await page.waitForTimeout(500);
await page.waitForTimeout(500); // eslint-disable-line -- documented dwell: let any post-save error dialog/log surface before asserting its absence
const errDialog = await page.evaluate(() =>
window.wxElementRegistry
.findAll({ visible: true })

View file

@ -1,5 +1,5 @@
import { test, expect, type Page } from '@playwright/test';
import { waitForRegistry, clickByTooltip } from '../e2e/utils/element-tracker';
import { test, expect } from '@playwright/test';
import { waitForWxApp, focusCanvas, clickByTooltip, stableShot } from '../e2e/utils/element-tracker';
// Mirrors @pcbjam/shared USER_HEADER (tests/ doesn't depend on the shared pkg).
const USER_HEADER = 'x-pcbjam-user';
@ -17,13 +17,6 @@ const SCOPE = 'default';
*/
const BACKEND = process.env.BACKEND_URL ?? 'http://localhost:3060';
const SHOT = (n: string) => `test-results/symremote-${n}.png`;
async function focusCanvas(page: Page): Promise<void> {
const box = await page.locator('#canvas').boundingBox();
if (box) await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
await page.waitForTimeout(300);
}
test('symbol editor save persists to the backend (remote write round-trip)', async ({ page }) => {
// Unique owner per run so the test is isolated from prior runs.
@ -33,16 +26,14 @@ test('symbol editor save persists to the backend (remote write round-trip)', asy
page.on('pageerror', (e) => logs.push(`[pageerror] ${e.message}`));
await page.goto(`/default/projects/demo/-/symbol_editor?libowner=${owner}`);
await expect(page.locator('#canvas')).toBeVisible({ timeout: 150000 });
await waitForRegistry(page, 150000);
await waitForWxApp(page, { timeout: 150000 });
await page.waitForFunction(
() => !!window.wxElementRegistry && window.wxElementRegistry.findAll({}).length > 5,
null,
{ timeout: 150000 },
);
await page.waitForFunction(() => !!(window as any).kicadLibs, null, { timeout: 60000 });
await page.waitForTimeout(2000);
await page.screenshot({ path: SHOT('01-boot'), scale: 'css' });
await stableShot(page, 'symremote-01-boot.png');
// Boot's ensure-user-lib created "My Symbols" (slug my-symbols) for this owner.
const ownerHeaders = { [USER_HEADER]: owner };
@ -58,17 +49,16 @@ test('symbol editor save persists to the backend (remote write round-trip)', asy
});
expect(hdr, 'Item column header found').not.toBeNull();
await page.mouse.click(hdr!.cx, hdr!.cy + hdr!.hgt + 8);
await page.waitForTimeout(200);
await page.waitForTimeout(200); // eslint-disable-line -- documented interaction dwell
await page.keyboard.press('Home');
await page.waitForTimeout(150);
await page.waitForTimeout(150); // eslint-disable-line -- documented interaction dwell
await page.keyboard.press('ArrowDown');
await page.waitForTimeout(150);
await page.waitForTimeout(150); // eslint-disable-line -- documented interaction dwell
await page.keyboard.press('ArrowUp');
await page.waitForTimeout(400);
await page.waitForTimeout(400); // eslint-disable-line -- documented interaction dwell
expect(await clickByTooltip(page, 'New Symbol...'), 'New Symbol clicked').toBe(true);
await page.waitForTimeout(1500);
await page.screenshot({ path: SHOT('02-newsym'), scale: 'css' });
await stableShot(page, 'symremote-02-newsym.png');
// Name field (the one that isn't the lib filter ~y65/87), then confirm.
const nameField = await page.evaluate(() => {
@ -81,13 +71,12 @@ test('symbol editor save persists to the backend (remote write round-trip)', asy
});
expect(nameField, 'New Symbol name field present').toBeTruthy();
await page.mouse.click(nameField!.cx, nameField!.cy);
await page.waitForTimeout(150);
await page.waitForTimeout(150); // eslint-disable-line -- documented interaction dwell
await page.keyboard.press('Control+a');
await page.keyboard.press('Delete');
await page.keyboard.type('RemoteRes', { delay: 40 });
await page.keyboard.press('Enter');
await page.waitForTimeout(1500);
await page.screenshot({ path: SHOT('03-created'), scale: 'css' });
await stableShot(page, 'symremote-03-created.png');
// Save → PUT to the backend.
await focusCanvas(page);
@ -105,7 +94,7 @@ test('symbol editor save persists to the backend (remote write round-trip)', asy
{ timeout: 30000, intervals: [500] },
)
.toBeGreaterThan(0);
await page.screenshot({ path: SHOT('04-saved'), scale: 'css' });
await stableShot(page, 'symremote-04-saved.png');
const saved = items[0];
logs.push(`[spec] backend item: ${JSON.stringify(saved)}`);

View file

@ -1,5 +1,9 @@
import { test, expect, type Page } from '@playwright/test';
import { waitForRegistry, clickByTooltip } from '../e2e/utils/element-tracker';
import {
clickByTooltip,
waitForWxApp,
focusCanvas,
waitUntil, stableShot } from '../e2e/utils/element-tracker';
/**
* 0004-A write-path spike: does the symbol editor's SaveSymbol path route through
@ -13,25 +17,15 @@ import { waitForRegistry, clickByTooltip } from '../e2e/utils/element-tracker';
* fork-native s-expr, and the app stays live (no abort / no OOM respawn).
*/
const SHOT = (name: string) => `test-results/symwrite-${name}.png`;
async function bootSymbolEditor(page: Page): Promise<void> {
await page.goto('/p/demo/symbol_editor/?libwrite=1');
await expect(page.locator('#canvas')).toBeVisible({ timeout: 150000 });
await waitForRegistry(page, 150000);
await waitForWxApp(page, { timeout: 150000 });
await page.waitForFunction(
() => !!window.wxElementRegistry && window.wxElementRegistry.findAll({}).length > 5,
null,
{ timeout: 150000 },
);
await page.waitForFunction(() => !!(window as any).kicadLibs, null, { timeout: 60000 });
await page.waitForTimeout(2000);
}
async function focusCanvas(page: Page): Promise<void> {
const box = await page.locator('#canvas').boundingBox();
if (box) await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
await page.waitForTimeout(300);
}
test('symbol editor save routes through the pcbjam write bridge (main thread)', async ({ page }) => {
@ -40,7 +34,7 @@ test('symbol editor save routes through the pcbjam write bridge (main thread)',
page.on('pageerror', (e) => logs.push(`[pageerror] ${e.message}`));
await bootSymbolEditor(page);
await page.screenshot({ path: SHOT('01-boot'), scale: 'css' });
await stableShot(page, 'symwrite-01-boot.png');
// Spike provider is active.
expect(await page.evaluate(() => !!(window as any).__pcbjamSaved), 'spike marker present').toBe(true);
@ -57,20 +51,24 @@ test('symbol editor save routes through the pcbjam write bridge (main thread)',
// Click focuses the tree row but doesn't always select it; drive the keyboard
// to make the first (only) library row the SELECTED item (GetTargetLibId).
await page.mouse.click(hdr!.cx, hdr!.cy + hdr!.hgt + 8); // focus the tree
await page.waitForTimeout(200);
await page.waitForTimeout(200); // eslint-disable-line -- documented interaction dwell
await page.keyboard.press('Home');
await page.waitForTimeout(150);
await page.waitForTimeout(150); // eslint-disable-line -- documented interaction dwell
await page.keyboard.press('ArrowDown');
await page.waitForTimeout(150);
await page.waitForTimeout(150); // eslint-disable-line -- documented interaction dwell
await page.keyboard.press('ArrowUp');
await page.waitForTimeout(400);
await page.screenshot({ path: SHOT('02-lib-selected'), scale: 'css' });
await page.waitForTimeout(400); // eslint-disable-line -- documented interaction dwell
await stableShot(page, 'symwrite-02-lib-selected.png');
// New Symbol via the toolbar button (tooltip), proven-clickable in the harness.
const clicked = await clickByTooltip(page, 'New Symbol...');
expect(clicked, 'New Symbol toolbar button clicked').toBe(true);
await page.waitForTimeout(1500);
await page.screenshot({ path: SHOT('03-newsym-dialog'), scale: 'css' });
await waitUntil(
page,
() => window.wxElementRegistry.findAll({ visible: true }).some((e: any) => /Dialog/i.test(e.typeName)),
'New Symbol dialog visible',
);
await stableShot(page, 'symwrite-03-newsym-dialog.png');
// Diagnostics: what dialog/controls are present now.
const dlg = await page.evaluate(() => {
@ -87,15 +85,19 @@ test('symbol editor save routes through the pcbjam write bridge (main thread)',
const nameField = dlg.texts.find((t) => Math.abs(t.cy - 65) > 30 && Math.abs(t.cy - 87) > 30);
expect(nameField, 'New Symbol name field present').toBeTruthy();
await page.mouse.click(nameField!.cx, nameField!.cy);
await page.waitForTimeout(150);
await page.waitForTimeout(150); // eslint-disable-line -- documented interaction dwell
await page.keyboard.press('Control+a');
await page.keyboard.press('Delete');
await page.keyboard.type(SYM, { delay: 40 });
await page.waitForTimeout(300);
await page.screenshot({ path: SHOT('04-name-typed'), scale: 'css' });
await page.waitForTimeout(300); // eslint-disable-line -- documented interaction dwell
await stableShot(page, 'symwrite-04-name-typed.png');
await page.keyboard.press('Enter');
await page.waitForTimeout(1500);
await page.screenshot({ path: SHOT('05-symbol-created'), scale: 'css' });
await waitUntil(
page,
() => !window.wxElementRegistry.findAll({ visible: true }).some((e: any) => /Dialog/i.test(e.typeName)),
'New Symbol dialog dismissed',
);
await stableShot(page, 'symwrite-05-symbol-created.png');
// Title should reflect the new symbol now being edited.
const titleAfterCreate = await page.title();
@ -115,7 +117,7 @@ test('symbol editor save routes through the pcbjam write bridge (main thread)',
null,
{ timeout: 30000 },
);
await page.screenshot({ path: SHOT('06-saved'), scale: 'css' });
await stableShot(page, 'symwrite-06-saved.png');
const { savedName, body } = await page.evaluate(() => {
const saved = (window as any).__pcbjamSaved as Record<string, string>;
@ -131,7 +133,7 @@ test('symbol editor save routes through the pcbjam write bridge (main thread)',
expect(body).toContain(`(symbol "${savedName}"`);
// No post-save error dialog (the placeholder-file fix for GetModificationTime).
await page.waitForTimeout(500);
await page.waitForTimeout(500); // eslint-disable-line -- documented interaction dwell
const errDialog = await page.evaluate(() =>
window.wxElementRegistry
.findAll({ visible: true })

View file

@ -1,5 +1,5 @@
import { test, expect, type Page } from '@playwright/test';
import { clickMenuBarItem, clickMenuItem } from '../e2e/utils/element-tracker';
import { clickMenuBarItem, clickMenuItemByText, stableShot } from '../e2e/utils/element-tracker';
/**
* Tool-switch e2e: eeschema Tools → "Switch to PCB Editor" (and the reverse)
@ -38,9 +38,7 @@ async function switchTool(
expectedTitle: RegExp
): Promise<void> {
expect(await clickMenuBarItem(page, 'Tools'), 'Tools menubar item clickable').toBe(true);
await page.waitForTimeout(400); // popup render settle, same as tests/kicad specs
expect(await clickMenuItem(page, menuLabel), `"${menuLabel}" menu item clickable`).toBe(true);
await clickMenuItemByText(page, menuLabel);
await page.waitForURL(expectedUrl, { timeout: 30000 });
await waitForToolReady(page, expectedTitle);
@ -60,10 +58,7 @@ test.describe('web app — tool switching', () => {
/demo — PCB Editor/i
);
await page.screenshot({
path: 'test-results/web-switch-sch-to-pcb.png',
scale: 'css',
});
await stableShot(page, 'web-switch-sch-to-pcb.png');
});
test('pcbnew → Switch to Schematic Editor navigates to eeschema', async ({ page }) => {
@ -79,9 +74,6 @@ test.describe('web app — tool switching', () => {
/demo — Schematic Editor/i
);
await page.screenshot({
path: 'test-results/web-switch-pcb-to-sch.png',
scale: 'css',
});
await stableShot(page, 'web-switch-pcb-to-sch.png');
});
});