--- name: playwright-recording-processor description: "Transforms raw Playwright codegen recordings into production-ready E2E tests through trimming, classification, and assertion injection. Use when processing codegen session recordings, trimming recorded browser sessions to a marker URL, classifying recordings as happy-path or bug-repro flows, or injecting diagnostic capture into reproduction tests. Invoke to convert a raw codegen recording into a maintainable test file or to build a bug reproduction test with console/network/state diagnostics." license: MIT metadata: author: https://github.com/dheerajc8073 version: "1.0.0" domain: quality triggers: codegen, recording, trim, marker URL, bug repro, diagnostic capture, session recording, Playwright codegen, recording processing, test generation role: specialist scope: implementation output-format: code related-skills: playwright-expert, test-master --- # Playwright Recording Processor Recording processing specialist that converts raw Playwright codegen output into structured, maintainable E2E tests. ## Core Workflow 1. **Trim** — Cut the raw recording at the exact marker URL path, discarding pre-feature navigation (via `scripts/trim-recording.ts` saved from `references/trim-recording.md` or manual inline steps) 2. **Classify** — Determine flow type: happy path (feature coverage) or bug reproduction (diagnostic capture) 3. **Swap fixtures** — Replace raw `page` references with custom fixtures (e.g. `authenticatedPage` from `e2e/fixtures.ts`); update imports to load `test` from the project's fixture file 4. **Harden** — Replace brittle selectors with role-based locators (cross-ref `playwright-expert`) 5. **Assert** — Inject assertions appropriate to flow type: checkpoint verification (happy path) or expected-outcome assertion with diagnostic capture in `finally` and screenshot capture in `test.afterEach` (bug repro) ## Quick-Start Example Transform raw recorded actions into an assertion-rich test using the auth fixture (assumes `baseURL` in `playwright.config.ts`): ```typescript // ❌ Raw recording (untrimmed with manual auth, hardcoded URL, no assertions) // await page.goto('https://app.example.com/login'); // await page.getByLabel('Email').fill('user@example.com'); // await page.getByRole('button', { name: 'Sign in' }).click(); // await page.goto('https://app.example.com/invoices/export'); // await page.getByRole('button', { name: 'Download' }).click(); // ✅ Processed test (trimmed to marker URL, custom fixture, assertions added) import { test, expect } from './fixtures'; // Source recording: recordings/raw-session-20240315.spec.ts (lines 14-22) test('Invoice Export @happy-path', async ({ authenticatedPage: page }) => { await page.goto('/invoices/export'); await expect(page.getByRole('heading', { name: 'Export' })).toBeVisible(); const downloadPromise = page.waitForEvent('download'); await page.getByRole('button', { name: 'Download' }).click(); const download = await downloadPromise; expect(download.suggestedFilename()).toMatch(/\.csv$/); }); ``` ## Inputs Required 1. Raw recording file — the `.spec.ts` output from `npx playwright codegen` 2. Marker URL — the path where the feature under test begins (e.g. `/invoices/export`) 3. Flow type — happy path or bug reproduction 4. Auth fixture name and import path — e.g. `authenticatedPage` from `./fixtures` for a spec in `e2e/`; a spec in `integration/` needs the path from there to `e2e/fixtures.ts` 5. Output target — `e2e/` or `integration/` depending on scope If any of these are missing, ask before proceeding. ## Flow Classification ### Happy Path Flow Use when: - Testing a new feature for the first time - Adding coverage for a release - Tester followed a structured checklist Output: A clean spec with the full user journey from marker URL to completion, using the existing auth fixture, with assertions added at key checkpoints. ### Bug Reproduction Flow Use when: - A nontechnical user reported "the app broke" - You need to capture what they actually did, in what state, on what browser - The goal is a reproducible failing test to anchor a fix Output: A spec that asserts the expected behavior (failing while bug is present) and captures full runtime diagnostic metadata (`diagnostic-report`) in a `finally` block (with failure screenshots captured via `test.afterEach` hook) so timeouts never lose diagnostics. ## Reference Guide Load detailed guidance based on context: | Topic | Reference | Load When | |-------|-----------|-----------| | Assertion Patterns | `references/assertion-patterns.md` | Adding assertions by UI element type | | Trim Recording | `references/trim-recording.md` | Trimming raw codegen output, exact marker URL path | | Bug Repro Diagnostics | `references/bug-repro-diagnostics.md` | Diagnostic injection, console/network/state capture | ### Cross-References (from `playwright-expert`, not duplicated) - For locator hardening patterns, see `playwright-expert` (`selectors-locators.md`) - For Page Object Model and fixture patterns, see `playwright-expert` (`page-object-model.md`) - For debugging flaky processed tests, see `playwright-expert` (`debugging-flaky.md`) ## Constraints ### MUST DO - Always trim to the exact marker URL pathname before processing - Classify every recording before adding assertions - Use role-based selectors from `playwright-expert` patterns when hardening - In bug repro flows, assert the expected behavior and attach `diagnostic-report` in a `finally` block (capturing failure screenshots via `test.afterEach`) - Import `test` from the project's fixture file when custom fixtures are swapped in - Annotate generated tests with source recording comments: `// Source recording: recordings/.spec.ts (lines X-Y)` - Assume `baseURL` is configured; use relative paths for URLs from marker URL onwards ### MUST NOT DO - Process untrimmed recordings (pre-feature navigation noise pollutes tests) - Add multi-step feature verification assertions to bug repro tests (only assert the single reported failure point) - Generate tests without assertion injection (both happy-path and bug-repro tests require assertions) - Duplicate locator/POM patterns already covered by `playwright-expert` - Use `waitForTimeout()` in generated tests (replace with auto-waiting web assertions or waitForURL) ## Output File Placement - `e2e/`: Full journeys crossing multiple pages or system boundaries - `integration/`: Scoped to feature area; bug repros usually land here - `recordings/`: Archive only — raw files are never run directly ## Checklist Before Handing Off - [ ] Trimmed to exact marker URL path — no auth or pre-feature navigation - [ ] Auth fixture swapped in and imported from project fixture file - [ ] All locators are semantic (role, label, text) not positional - [ ] Assertions added: checkpoint assertions (happy path) or expected-behavior assertion (bug repro) - [ ] Diagnostic collection attached in `finally` block under `diagnostic-report` (bug repro) and failure screenshots captured via `test.afterEach` - [ ] Any `waitForTimeout()` calls removed and replaced with auto-waiting assertions - [ ] Source recording comment added at top of test - [ ] Tagged correctly (`@happy-path` or `@bug-repro`) - [ ] Placed in correct output directory - [ ] Raw recording archived untouched in `recordings/` [Documentation](https://jeffallan.github.io/claude-skills/skills/quality/playwright-recording-processor/)