</>

Playwright Cheat Sheet

Practical Playwright cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.

playwright e2e-testing browser-testing qa automation

Playwright cheat sheet with real commands and snippets for setup, core workflows, debugging, and production-safe automation patterns. If you are working across tools, pair this with the Cypress Cheat Sheet and GitHub Actions Cheat Sheet.

Setup and Installation

Goal: Verify installation and CLI metadata

# Resolve command path from current shell
command -v playwright

# Print installed version to confirm runtime
playwright --version

# Read top-level help before using subcommands
playwright --help

Goal: Install or upgrade the tool on a workstation

# Install Playwright test runner
npm install -D @playwright/test

# Install required browser binaries
npx playwright install --with-deps

Goal: Run day-to-day commands

# Install browsers and dependencies
npx playwright install

# Run all Playwright tests
npx playwright test

# Run tests in headed debug mode
npx playwright test --headed --debug

# Open latest HTML report
npx playwright show-report

Core Workflows

Goal: Capture command help for quick offline lookup

# Create docs folder for generated command references
mkdir -p docs/cli

# Write help output to a timestamped file
playwright --help > docs/cli/playwright-help.txt

# Search help output for a keyword
rg "config|auth|deploy" docs/cli/playwright-help.txt

Goal: Wrap repetitive commands in a script

# Create scripts directory for local automation
mkdir -p scripts

# Write repeatable health-check script
cat > scripts/check-playwright.sh <<'SH'
#!/usr/bin/env bash
set -euo pipefail
playwright --version
playwright --help >/dev/null
SH

# Make script executable and run it
chmod +x scripts/check-playwright.sh && ./scripts/check-playwright.sh

Configuration and Environment

Goal: Pin environment variables for predictable runs

# Define environment profile for local commands
export PLAYWRIGHT_PROFILE=dev

# Persist profile in local shell configuration
echo 'export PLAYWRIGHT_PROFILE=dev' >> ~/.zshrc

# Reload shell profile changes
source ~/.zshrc

Automation and CI

Goal: Add tool checks to CI pipeline

# Run lint/test/build in strict mode
set -euo pipefail

# Verify CLI exists before invoking workflow
command -v playwright

# Exit quickly if command is unavailable
playwright --version

Debugging and Troubleshooting

Goal: Collect diagnostics when commands fail

# Capture command output and exit code
playwright --help > /tmp/playwright-debug.log 2>&1; echo $?

# Inspect captured diagnostics
tail -n 80 /tmp/playwright-debug.log

# Check current shell PATH entries
echo $PATH | tr ':' '\n'

Common Gotchas

  • Pin Playwright versions in CI so local and pipeline behavior match.
  • Check tool authentication context before running write or deploy commands.
  • Prefer non-interactive flags in scripts to avoid stalled jobs.
  • Capture stderr logs in CI artifacts for faster incident triage.
  • Keep secrets in environment variables, not committed scripts.

Related Cheat Sheets