| name | playwright-cli |
| description | Use Playwright via npx to run browser tests, take screenshots, generate code, and automate browser interactions. Use this instead of the Playwright MCP server. |
Playwright CLI (npx playwright)
Browser automation and testing framework. Run tests, capture screenshots, generate test code, and automate web interactions.
Setup
npx playwright install
npx playwright install chromium
npx playwright install --with-deps
Common Commands
Running Tests
npx playwright test
npx playwright test tests/login.spec.ts
npx playwright test --grep "login"
npx playwright test --project=chromium
npx playwright test --headed
npx playwright test --debug
npx playwright test --reporter=json
Code Generation
npx playwright codegen https://example.com
npx playwright codegen --target javascript
Screenshots and PDFs
npx playwright screenshot https://example.com screenshot.png
npx playwright screenshot --full-page https://example.com full.png
npx playwright pdf https://example.com page.pdf
Trace Viewer
npx playwright test --trace on
npx playwright show-trace trace.zip
Test Report
npx playwright show-report
Agent Best Practices
- Use
--reporter=json for machine-parseable test results
- Use
npx playwright codegen to generate test scaffolding, then refine
- Always install browsers first with
npx playwright install
- Use
--project=chromium to run on a single browser for speed
- Screenshots are useful for visual verification of page state
- Use
--trace on when debugging flaky tests
Example Workflows
Take a screenshot of a page
npx playwright screenshot --full-page https://example.com /tmp/screenshot.png
Run tests and get JSON results
npx playwright test --reporter=json 2>/dev/null | jq '.suites[].specs[] | {title, ok}'