Files
computer-playbook/docs/contributing/code/tests/playwright.md
T
kevinveenbirkenbachandClaude Sonnet 4.6 10b889e76f refactor(deploy): single deploy-fresh-purged-apps target with FULL_CYCLE flag
Consolidates into one target. FULL_CYCLE defaults to false (deploy only);
set FULL_CYCLE=true for deploy + update pass. Extracts run_pass function
in fresh-purged-app.sh to eliminate duplicated init+deploy logic. Updates
makefile.md, playwright.md, iteration.md, and environment.sh with correct
FULL_CYCLE usage.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 17:14:44 +02:00

3.9 KiB

Playwright Tests

This page is the SPOT for Playwright end-to-end test requirements, runner integration, and file contracts. For implementation guidance when writing or updating role-local files, see Agent playwright.spec.js and Agent playwright.env.j2.

Framework

  • Playwright runs inside Docker via the shared test-e2e-playwright role.
  • There is no standalone make target for Playwright. Tests run as part of local deploy flows (e.g. FULL_CYCLE=true APPS=web-app-matomo make deploy-fresh-purged-apps).

When to Write

  • You MUST provide Playwright tests for every web-* role.
  • You MUST update the Playwright suite when you add or change role-local javascript.js or style.css.

Role-Local Files

Every Playwright-enabled role MUST provide exactly these two files:

File Purpose
files/playwright.spec.js Test scenarios executed by the Playwright runner
templates/playwright.env.j2 Rendered .env passed to the Playwright container

package.json and playwright.config.js MUST remain centralized in roles/test-e2e-playwright/files/. You MUST NOT duplicate or override them per role.

Runner

The test-e2e-playwright role discovers Playwright-enabled roles through the presence of templates/playwright.env.j2. For each discovered role it:

  1. stages the test project
  2. renders .env from playwright.env.j2
  3. copies files/playwright.spec.js into the project as tests/playwright.spec.js
  4. injects the shared package.json and playwright.config.js
  5. waits until the app is reachable
  6. runs Playwright in Docker

File Requirements

See the dedicated SPOT pages for authoring rules:

Recording Tests

Playwright Codegen (built-in)

Playwright ships a built-in code recorder:

npx playwright codegen https://<app-url>

This opens the Playwright Inspector alongside a browser. Every interaction is recorded and emitted as a runnable spec. Use the output as a starting draft and clean it up according to the authoring rules in playwright.spec.js.

playwright-recorder (Docker-based)

For infrastructure-heavy setups where Playwright should not live in the main repository, use playwright-recorder. It wraps Playwright codegen in Docker with X11/XWayland forwarding and an ephemeral workspace so no state leaks between recordings.

Requirements: Docker, X11 or XWayland, xhost

# Install
make install

# Record a flow starting at a specific URL
make codegen
# or directly:
./scripts/codegen.sh https://<app-url>/login

# Replay a recorded spec headlessly
make replay
# or directly:
./scripts/replay.sh recordings/login.spec.ts

Generated files are persisted in the local workspace (git-ignored). Copy the relevant parts into files/playwright.spec.js and adapt them.

Development Procedure

  1. Analyze the deployed application in a running local stack.
  2. Build hypotheses about the expected user flows before writing tests.
  3. Optionally record a draft with Playwright codegen or playwright-recorder.
  4. Write or update files/playwright.spec.js and templates/playwright.env.j2.
  5. Run the relevant deploy flow (e.g. FULL_CYCLE=true APPS=<role> make deploy-fresh-purged-apps).
  6. Run make trust-ca and open the app in your browser to confirm the flow manually.
  7. Inspect the browser console for errors when the flow depends on injected JavaScript.
  8. Verify the suite finishes in a logged-out state.