Playwright Setup
Overview
Use this skill to add a small, reliable Playwright test surface to a web app and wire it into CI.
Prefer one fast unit-style sanity test plus one browser E2E test before expanding coverage. Keep E2E tests focused on user-visible behavior and make CI provide any local mock env vars required for the app to boot.
Workflow
Inspect the repo. Read
package.json, app framework config, existing tests, existing CI workflows,.gitignore, and any env-dependent app startup code.Install Playwright. Add
@playwright/testas a dev dependency. Add npm scripts fortest,test:unit, andtest:e2e.Add separate configs. Use a unit config for tests that do not launch a browser. Use an E2E config with a local web server, localhost base URL, browser project, retries, and CI-safe workers.
Add sample tests. Add one unit-style test for a stable helper or pure function. Add one E2E test for the first screen or signed-out flow. Avoid real third-party auth or payment calls in CI E2E tests unless explicitly required.
Update ignored artifacts. Ignore
/playwright-reportand/test-results. Add those paths to ESLint global ignores if ESLint walks ignored directories.Wire CI. Run typecheck, lint, build, unit tests, install Playwright browsers, and E2E tests. Use
npx playwright install --with-deps chromiumin Ubuntu CI. Scope mock env vars to the E2E step when the app needs local auth/database config just to boot.Verify. Run
npm run typecheck,npm run lint,npm run build,npm run test:unit,npm run test:e2e, andnpm test.
GitHub Actions Rules
- Run CI on pull requests to the target branch.
- If the same workflow also releases, only release on pushes to the release branch.
- Prefer
pull_requestdefault events unless customtypesare needed. GitHub defaults toopened,synchronize, andreopened. - Put mock test env vars on the E2E test step, not global workflow scope.
- Do not hardcode real secrets in workflow files.
Troubleshooting
- Browser missing in CI: add
npx playwright install --with-deps chromiumbefore E2E tests. - App cannot start in CI: add local mock env vars required for startup to the E2E step.
- AuthKit redirect URI missing: set
NEXT_PUBLIC_WORKOS_REDIRECT_URI=http://localhost:3000/callbackon the E2E step. - AuthKit cookie password missing: set a 32+ character mock
WORKOS_COOKIE_PASSWORDon the E2E step. - Tests pass locally but fail in CI: check workers, base URL, web server port, retries, and missing env vars.
- ESLint errors on
test-results: addtest-results/**andplaywright-report/**to ESLint global ignores.
References
Read references/setup.md for recommended configs, package scripts, sample tests, CI snippets, and mock env examples.