Generate Playwright E2E Test
Create idiomatic Playwright e2e tests for OpenShift Console features following the project's established patterns.
Before Starting
- Check that
frontend/e2e/.env exists. If missing and --analyze is not specified, copy frontend/e2e/.env.example to frontend/e2e/.env and ask the user to fill in their cluster values. During --analyze, report the missing file without creating it.
- Read
.claude/e2e-context.md for project conventions, patterns, and rules. That file is the single source of truth for how Playwright tests should be structured.
- Read
frontend/e2e/fixtures/index.ts and trace its imports to discover all available fixtures.
Input
/gen-e2e-test <description>: generate test for the described feature/workflow
/gen-e2e-test <description> --project=<name>: specify the Playwright project (default: inferred from feature area)
/gen-e2e-test <description> --analyze: produce a test plan without generating code
Examples
/gen-e2e-test "ConfigMap CRUD operations in admin perspective"
/gen-e2e-test "verify topology view shows deployments" --project=topology
/gen-e2e-test "developer user creates a project and deploys from git" --project=dev-console-developer
Workflow
Phase 1: Scope
- Understand the feature/workflow to test from the user's description
- Identify the Playwright project and output directory (see
e2e-context.md Project Structure)
- Identify admin vs developer persona
- Determine test isolation strategy: self-contained (A), shared resources (B), or API-created (C)
- Determine if tests can run in parallel or must be serial:
- Parallel: tests are independent, each creates its own namespace, no shared mutable state
- Serial (default): tests share a namespace, modify global settings, or depend on order
- Document each test's intent in plain language
- Produce a test plan:
Test Plan: <feature>
Project: <playwright-project>
Output: e2e/tests/<project>/<name>.spec.ts
Persona: admin | developer
Isolation: Strategy A | B | C
Execution: serial | parallel
Tests:
1. <test name>: <intent>
2. <test name>: <intent>
Page objects:
- Reuse: <existing page objects>
- Create: <new page objects needed>
Resources:
- <namespace, deployment, configmap, etc.>
Stop here if --analyze was specified. Ask the user to review and confirm before proceeding.
Phase 2: Discover
Search existing page objects: find frontend/e2e/pages -name "*.ts"
Read relevant page objects to understand available methods and locators
Read frontend/e2e/fixtures/index.ts to understand available fixtures
Read frontend/e2e/clients/kubernetes-client.ts for available K8s API methods
If the feature involves React components, read the component source to find existing data-test attributes
If Playwright MCP is available:
- Resize viewport to 1920x1080
- Navigate to target pages in the live UI
- Snapshot accessibility tree to discover selectors and
data-test attributes
- Verify selectors with non-submitting interactions (click navigation elements, type in search fields)
- Do not submit forms, create resources, or perform state-changing actions during discovery. Ask the user before login or credential entry
If MCP is unavailable or no cluster is reachable, log a warning: "Playwright MCP not available. Selectors based on React source only. Run /debug-test after deployment to verify." Proceed to Phase 3.
Phase 3: Implement
Add data-test attributes to React components if needed. When a component only has legacy test attributes (data-test-id, etc.), add data-test alongside the legacy attribute (see e2e-context.md Test Selectors)
Create/extend page objects if needed:
- Follow the BasePage pattern from
e2e-context.md
private readonly locator properties using getByTestId() or locator()
- Getter methods to expose locators (
getX(): Locator)
- Action methods returning
Promise<void>
- Use
robustClick() for clicks inside page objects
- Do NOT add
waitFor() before action methods. Playwright auto-waits
Write the spec file:
import { test, expect } from '../../fixtures' (adjust relative path based on test depth)
- Tags are optional. Only add them if they enable filtering beyond the directory structure (see
e2e-context.md Tags section)
- Apply the chosen isolation strategy and execution mode
- Use
test.step() for multi-phase workflows within a single test
- Track all created resources with
cleanup.track*() or use test.afterAll for shared resources
- Name tests by user intent, not implementation
Validate code (run from frontend/):
cd frontend && npx tsc --noEmit -p e2e/tsconfig.json: zero type errors
cd frontend && yarn eslint <generated-files>: fix lint errors
Phase 4: Verify
- Run (from
frontend/): cd frontend && npx playwright test --project=<project> <spec-file> --retries=0
- For developer tests:
--project=<project>-developer
- Note:
e2e/.env may set WEB_CONSOLE_URL to a remote cluster. If running against localhost, verify .env or override with WEB_CONSOLE_URL=http://localhost:9000
- Debug failures using Playwright MCP if available (navigate → snapshot → console → network). Fix and re-run.
- If a test still fails after 3 fix attempts, stop trying and ask the user if they want to run
/debug-test <spec-file> for deeper MCP-assisted diagnosis.
- Run 2 additional times to confirm stability
- Verify no orphaned resources after test run
- Output summary:
Generation complete: e2e/tests/<project>/<name>.spec.ts
Tests created: N
Page objects created: [list]
Page objects reused: [list]
Files written: [list]
Validation: passed
Rules
- Always read
e2e-context.md before writing any code
- Discover available fixtures and page objects before creating new ones
- Use Playwright MCP to verify selectors when available
- Follow the project's existing patterns. Don't invent new conventions
- Golden path first. Only add edge case tests when explicitly asked
- DO NOT commit. The user handles git operations
1---2name: gen-e2e-test3description: Generate Playwright e2e tests for OpenShift Console features. Creates spec files and page objects following the project's established patterns and conventions. Use this skill whenever the user wants to create, write, or add e2e tests, asks to cover a feature with e2e, describes a UI workflow to test, says "I need to test this feature", "add test coverage for X", or invokes /gen-e2e-test explicitly.4---56# Generate Playwright E2E Test78Create idiomatic Playwright e2e tests for OpenShift Console features following the project's established patterns.910## Before Starting11121. Check that `frontend/e2e/.env` exists. If missing and `--analyze` is not specified, copy `frontend/e2e/.env.example` to `frontend/e2e/.env` and ask the user to fill in their cluster values. During `--analyze`, report the missing file without creating it.132. Read `.claude/e2e-context.md` for project conventions, patterns, and rules. That file is the single source of truth for how Playwright tests should be structured.143. Read `frontend/e2e/fixtures/index.ts` and trace its imports to discover all available fixtures.1516## Input1718- `/gen-e2e-test <description>`: generate test for the described feature/workflow19- `/gen-e2e-test <description> --project=<name>`: specify the Playwright project (default: inferred from feature area)20- `/gen-e2e-test <description> --analyze`: produce a test plan without generating code2122### Examples2324```shell25/gen-e2e-test "ConfigMap CRUD operations in admin perspective"26/gen-e2e-test "verify topology view shows deployments" --project=topology27/gen-e2e-test "developer user creates a project and deploys from git" --project=dev-console-developer28```2930## Workflow3132### Phase 1: Scope33341. Understand the feature/workflow to test from the user's description352. Identify the Playwright project and output directory (see `e2e-context.md` Project Structure)363. Identify admin vs developer persona374. Determine test isolation strategy: self-contained (A), shared resources (B), or API-created (C)385. Determine if tests can run in parallel or must be serial:39 - **Parallel**: tests are independent, each creates its own namespace, no shared mutable state40 - **Serial** (default): tests share a namespace, modify global settings, or depend on order416. Document each test's intent in plain language427. Produce a test plan:43 ```44 Test Plan: <feature>45 Project: <playwright-project>46 Output: e2e/tests/<project>/<name>.spec.ts47 Persona: admin | developer48 Isolation: Strategy A | B | C49 Execution: serial | parallel5051 Tests:52 1. <test name>: <intent>53 2. <test name>: <intent>5455 Page objects:56 - Reuse: <existing page objects>57 - Create: <new page objects needed>5859 Resources:60 - <namespace, deployment, configmap, etc.>61 ```6263**Stop here if `--analyze` was specified.** Ask the user to review and confirm before proceeding.6465### Phase 2: Discover66671. Search existing page objects: `find frontend/e2e/pages -name "*.ts"`682. Read relevant page objects to understand available methods and locators693. Read `frontend/e2e/fixtures/index.ts` to understand available fixtures704. Read `frontend/e2e/clients/kubernetes-client.ts` for available K8s API methods715. If the feature involves React components, read the component source to find existing `data-test` attributes726. If Playwright MCP is available:73 - Resize viewport to 1920x108074 - Navigate to target pages in the live UI75 - Snapshot accessibility tree to discover selectors and `data-test` attributes76 - Verify selectors with non-submitting interactions (click navigation elements, type in search fields)77 - Do not submit forms, create resources, or perform state-changing actions during discovery. Ask the user before login or credential entry7879 If MCP is unavailable or no cluster is reachable, log a warning: "Playwright MCP not available. Selectors based on React source only. Run `/debug-test` after deployment to verify." Proceed to Phase 3.8081### Phase 3: Implement82831. **Add `data-test` attributes** to React components if needed. When a component only has legacy test attributes (`data-test-id`, etc.), add `data-test` alongside the legacy attribute (see `e2e-context.md` Test Selectors)84852. **Create/extend page objects** if needed:86 - Follow the BasePage pattern from `e2e-context.md`87 - `private readonly` locator properties using `getByTestId()` or `locator()`88 - Getter methods to expose locators (`getX(): Locator`)89 - Action methods returning `Promise<void>`90 - Use `robustClick()` for clicks inside page objects91 - Do NOT add `waitFor()` before action methods. Playwright auto-waits92933. **Write the spec file:**94 - `import { test, expect } from '../../fixtures'` (adjust relative path based on test depth)95 - Tags are optional. Only add them if they enable filtering beyond the directory structure (see `e2e-context.md` Tags section)96 - Apply the chosen isolation strategy and execution mode97 - Use `test.step()` for multi-phase workflows within a single test98 - Track all created resources with `cleanup.track*()` or use `test.afterAll` for shared resources99 - Name tests by user intent, not implementation1001014. **Validate code** (run from `frontend/`):102 - `cd frontend && npx tsc --noEmit -p e2e/tsconfig.json`: zero type errors103 - `cd frontend && yarn eslint <generated-files>`: fix lint errors104105### Phase 4: Verify1061071. Run (from `frontend/`): `cd frontend && npx playwright test --project=<project> <spec-file> --retries=0`108 - For developer tests: `--project=<project>-developer`109 - Note: `e2e/.env` may set `WEB_CONSOLE_URL` to a remote cluster. If running against localhost, verify `.env` or override with `WEB_CONSOLE_URL=http://localhost:9000`1102. Debug failures using Playwright MCP if available (navigate → snapshot → console → network). Fix and re-run.1113. If a test still fails after 3 fix attempts, stop trying and ask the user if they want to run `/debug-test <spec-file>` for deeper MCP-assisted diagnosis.1124. Run 2 additional times to confirm stability1135. Verify no orphaned resources after test run1146. Output summary:115 ```116 Generation complete: e2e/tests/<project>/<name>.spec.ts117 Tests created: N118 Page objects created: [list]119 Page objects reused: [list]120 Files written: [list]121 Validation: passed122 ```123124## Rules125126- Always read `e2e-context.md` before writing any code127- Discover available fixtures and page objects before creating new ones128- Use Playwright MCP to verify selectors when available129- Follow the project's existing patterns. Don't invent new conventions130- Golden path first. Only add edge case tests when explicitly asked131- **DO NOT commit.** The user handles git operations