Refactor test logging into shared utilities
- Extract common logging code to tests/e2e/utils/ - fixtures.ts: Playwright fixture with automatic log capture - test-utils.ts: Logging utilities and helper functions - Each test now automatically captures: - Console logs with timestamps and log levels - Page errors with full stack traces - Log files written per test to tests/logs/ - <test-name>.log for all console output - <test-name>.errors.log only when errors occur - Update all 13 spec files to use shared fixtures - Update README with test structure and logging docs - Net reduction of ~700 lines by removing duplicated code 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2264a22685
commit
26181bb929
16 changed files with 431 additions and 1131 deletions
|
|
@ -1,53 +1,23 @@
|
|||
// wxClipboard Tests - Clipboard operations for KiCad copy/paste
|
||||
import { test, expect, Page } from '@playwright/test';
|
||||
|
||||
const MAIN_CANVAS = '#canvas';
|
||||
|
||||
async function waitForApp(page: Page, timeout = 30000) {
|
||||
await page.waitForSelector(MAIN_CANVAS, { state: 'visible', timeout });
|
||||
await page.waitForTimeout(500);
|
||||
}
|
||||
|
||||
async function tryLoadApp(page: Page) {
|
||||
try {
|
||||
await waitForApp(page, 15000);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
import { test, expect, MAIN_CANVAS, tryLoadApp, getCanvasBox } from './utils/fixtures';
|
||||
|
||||
test.describe('wxClipboard Tests', () => {
|
||||
|
||||
test('Clipboard test app loads successfully', async ({ page }) => {
|
||||
const errors: string[] = [];
|
||||
const logs: string[] = [];
|
||||
|
||||
page.on('pageerror', err => {
|
||||
errors.push(`[PAGE_ERROR] ${err.message}`);
|
||||
});
|
||||
page.on('console', msg => {
|
||||
logs.push(`[${msg.type()}] ${msg.text()}`);
|
||||
});
|
||||
|
||||
test('Clipboard test app loads successfully', async ({ page, testLogger }) => {
|
||||
await page.goto('/standalone/clipboard/clipboard_test.html');
|
||||
const loaded = await tryLoadApp(page);
|
||||
|
||||
await page.screenshot({ path: 'test-results/clipboard-01-loaded.png', fullPage: true });
|
||||
|
||||
const hasStartupLog = logs.some(l => l.includes('wxClipboard test app started') || l.includes('Clipboard test app started'));
|
||||
console.log('Clipboard app logs:', logs.filter(l => l.includes('CLIPBOARD')));
|
||||
console.log('Clipboard app loaded:', loaded);
|
||||
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(errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
|
||||
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('Copy button can be clicked', async ({ page }) => {
|
||||
const logs: string[] = [];
|
||||
|
||||
page.on('console', msg => logs.push(msg.text()));
|
||||
|
||||
test('Copy button can be clicked', async ({ page, testLogger }) => {
|
||||
await page.goto('/standalone/clipboard/clipboard_test.html');
|
||||
const loaded = await tryLoadApp(page);
|
||||
if (!loaded) {
|
||||
|
|
@ -55,9 +25,7 @@ test.describe('wxClipboard Tests', () => {
|
|||
return;
|
||||
}
|
||||
|
||||
const canvas = page.locator(MAIN_CANVAS);
|
||||
const box = await canvas.boundingBox();
|
||||
if (!box) throw new Error('Canvas not found');
|
||||
const box = await getCanvasBox(page);
|
||||
|
||||
// Click "Copy to Clipboard" button
|
||||
await page.mouse.click(box.x + 100, box.y + 220);
|
||||
|
|
@ -65,17 +33,10 @@ test.describe('wxClipboard Tests', () => {
|
|||
|
||||
await page.screenshot({ path: 'test-results/clipboard-02-copy-clicked.png', fullPage: true });
|
||||
|
||||
const hasCopyLog = logs.some(l => l.includes('copy') || l.includes('Copy') || l.includes('Copied'));
|
||||
console.log('Copy logs:', logs.filter(l => l.includes('CLIPBOARD') || l.includes('copy') || l.includes('Copy')));
|
||||
|
||||
expect(true).toBe(true); // Smoke test
|
||||
});
|
||||
|
||||
test('Paste button can be clicked', async ({ page }) => {
|
||||
const logs: string[] = [];
|
||||
|
||||
page.on('console', msg => logs.push(msg.text()));
|
||||
|
||||
test('Paste button can be clicked', async ({ page, testLogger }) => {
|
||||
await page.goto('/standalone/clipboard/clipboard_test.html');
|
||||
const loaded = await tryLoadApp(page);
|
||||
if (!loaded) {
|
||||
|
|
@ -83,9 +44,7 @@ test.describe('wxClipboard Tests', () => {
|
|||
return;
|
||||
}
|
||||
|
||||
const canvas = page.locator(MAIN_CANVAS);
|
||||
const box = await canvas.boundingBox();
|
||||
if (!box) throw new Error('Canvas not found');
|
||||
const box = await getCanvasBox(page);
|
||||
|
||||
// First copy something
|
||||
await page.mouse.click(box.x + 100, box.y + 220);
|
||||
|
|
@ -97,16 +56,10 @@ test.describe('wxClipboard Tests', () => {
|
|||
|
||||
await page.screenshot({ path: 'test-results/clipboard-03-paste-clicked.png', fullPage: true });
|
||||
|
||||
console.log('Paste logs:', logs.filter(l => l.includes('CLIPBOARD') || l.includes('paste') || l.includes('Paste')));
|
||||
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
|
||||
test('Check clipboard button works', async ({ page }) => {
|
||||
const logs: string[] = [];
|
||||
|
||||
page.on('console', msg => logs.push(msg.text()));
|
||||
|
||||
test('Check clipboard button works', async ({ page, testLogger }) => {
|
||||
await page.goto('/standalone/clipboard/clipboard_test.html');
|
||||
const loaded = await tryLoadApp(page);
|
||||
if (!loaded) {
|
||||
|
|
@ -114,9 +67,7 @@ test.describe('wxClipboard Tests', () => {
|
|||
return;
|
||||
}
|
||||
|
||||
const canvas = page.locator(MAIN_CANVAS);
|
||||
const box = await canvas.boundingBox();
|
||||
if (!box) throw new Error('Canvas not found');
|
||||
const box = await getCanvasBox(page);
|
||||
|
||||
// Click "Check Clipboard" button
|
||||
await page.mouse.click(box.x + 400, box.y + 220);
|
||||
|
|
@ -124,16 +75,10 @@ test.describe('wxClipboard Tests', () => {
|
|||
|
||||
await page.screenshot({ path: 'test-results/clipboard-04-check-clicked.png', fullPage: true });
|
||||
|
||||
console.log('Check logs:', logs.filter(l => l.includes('CLIPBOARD') || l.includes('Check') || l.includes('contains')));
|
||||
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
|
||||
test('Clear clipboard button works', async ({ page }) => {
|
||||
const logs: string[] = [];
|
||||
|
||||
page.on('console', msg => logs.push(msg.text()));
|
||||
|
||||
test('Clear clipboard button works', async ({ page, testLogger }) => {
|
||||
await page.goto('/standalone/clipboard/clipboard_test.html');
|
||||
const loaded = await tryLoadApp(page);
|
||||
if (!loaded) {
|
||||
|
|
@ -141,9 +86,7 @@ test.describe('wxClipboard Tests', () => {
|
|||
return;
|
||||
}
|
||||
|
||||
const canvas = page.locator(MAIN_CANVAS);
|
||||
const box = await canvas.boundingBox();
|
||||
if (!box) throw new Error('Canvas not found');
|
||||
const box = await getCanvasBox(page);
|
||||
|
||||
// First copy something
|
||||
await page.mouse.click(box.x + 100, box.y + 220);
|
||||
|
|
@ -155,18 +98,10 @@ test.describe('wxClipboard Tests', () => {
|
|||
|
||||
await page.screenshot({ path: 'test-results/clipboard-05-clear-clicked.png', fullPage: true });
|
||||
|
||||
console.log('Clear logs:', logs.filter(l => l.includes('CLIPBOARD') || l.includes('clear') || l.includes('Clear')));
|
||||
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
|
||||
test('Full clipboard flow: copy, check, paste, clear', async ({ page }) => {
|
||||
const errors: string[] = [];
|
||||
const logs: string[] = [];
|
||||
|
||||
page.on('pageerror', err => errors.push(err.message));
|
||||
page.on('console', msg => logs.push(msg.text()));
|
||||
|
||||
test('Full clipboard flow: copy, check, paste, clear', async ({ page, testLogger }) => {
|
||||
await page.goto('/standalone/clipboard/clipboard_test.html');
|
||||
const loaded = await tryLoadApp(page);
|
||||
if (!loaded) {
|
||||
|
|
@ -174,9 +109,7 @@ test.describe('wxClipboard Tests', () => {
|
|||
return;
|
||||
}
|
||||
|
||||
const canvas = page.locator(MAIN_CANVAS);
|
||||
const box = await canvas.boundingBox();
|
||||
if (!box) throw new Error('Canvas not found');
|
||||
const box = await getCanvasBox(page);
|
||||
|
||||
// 1. Copy
|
||||
await page.mouse.click(box.x + 100, box.y + 220);
|
||||
|
|
@ -196,9 +129,6 @@ test.describe('wxClipboard Tests', () => {
|
|||
|
||||
await page.screenshot({ path: 'test-results/clipboard-06-full-flow.png', fullPage: true });
|
||||
|
||||
console.log('\n=== CLIPBOARD EVENTS ===');
|
||||
logs.filter(l => l.includes('CLIPBOARD')).forEach(l => console.log(l));
|
||||
|
||||
expect(errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
|
||||
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue