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,177 +1,132 @@
// wxClipboard Tests - Clipboard operations for KiCad copy/paste
// Uses element registry for semantic element identification
import { test, expect, tryLoadApp, waitForRegistry, clickByLabel } from './utils/fixtures';
import { test, expect, waitForWxApp, clickByLabel } from './utils/fixtures';
import { stableShot } from './utils/element-tracker';
test.describe('wxClipboard Tests', () => {
test('Clipboard test app loads successfully', async ({ page, testLogger }) => {
await page.goto('/standalone/clipboard/clipboard_test.html');
const loaded = await tryLoadApp(page);
await waitForWxApp(page);
await page.screenshot({ path: 'test-results/clipboard-01-loaded.png', fullPage: true });
await stableShot(page, 'clipboard-01-loaded.png', { fullPage: true });
const hasStartupLog = testLogger.consoleLogs.some(l =>
l.includes('wxClipboard test app started') || l.includes('Clipboard test app started')
);
expect(loaded, 'wxClipboard app should load').toBe(true);
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
});
test('Copy button copies text to clipboard', async ({ page, testLogger }) => {
await page.goto('/standalone/clipboard/clipboard_test.html');
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForRegistry(page);
await waitForWxApp(page);
// Click "Copy to Clipboard" button
await clickByLabel(page, 'Copy to Clipboard');
await page.waitForTimeout(2500); // Wait for async clipboard operation + timeout
await page.screenshot({ path: 'test-results/clipboard-02-copy-clicked.png', fullPage: true });
// Check for SUCCESS log (clipboard implementation working) or at least the attempt log
const hasCopySuccess = testLogger.consoleLogs.some(l =>
l.includes('SUCCESS') && l.includes('Copied')
);
const hasCopyAttempt = testLogger.consoleLogs.some(l =>
l.includes('Attempting to copy')
);
// Either success (real clipboard worked) or at least attempt was made
expect(hasCopySuccess || hasCopyAttempt, 'Copy should succeed or at least attempt').toBe(true);
await expect.poll(() => testLogger.consoleLogs.some(l =>
(l.includes('SUCCESS') && l.includes('Copied')) || l.includes('Attempting to copy')
), { message: 'Copy should succeed or at least attempt' }).toBe(true);
await stableShot(page, 'clipboard-02-copy-clicked.png', { fullPage: true });
});
test('Paste button retrieves text from clipboard', async ({ page, testLogger }) => {
await page.goto('/standalone/clipboard/clipboard_test.html');
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForRegistry(page);
await waitForWxApp(page);
// First copy something
await clickByLabel(page, 'Copy to Clipboard');
await page.waitForTimeout(2500);
await expect.poll(() => testLogger.consoleLogs.some(l =>
(l.includes('SUCCESS') && l.includes('Copied')) || l.includes('Attempting to copy')
), { message: 'Copy should log activity' }).toBe(true);
// Click "Paste from Clipboard" button
await clickByLabel(page, 'Paste from Clipboard');
await page.waitForTimeout(2500);
await page.screenshot({ path: 'test-results/clipboard-03-paste-clicked.png', fullPage: true });
// Check for SUCCESS log or at least no ERROR
const hasPasteSuccess = testLogger.consoleLogs.some(l =>
l.includes('SUCCESS') && l.includes('Pasted')
);
const hasPasteWarning = testLogger.consoleLogs.some(l =>
l.includes('WARNING') && l.includes('No text data')
);
const hasPasteAttempt = testLogger.consoleLogs.some(l =>
l.includes('Attempting to paste')
);
// Either we successfully pasted, there was no text (valid), or at least we attempted
expect(hasPasteSuccess || hasPasteWarning || hasPasteAttempt, 'Paste should succeed or report no text').toBe(true);
await expect.poll(() => testLogger.consoleLogs.some(l =>
(l.includes('SUCCESS') && l.includes('Pasted')) ||
(l.includes('WARNING') && l.includes('No text data')) ||
l.includes('Attempting to paste')
), { message: 'Paste should succeed or report no text' }).toBe(true);
await stableShot(page, 'clipboard-03-paste-clicked.png', { fullPage: true });
});
test('Check clipboard button reports clipboard content', async ({ page, testLogger }) => {
await page.goto('/standalone/clipboard/clipboard_test.html');
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForRegistry(page);
await waitForWxApp(page);
// First copy something to ensure clipboard has content
await clickByLabel(page, 'Copy to Clipboard');
await page.waitForTimeout(2500);
await expect.poll(() => testLogger.consoleLogs.some(l =>
(l.includes('SUCCESS') && l.includes('Copied')) || l.includes('Attempting to copy')
), { message: 'Copy should log activity' }).toBe(true);
// Click "Check Clipboard" button
await clickByLabel(page, 'Check Clipboard');
await page.waitForTimeout(2500);
await page.screenshot({ path: 'test-results/clipboard-04-check-clicked.png', fullPage: true });
// Check for clipboard content report
const hasCheckResult = testLogger.consoleLogs.some(l =>
await expect.poll(() => testLogger.consoleLogs.some(l =>
l.includes('Clipboard contains') || l.includes('Checking clipboard')
);
), { message: 'Check should report clipboard contents' }).toBe(true);
expect(hasCheckResult, 'Check should report clipboard contents').toBe(true);
await stableShot(page, 'clipboard-04-check-clicked.png', { fullPage: true });
});
test('Clear clipboard button clears clipboard', async ({ page, testLogger }) => {
await page.goto('/standalone/clipboard/clipboard_test.html');
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForRegistry(page);
await waitForWxApp(page);
// First copy something
await clickByLabel(page, 'Copy to Clipboard');
await page.waitForTimeout(2500);
await expect.poll(() => testLogger.consoleLogs.some(l =>
(l.includes('SUCCESS') && l.includes('Copied')) || l.includes('Attempting to copy')
), { message: 'Copy should log activity' }).toBe(true);
// Click "Clear Clipboard" button
await clickByLabel(page, 'Clear Clipboard');
await page.waitForTimeout(2500);
await page.screenshot({ path: 'test-results/clipboard-05-clear-clicked.png', fullPage: true });
// Check for SUCCESS log or at least attempt
const hasClearSuccess = testLogger.consoleLogs.some(l =>
l.includes('SUCCESS') && l.includes('Clipboard cleared')
);
const hasClearAttempt = testLogger.consoleLogs.some(l =>
l.includes('Attempting to clear')
);
await expect.poll(() => testLogger.consoleLogs.some(l =>
(l.includes('SUCCESS') && l.includes('Clipboard cleared')) || l.includes('Attempting to clear')
), { message: 'Clear should succeed or at least attempt' }).toBe(true);
expect(hasClearSuccess || hasClearAttempt, 'Clear should succeed or at least attempt').toBe(true);
await stableShot(page, 'clipboard-05-clear-clicked.png', { fullPage: true });
});
test('Full clipboard flow: copy, check, paste, clear', async ({ page, testLogger }) => {
await page.goto('/standalone/clipboard/clipboard_test.html');
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForRegistry(page);
await waitForWxApp(page);
// 1. Copy
await clickByLabel(page, 'Copy to Clipboard');
await page.waitForTimeout(2500);
const hasCopyLog = testLogger.consoleLogs.some(l =>
await expect.poll(() => testLogger.consoleLogs.some(l =>
l.includes('SUCCESS') && l.includes('Copied') || l.includes('Attempting to copy')
);
expect(hasCopyLog, 'Copy should log activity').toBe(true);
), { message: 'Copy should log activity' }).toBe(true);
// 2. Check
await clickByLabel(page, 'Check Clipboard');
await page.waitForTimeout(2500);
const hasCheckResult = testLogger.consoleLogs.some(l =>
await expect.poll(() => testLogger.consoleLogs.some(l =>
l.includes('Clipboard contains') || l.includes('Checking clipboard')
);
expect(hasCheckResult, 'Check should report clipboard').toBe(true);
), { message: 'Check should report clipboard' }).toBe(true);
// 3. Paste
await clickByLabel(page, 'Paste from Clipboard');
await page.waitForTimeout(2500);
const hasPasteLog = testLogger.consoleLogs.some(l =>
await expect.poll(() => testLogger.consoleLogs.some(l =>
l.includes('SUCCESS') && l.includes('Pasted') || l.includes('Attempting to paste')
);
expect(hasPasteLog, 'Paste should log activity').toBe(true);
), { message: 'Paste should log activity' }).toBe(true);
// 4. Clear
await clickByLabel(page, 'Clear Clipboard');
await page.waitForTimeout(2500);
const hasClearLog = testLogger.consoleLogs.some(l =>
await expect.poll(() => testLogger.consoleLogs.some(l =>
l.includes('SUCCESS') && l.includes('Clipboard cleared') || l.includes('Attempting to clear')
);
expect(hasClearLog, 'Clear should log activity').toBe(true);
), { message: 'Clear should log activity' }).toBe(true);
await page.screenshot({ path: 'test-results/clipboard-06-full-flow.png', fullPage: true });
await stableShot(page, 'clipboard-06-full-flow.png', { fullPage: true });
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
});