IKivan-kozenko -aqa
Try yourself as a QA tester
All topics·Intermediate·26 / 27

Coding agents

playwright-cli is a token-efficient browser automation CLI built for coding agents like Claude Code. Instead of loading full tool schemas and accessibility trees into the model context, it exposes concise commands: open, click, type, screenshot, snapshot. Each command outputs minimal state.

What playwright-cli is and why it exists

Regular Playwright MCP exposes full browser state to the model — useful for deep exploration, but expensive in tokens. playwright-cli takes the opposite approach: short commands, minimal output, designed for agents that need to balance browser automation with large codebases and limited context windows.

Use playwright-cli when: the agent is working on a codebase and occasionally needs to check something in the browser. Use MCP when: the agent needs to explore page structure deeply and reason over it iteratively.

bash
# Встановити глобально
npm install -g @playwright/cli@latest

# Або через npx (без глобального встановлення)
npx playwright-cli --help

# Встановити skills для кращого контексту в агентах
playwright-cli install --skills

Core commands

The most common commands I use when asking an agent to test something in the browser:

bash
# Відкрити сторінку
playwright-cli open https://localhost:3000/orders

# Взаємодіяти
playwright-cli click "role=button[name=Create order]"
playwright-cli fill "label=Item name" "Laptop Stand"
playwright-cli press Enter

# Перевірити стан
playwright-cli snapshot         # структура сторінки (для агента)
playwright-cli screenshot       # візуальний знімок

# Навігація
playwright-cli goto /orders/42
playwright-cli go-back
bash
# snapshot повертає refs для кожного елементу
playwright-cli snapshot
# → [e15] Create order button
# → [e22] Item name input

# Використати ref для точного кліку
playwright-cli click e15
playwright-cli fill e22 "Laptop Stand"

Sessions — keep browser state between commands

By default, CLI keeps browser state in memory — cookies and localStorage persist between calls within a session but reset when the browser closes. Named sessions let you run multiple browsers for different contexts.

bash
# Іменована сесія — для ізоляції різних проєктів
playwright-cli -s=crm open https://localhost:3000 --persistent
playwright-cli -s=admin open https://localhost:3000/admin

# Переглянути активні сесії
playwright-cli list

# Передати сесію агенту через env
PLAYWRIGHT_CLI_SESSION=crm claude .

Monitoring all sessions

playwright-cli show opens a visual dashboard in the browser where you can see all running sessions with live screencasts. You can click into any session to take over mouse and keyboard control.

bash
# Відкрити панель моніторингу
playwright-cli show

How to ask a coding agent to use playwright-cli

The simplest way: just describe what to test and mention playwright-cli. The agent will discover commands via playwright-cli --help or use installed skills.

text
Протестуй flow створення замовлення на http://localhost:3000
використовуючи playwright-cli.

1. Відкрий /orders/new
2. Заповни форму: Item = "Laptop Stand", Quantity = 2
3. Підтвердь замовлення
4. Перевір що з'явився banner "Order created"
5. Зроби screenshot фінального стану