The playwright-cli provides an end-to-end workflow for authoring and maintaining Playwright tests using a Plan → Generate → Heal model.
Every action performed via the CLI (like click or fill) automatically generates the equivalent Playwright TypeScript code. This generated code is intended to be copied directly into your test files.
Core Workflow Components:
- Plan: Explore the application and produce a specification file (e.g.,
specs/<feature>.plan.md) describing what to test. - Generate: Convert a specification file into actual Playwright test files.
- Heal: Diagnose failing tests, fix the code, and reconcile the specification with the current state of the application.
To drive the interactive session, you must run npx playwright test --debug=cli in the background and then use playwright-cli attach <session-id> to connect.
# Start a session
playwright-cli open https://example.com/login
# Take a snapshot to see elements
playwright-cli snapshot
# Output shows: e1 [textbox "Email"], e2 [textbox "Password"], e3 [button "Sign In"]
# Fill form fields - generates code automatically
playwright-cli fill e1 "user@example.com"
# Ran Playwright code:
# await page.getByRole('textbox', { name: 'Email' }).fill('user@example.com');
playwright-cli click e3
# Ran Playwright code:
# await page.getByRole('button', { name: 'Sign In' }).click();