Skip to main content

๐Ÿงฉ Module 9 โ€“ Reports & Debugging

Playwright is built for fast debugging. From rich HTML reports to trace viewer, screenshots, videos, and the Playwright Inspector โ€” you have everything you need to diagnose failures quickly.


โœ… 1) Generate & View HTML Reportโ€‹

After running tests, Playwright generates an HTML report.

# Run tests (with traces enabled for best debugging)
npx playwright test --project=chromium --trace=on

# Open the HTML report
npx playwright show-report

โœ… The HTML report shows:

  • โœ… Passed / failed / flaky tests
  • โœ… Duration per test
  • โœ… Direct links to traces, screenshots, videos

โœ… 2) Trace Viewer (Most Powerful Debugging Tool)โ€‹

Traces capture everything: DOM snapshots, network requests, console logs, actions, and more.

  • From HTML report: Click any test โ†’ click Trace
  • From CLI: Open a specific trace file:
    npx playwright show-trace test-results/<test-folder>/trace.zip

๐ŸŽฏ In Trace Viewer you can:

  • โช Step through each action (click/fill/navigation)
  • ๐Ÿ” Inspect DOM snapshots at each step
  • ๐ŸŒ Review network requests/responses
  • ๐Ÿงพ Check console logs

โœ… 3) Screenshots, Videos & Error Contextโ€‹

Configured in playwright.config.js:

use: {
screenshot: 'only-on-failure',
trace: 'on-first-retry',
video: 'on-first-retry',
}

๐Ÿ“ธ Screenshots: Saved on failures
๐ŸŽฅ Videos: Recorded on first retry (great for flaky tests)
๐Ÿงพ Error Context: Playwright writes error-context.md files with extra info


โœ… 4) Debug Mode (--debug)โ€‹

Step through a test line-by-line with the Playwright Inspector:

npx playwright test tests/login.spec.js --project=chromium --debug
  • ๐Ÿงญ Use the step button to execute one action at a time
  • ๐Ÿ”Ž Inspect locators live in the browser
  • โœ๏ธ Edit the test on the fly and rerun

โœ… 5) PWDEBUG=1 (Terminal Debugging)โ€‹

An alternative debug mode that prints detailed logs in the terminal:

PWDEBUG=1 npx playwright test tests/login.spec.js --project=chromium

Useful when the Inspector UI doesn't attach (permissions, headless quirks, CI).


โœ… 6) Common Debugging Scenarios & Fixesโ€‹

ProblemLikely CauseFix
Test times out on click() / fill()Locator too strict / element not readyUse getByRole() / getByLabel(), add waitFor() / waitForLoadState()
toBeVisible() failsElement is in DOM but hidden / off-screenUse scrollIntoViewIfNeeded() or verify visibility condition
Flaky test (intermittent)Race condition / animations / networkAdd waitForURL(), waitForResponse(), increase timeouts carefully
--debug shows "about:blank"Browser/DevTools connection issuenpx playwright install chromium, close all browser windows, try PWDEBUG=1
Port conflict for report (EADDRINUSE)Another process using report portlsof -i :9323 โ†’ kill -9 <PID> (macOS/Linux) or netstat / taskkill (Windows)

โœ… 7) Best Practices for Debuggingโ€‹

  • โœ… Always enable trace on failure: trace: 'on-first-retry'
  • โœ… Run locally with --headed first: npx playwright test --headed
  • โœ… Use data-testid in your app for the most stable locators
  • โœ… Keep tests small & focused: One behavior per test = easier to isolate failures
  • โœ… Write meaningful test names: test('Login fails with invalid password') is easier to debug than test('test 3')

๐ŸŽฏ Summary: Playwright gives you a complete debugging toolkit โ€” HTML report + trace viewer + screenshots/videos + Inspector + logs โ€” so you can fix failures in minutes, not hours.


๐Ÿš€ Keep Goingโ€‹

Apply what you learned in this module: