| name | playwright-cli |
| description | Automate browser interactions using Playwright CLI tools. Covers both standard CLI (npx playwright) for test execution, codegen, debugging, reporting, and the new @playwright/cli for AI-agent-friendly persistent browser sessions.
|
| triggers | ["playwright","codegen","browser test","e2e test","record test","login automation","headed mode","trace viewer","html report","playwright cli","test generation"] |
Playwright CLI Skill
Use this skill when the user asks to run Playwright tests, record tests with codegen, debug tests, view reports/traces, manage browsers, or automate browser interactions via the CLI.
Standard CLI Commands (npx playwright)
Run Tests
npx playwright test
npx playwright test --headed
npx playwright test --debug
npx playwright test --ui
npx playwright test --grep "login"
npx playwright test --grep-invert "slow"
npx playwright test --project=chromium
npx playwright test --workers=4
npx playwright test --retries=2
npx playwright test --trace on
npx playwright test --shard=1/3
npx playwright test --list
npx playwright test --forbid-only
npx playwright test --update-snapshots
npx playwright test tests/login.spec.js
Record Tests (Codegen)
npx playwright codegen [url]
npx playwright codegen --output tests/my.spec.js
npx playwright codegen --target python
npx playwright codegen --target java
npx playwright codegen --target csharp
npx playwright codegen --device "iPhone 13"
npx playwright codegen --viewport-size "1280,720"
npx playwright codegen --color-scheme dark
npx playwright codegen --timezone "Asia/Kolkata"
npx playwright codegen --save-storage auth.json
npx playwright codegen --load-storage auth.json
npx playwright codegen --browser firefox
Reports & Debugging
npx playwright show-report
npx playwright show-trace trace.zip
npx playwright install
npx playwright install chromium
npx playwright install --with-deps
npx playwright clear-cache
npx playwright merge-reports
@playwright/cli (AI Agent CLI)
Setup
npm install -g @playwright/cli@latest
playwright-cli install
playwright-cli install --skills
Interactive Commands
playwright-cli open [url] -s=[session]
playwright-cli goto [url] -s=[session]
playwright-cli reload -s=[session]
playwright-cli close -s=[session]
playwright-cli snapshot -s=[session]
playwright-cli screenshot -s=[session]
playwright-cli pdf -s=[session]
playwright-cli eval "expression" -s=[s]
playwright-cli console -s=[session]
playwright-cli network -s=[session]
playwright-cli click [ref] -s=[session]
playwright-cli fill [ref] "text" -s=[s]
playwright-cli type [ref] "text" -s=[s]
playwright-cli press Enter -s=[session]
playwright-cli select [ref] "val" -s=[s]
playwright-cli check [ref] -s=[session]
playwright-cli uncheck [ref] -s=[session]
playwright-cli drag [src] [dst] -s=[s]
playwright-cli state-save file.json -s=[s]
playwright-cli state-load file.json -s=[s]
playwright-cli cookie-list -s=[session]
playwright-cli localstorage-list -s=[s]
playwright-cli tracing-start -s=[session]
playwright-cli tracing-stop -s=[session]
playwright-cli video-start -s=[session]
playwright-cli video-stop -s=[session]
playwright-cli list
playwright-cli close-all
Key Flags
-s=name : Named session (allows parallel sessions)
--persistent : Save browser profile to disk
--headed : Show visible browser window
Codegen Locator Priority
getByRole('button', { name: '...' }) - ARIA role-based (most resilient)
getByText('...') - Visible text content
getByTestId('...') - data-testid attribute
getByPlaceholder('...') - Input placeholder text
locator('css-selector') - CSS selector (last resort)
Common Patterns
Login Test
import { test, expect } from '@playwright/test';
test('login with valid credentials', async ({ page }) => {
await page.goto('https://app.example.com');
await page.getByPlaceholder('Email').fill('user@test.com');
await page.getByPlaceholder('Password').fill('password123');
await page.getByRole('button', { name: 'Sign in' }).click();
await expect(page).toHaveURL(/dashboard/);
});
CI/CD Pipeline
npx playwright install --with-deps
npx playwright test \
--reporter=json,html \
--workers=4 \
--retries=2 \
--trace=on-first-retry \
--forbid-only
Auth State Reuse
npx playwright codegen --save-storage auth.json https://app.example.com
npx playwright codegen --load-storage auth.json https://app.example.com/dashboard
MCP vs CLI Decision Guide
- Use Standard CLI for: CI/CD, test runs, codegen, reports, traces
- Use MCP Server for: AI agent needs live browser in context window
- Use @playwright/cli for: AI agents needing token efficiency (4.6x fewer tokens than MCP)