|
| 1 | +# Running Playwright E2E (headed and headless) |
| 2 | + |
| 3 | +This document explains how to run Playwright tests using a real browser (headed) on Linux machines and in the project's Docker E2E environment. |
| 4 | + |
| 5 | +## Key points |
| 6 | +- Playwright's interactive Test UI (--ui) requires an X server (a display). On headless CI or servers, use Xvfb. |
| 7 | +- Prefer the project's E2E Docker image for integration-like runs; use the local `--ui` flow for manual debugging. |
| 8 | + |
| 9 | +## Quick commands (local Linux) |
| 10 | +- Headless (recommended for CI / fast runs): |
| 11 | + ```bash |
| 12 | + npm run e2e |
| 13 | + ``` |
| 14 | + |
| 15 | +- Headed UI on a headless machine (auto-starts Xvfb): |
| 16 | + ```bash |
| 17 | + npm run e2e:ui:headless-server |
| 18 | + # or, if you prefer manual control: |
| 19 | + xvfb-run --auto-servernum --server-args='-screen 0 1280x720x24' npx playwright test --ui |
| 20 | + ``` |
| 21 | + |
| 22 | +- Headed UI on a workstation with an X server already running: |
| 23 | + ```bash |
| 24 | + npx playwright test --ui |
| 25 | + ``` |
| 26 | + |
| 27 | +## Using the project's E2E Docker image (recommended for parity with CI) |
| 28 | +1. Rebuild/start the E2E container (this sets up the full test environment): |
| 29 | + ```bash |
| 30 | + .github/skills/scripts/skill-runner.sh docker-rebuild-e2e |
| 31 | + ``` |
| 32 | +2. Run the UI against the container (you still need an X server on your host): |
| 33 | + ```bash |
| 34 | + PLAYWRIGHT_BASE_URL=http://localhost:8080 npm run e2e:ui:headless-server |
| 35 | + ``` |
| 36 | + |
| 37 | +## CI guidance |
| 38 | +- Do not run Playwright `--ui` in CI. Use headless runs or the E2E Docker image and collect traces/videos for failures. |
| 39 | +- For coverage, use the provided skill: `.github/skills/scripts/skill-runner.sh test-e2e-playwright-coverage` |
| 40 | + |
| 41 | +## Troubleshooting |
| 42 | +- Playwright error: "Looks like you launched a headed browser without having a XServer running." → run `npm run e2e:ui:headless-server` or install Xvfb. |
| 43 | +- If `npm run e2e:ui:headless-server` fails with an exit code like `148`: |
| 44 | + - Inspect Xvfb logs: `tail -n 200 /tmp/xvfb.playwright.log` |
| 45 | + - Ensure no permission issues on `/tmp/.X11-unix`: `ls -la /tmp/.X11-unix` |
| 46 | + - Try starting Xvfb manually: `Xvfb :99 -screen 0 1280x720x24 &` then `export DISPLAY=:99` and re-run `npx playwright test --ui`. |
| 47 | +- If running inside Docker, prefer the skill-runner which provisions the required services; the UI still needs host X (or use VNC). |
| 48 | + |
| 49 | +## Developer notes (what we changed) |
| 50 | +- Added `scripts/run-e2e-ui.sh` — wrapper that auto-starts Xvfb when DISPLAY is unset. |
| 51 | +- Added `npm run e2e:ui:headless-server` to run the Playwright UI on headless machines. |
| 52 | +- Playwright config now auto-starts Xvfb when `--ui` is requested locally and prints an actionable error if Xvfb is not available. |
| 53 | + |
| 54 | +## Security & hygiene |
| 55 | +- Playwright auth artifacts are ignored by git (`playwright/.auth/`). Do not commit credentials. |
| 56 | + |
| 57 | +--- |
| 58 | +If you'd like, I can open a PR with these changes (scripts + config + docs) and add a short CI note to `.github/` workflows. |
0 commit comments