Playwright

Screenshots, PDFs, and Visual Evidence

Thirdy Gayares
12 min read

🎯 What You Will Learn

Capture pages and elements, choose useful viewport sizes, export PDFs, and organize browser evidence for debugging.

  • Capture viewport and element screenshots
  • Set repeatable viewport dimensions
  • Export a browser page to PDF
  • Organize evidence so another developer can reproduce the state
Prerequisites: A Playwright CLI session and a project directory where output/playwright can be created.

Capture Evidence with a Question

A screenshot is useful when it answers a specific question: what was visible, which control overlapped, whether the mobile menu opened, or what the browser showed before failure.

Prepare an Artifact Folder

Run the workflow from a dedicated output folder so snapshots and captures stay together.

Terminal
mkdir -p output/playwright/visual-evidence
cd output/playwright/visual-evidence

"$PWCLI" -s=visual open https://playwright.dev --headed

Set a Repeatable Viewport

Resize before capturing. A known viewport makes side-by-side comparisons more meaningful.

Terminal
"$PWCLI" -s=visual resize 1280 720
"$PWCLI" -s=visual snapshot

Capture the Visible Viewport

The screenshot command without a target captures the current viewport and reports the saved path.

Terminal
"$PWCLI" -s=visual screenshot
Screenshot saved to .playwright-cli/page-<timestamp>.png

Capture One Element

Snapshot first, identify the current element ref, then pass it to screenshot. This removes unrelated page chrome from the evidence.

Terminal
"$PWCLI" -s=visual snapshot
"$PWCLI" -s=visual screenshot eARTICLE

Capture Desktop and Mobile States

Resize, let the layout settle, snapshot, and capture each breakpoint. Label the resulting files in your issue or test report.

Terminal
"$PWCLI" -s=visual resize 390 844
"$PWCLI" -s=visual snapshot
"$PWCLI" -s=visual screenshot

"$PWCLI" -s=visual resize 1440 900
"$PWCLI" -s=visual snapshot
"$PWCLI" -s=visual screenshot

Export the Page as PDF

PDF export is useful for printable documentation and reviewing long pages outside the browser. The CLI saves the generated document and returns its path.

Terminal
"$PWCLI" -s=visual pdf

Package Evidence for Another Developer

A capture without context is easy to misread. Pair it with the URL, viewport, exact action, expected result, actual result, console output, and trace when applicable.

IncludeExample
URLThe exact page and query string
Viewport390 × 844
ActionOpen menu, choose Account
ExpectedAccount panel is visible
ActualPanel is hidden behind the header

Visual regression: For automated pixel comparisons, use Playwright Test screenshot assertions rather than manually comparing CLI screenshots.

Recap

  • Choose a specific question before capturing evidence.
  • Record the viewport and active URL.
  • Use element screenshots to isolate the subject.
  • Pair images and PDFs with reproduction context.

Checkpoint: You have completed the workflow and have a repeatable reference for your next Playwright project.

Official Resources

About the Author

TG

Thirdy Gayares

Passionate developer creating custom solutions for everyone. I specialize in building user-friendly tools that solve real-world problems while maintaining the highest standards of security and privacy.