| name | playwright-debugging |
| description | Guide for writing, running, and debugging Playwright E2E tests. |
Playwright Debugging
Guide for writing, running, and debugging Playwright E2E tests.
Core Principles
- Failing tests indicate real bugs. The tests interact with the real app. If a test fails, the app is broken — investigate the app, not the test.
- Debug locally first. Read error messages, check screenshots/video, check browser console logs. Most issues are obvious once you look at the artifacts.
- Fix the app, not the test. If the test exposes a real bug, fix the production code. Only change the test if the test itself is wrong (wrong selector, wrong expectation, race condition in the test).
- Tests must be independent. Each test should manage its own state. Never depend on state from another test.
Debugging Approach
When a test fails, follow this sequence:
1. Read the Error Message
Playwright error messages are descriptive. They tell you exactly what selector failed and why. Start there.
2. Check Page Structure Output
Failed tests generate test-results/<test-name>/error-context.md with a YAML representation of the page structure:
- heading "Dashboard" [level=1] [ref=e10]
- paragraph [ref=e11]: Enter your section code to
[] []
[] []