playwright-repl 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +377 -0
- package/RELEASES.md +70 -0
- package/bin/daemon-launcher.cjs +13 -0
- package/bin/playwright-repl.mjs +79 -0
- package/examples/01-add-todos.pw +14 -0
- package/examples/02-complete-and-filter.pw +21 -0
- package/examples/03-record-session.pw +13 -0
- package/examples/04-replay-session.pw +17 -0
- package/examples/05-ci-pipe.pw +14 -0
- package/examples/06-edit-todo.pw +11 -0
- package/package.json +52 -0
- package/src/colors.mjs +17 -0
- package/src/connection.mjs +119 -0
- package/src/index.mjs +15 -0
- package/src/parser.mjs +141 -0
- package/src/recorder.mjs +241 -0
- package/src/repl.mjs +582 -0
- package/src/resolve.mjs +82 -0
- package/src/workspace.mjs +104 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Steve Zhang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
# playwright-repl
|
|
2
|
+
|
|
3
|
+
Interactive REPL for Playwright browser automation — keyword-driven testing from your terminal.
|
|
4
|
+
|
|
5
|
+
Inspired by [playwright-cli](https://github.com/anthropics/playwright-cli), reusing its command vocabulary and Playwright MCP daemon. Where playwright-cli is designed for AI agents (one command per process), playwright-repl is designed for **humans** — a persistent session with recording, replay, and instant feedback.
|
|
6
|
+
|
|
7
|
+
## Why?
|
|
8
|
+
|
|
9
|
+
The `playwright-cli` tool spawns a new Node.js process **per command** — connecting to the daemon, sending one message, and exiting. That's ~50–100ms overhead each time.
|
|
10
|
+
|
|
11
|
+
**playwright-repl** keeps a persistent socket connection open. Type a command, see the result instantly. Record your session, replay it later — no code, no tokens, no setup.
|
|
12
|
+
|
|
13
|
+
Key features beyond playwright-cli:
|
|
14
|
+
- **Text locators** — use `click "Submit"` or `fill "Email" "test@example.com"` instead of element refs. Auto-resolves via getByText, getByLabel, getByPlaceholder, and getByRole with fallback chains
|
|
15
|
+
- **Element refs** — also supports ref-based commands (`click e5`, `fill e7 "hello"`) from `snapshot` output
|
|
16
|
+
- **Assertions** — `verify-text`, `verify-element`, `verify-value`, `verify-list` for inline validation
|
|
17
|
+
- **Record & replay** — capture sessions as `.pw` files and replay them headlessly or step-by-step
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
pw> goto https://demo.playwright.dev/todomvc/
|
|
21
|
+
pw> fill "What needs to be done?" "Buy groceries"
|
|
22
|
+
pw> press Enter
|
|
23
|
+
pw> fill "What needs to be done?" "Write tests"
|
|
24
|
+
pw> press Enter
|
|
25
|
+
pw> check "Buy groceries"
|
|
26
|
+
pw> verify-text "1 item left"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Record it, replay it later:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pw> .record smoke-test
|
|
33
|
+
⏺ Recording to smoke-test.pw
|
|
34
|
+
|
|
35
|
+
pw> goto https://demo.playwright.dev/todomvc/
|
|
36
|
+
pw> fill "What needs to be done?" "Buy groceries"
|
|
37
|
+
pw> press Enter
|
|
38
|
+
pw> verify-text "1 item left"
|
|
39
|
+
pw> .save
|
|
40
|
+
✓ Saved 4 commands to smoke-test.pw
|
|
41
|
+
|
|
42
|
+
# Replay any time
|
|
43
|
+
$ playwright-repl --replay smoke-test.pw
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Install
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Prerequisites: Node.js >= 18 and Playwright
|
|
50
|
+
npm install -g playwright@latest
|
|
51
|
+
|
|
52
|
+
# Install playwright-repl
|
|
53
|
+
npm install -g playwright-repl
|
|
54
|
+
|
|
55
|
+
# Or from source
|
|
56
|
+
git clone https://github.com/stevez/playwright-repl.git
|
|
57
|
+
cd playwright-repl && npm install && npm link
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Quick Start
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# Start the REPL (launches browser automatically)
|
|
64
|
+
playwright-repl
|
|
65
|
+
|
|
66
|
+
# With a visible browser
|
|
67
|
+
playwright-repl --headed
|
|
68
|
+
|
|
69
|
+
# With a specific browser
|
|
70
|
+
playwright-repl --headed --browser firefox
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Once inside the REPL, use either **text locators** or **element refs**:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
pw> goto https://demo.playwright.dev/todomvc/
|
|
77
|
+
|
|
78
|
+
# Text locators — no snapshot needed
|
|
79
|
+
pw> fill "What needs to be done?" "Buy groceries"
|
|
80
|
+
pw> press Enter
|
|
81
|
+
pw> check "Buy groceries"
|
|
82
|
+
pw> verify-text "0 items left"
|
|
83
|
+
|
|
84
|
+
# Or use element refs from snapshot
|
|
85
|
+
pw> snapshot
|
|
86
|
+
- textbox "What needs to be done?" [ref=e8]
|
|
87
|
+
- listitem "Buy groceries" [ref=e21]
|
|
88
|
+
|
|
89
|
+
pw> click e21 # click by ref
|
|
90
|
+
pw> screenshot # take a screenshot
|
|
91
|
+
pw> close # close browser
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Usage
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Interactive REPL
|
|
98
|
+
playwright-repl [options]
|
|
99
|
+
|
|
100
|
+
# Replay a recorded session
|
|
101
|
+
playwright-repl --replay session.pw
|
|
102
|
+
|
|
103
|
+
# Step through replay (pause between commands)
|
|
104
|
+
playwright-repl --replay session.pw --step
|
|
105
|
+
|
|
106
|
+
# Start REPL with recording enabled
|
|
107
|
+
playwright-repl --record my-test.pw
|
|
108
|
+
|
|
109
|
+
# Pipe commands
|
|
110
|
+
echo -e "goto https://example.com\nsnapshot" | playwright-repl
|
|
111
|
+
|
|
112
|
+
# Named sessions
|
|
113
|
+
playwright-repl --session checkout-flow --headed
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### CLI Options
|
|
117
|
+
|
|
118
|
+
| Option | Description |
|
|
119
|
+
|--------|-------------|
|
|
120
|
+
| `-s, --session <name>` | Session name (default: `"default"`) |
|
|
121
|
+
| `-b, --browser <type>` | Browser: `chrome`, `firefox`, `webkit`, `msedge` |
|
|
122
|
+
| `--headed` | Run browser in headed (visible) mode |
|
|
123
|
+
| `--persistent` | Use persistent browser profile |
|
|
124
|
+
| `--profile <dir>` | Persistent profile directory |
|
|
125
|
+
| `--config <file>` | Path to config file |
|
|
126
|
+
| `--replay <file>` | Replay a `.pw` session file |
|
|
127
|
+
| `--record <file>` | Start REPL with recording to file |
|
|
128
|
+
| `--step` | Pause between commands during replay |
|
|
129
|
+
| `-q, --silent` | Suppress banner and status messages |
|
|
130
|
+
| `-h, --help` | Show help |
|
|
131
|
+
|
|
132
|
+
## Commands
|
|
133
|
+
|
|
134
|
+
### Navigation
|
|
135
|
+
|
|
136
|
+
| Command | Alias | Description |
|
|
137
|
+
|---------|-------|-------------|
|
|
138
|
+
| `goto <url>` | `g` | Navigate to a URL |
|
|
139
|
+
| `open [url]` | `o` | Open browser (optionally navigate) |
|
|
140
|
+
| `go-back` | `back` | Go back in history |
|
|
141
|
+
| `go-forward` | `fwd` | Go forward in history |
|
|
142
|
+
| `reload` | `r` | Reload page |
|
|
143
|
+
|
|
144
|
+
### Interaction
|
|
145
|
+
|
|
146
|
+
| Command | Alias | Description |
|
|
147
|
+
|---------|-------|-------------|
|
|
148
|
+
| `click <ref>` | `c` | Click an element |
|
|
149
|
+
| `dblclick <ref>` | `dc` | Double-click an element |
|
|
150
|
+
| `fill <ref> <text>` | `f` | Fill a form field |
|
|
151
|
+
| `type <text>` | `t` | Type text key by key |
|
|
152
|
+
| `press <key>` | `p` | Press a keyboard key |
|
|
153
|
+
| `hover <ref>` | `h` | Hover over element |
|
|
154
|
+
| `select <ref> <value>` | `sel` | Select dropdown option |
|
|
155
|
+
| `check <ref>` | `chk` | Check a checkbox |
|
|
156
|
+
| `uncheck <ref>` | `unchk` | Uncheck a checkbox |
|
|
157
|
+
| `upload <ref> <file>` | — | Upload a file |
|
|
158
|
+
| `drag <from> <to>` | — | Drag and drop |
|
|
159
|
+
|
|
160
|
+
### Inspection
|
|
161
|
+
|
|
162
|
+
| Command | Alias | Description |
|
|
163
|
+
|---------|-------|-------------|
|
|
164
|
+
| `snapshot` | `s` | Accessibility tree with element refs |
|
|
165
|
+
| `screenshot` | `ss` | Take a screenshot |
|
|
166
|
+
| `eval <expr>` | `e` | Evaluate JavaScript |
|
|
167
|
+
| `console` | `con` | Browser console messages |
|
|
168
|
+
| `network` | `net` | Network requests log |
|
|
169
|
+
| `run-code <code>` | — | Run Playwright code directly |
|
|
170
|
+
|
|
171
|
+
### Assertions
|
|
172
|
+
|
|
173
|
+
| Command | Alias | Description |
|
|
174
|
+
|---------|-------|-------------|
|
|
175
|
+
| `verify-text <text>` | `vt` | Verify text is visible on page |
|
|
176
|
+
| `verify-element <role> <name>` | `ve` | Verify element exists by role and name |
|
|
177
|
+
| `verify-value <ref> <value>` | `vv` | Verify input/select/checkbox value |
|
|
178
|
+
| `verify-list <ref> <items>` | `vl` | Verify list contains expected items |
|
|
179
|
+
|
|
180
|
+
### Tabs
|
|
181
|
+
|
|
182
|
+
| Command | Alias | Description |
|
|
183
|
+
|---------|-------|-------------|
|
|
184
|
+
| `tab-list` | `tl` | List open tabs |
|
|
185
|
+
| `tab-new [url]` | `tn` | Open a new tab |
|
|
186
|
+
| `tab-close [index]` | `tc` | Close a tab |
|
|
187
|
+
| `tab-select <index>` | `ts` | Switch to a tab |
|
|
188
|
+
|
|
189
|
+
### Storage & Cookies
|
|
190
|
+
|
|
191
|
+
| Command | Description |
|
|
192
|
+
|---------|-------------|
|
|
193
|
+
| `state-save [file]` | Save auth state (cookies + storage) |
|
|
194
|
+
| `state-load <file>` | Load auth state |
|
|
195
|
+
| `cookie-list` | List all cookies |
|
|
196
|
+
| `cookie-get <name>` | Get a specific cookie |
|
|
197
|
+
| `cookie-set <name> <value>` | Set a cookie |
|
|
198
|
+
| `cookie-delete <name>` | Delete a cookie |
|
|
199
|
+
| `cookie-clear` | Clear all cookies |
|
|
200
|
+
| `localstorage-list` | List all localStorage |
|
|
201
|
+
| `localstorage-get <key>` | Get localStorage value |
|
|
202
|
+
| `localstorage-set <key> <value>` | Set localStorage value |
|
|
203
|
+
| `localstorage-delete <key>` | Delete localStorage key |
|
|
204
|
+
| `localstorage-clear` | Clear all localStorage |
|
|
205
|
+
| `sessionstorage-list` | List all sessionStorage |
|
|
206
|
+
| `sessionstorage-get <key>` | Get sessionStorage value |
|
|
207
|
+
| `sessionstorage-set <key> <value>` | Set sessionStorage value |
|
|
208
|
+
| `sessionstorage-delete <key>` | Delete sessionStorage key |
|
|
209
|
+
| `sessionstorage-clear` | Clear all sessionStorage |
|
|
210
|
+
|
|
211
|
+
### Network Routing
|
|
212
|
+
|
|
213
|
+
| Command | Description |
|
|
214
|
+
|---------|-------------|
|
|
215
|
+
| `route <pattern>` | Intercept network requests |
|
|
216
|
+
| `route-list` | List active routes |
|
|
217
|
+
| `unroute [pattern]` | Remove route(s) |
|
|
218
|
+
|
|
219
|
+
### Dialogs & Layout
|
|
220
|
+
|
|
221
|
+
| Command | Description |
|
|
222
|
+
|---------|-------------|
|
|
223
|
+
| `dialog-accept [text]` | Accept a browser dialog |
|
|
224
|
+
| `dialog-dismiss` | Dismiss a browser dialog |
|
|
225
|
+
| `resize <w> <h>` | Resize browser window |
|
|
226
|
+
| `pdf` | Save page as PDF |
|
|
227
|
+
|
|
228
|
+
### Session Management
|
|
229
|
+
|
|
230
|
+
| Command | Alias | Description |
|
|
231
|
+
|---------|-------|-------------|
|
|
232
|
+
| `list` | `ls` | List active sessions |
|
|
233
|
+
| `close` | `q` | Close the browser |
|
|
234
|
+
| `close-all` | — | Close all sessions |
|
|
235
|
+
| `kill-all` | — | Kill all daemon processes |
|
|
236
|
+
| `config-print` | — | Print daemon config |
|
|
237
|
+
| `install-browser` | — | Install browser binaries |
|
|
238
|
+
|
|
239
|
+
### REPL Meta-Commands
|
|
240
|
+
|
|
241
|
+
| Command | Description |
|
|
242
|
+
|---------|-------------|
|
|
243
|
+
| `.help` | Show available commands |
|
|
244
|
+
| `.aliases` | Show all command aliases |
|
|
245
|
+
| `.status` | Show connection status |
|
|
246
|
+
| `.reconnect` | Reconnect to daemon |
|
|
247
|
+
| `.record [file]` | Start recording commands |
|
|
248
|
+
| `.save` | Stop recording and save to file |
|
|
249
|
+
| `.pause` | Pause/resume recording |
|
|
250
|
+
| `.discard` | Discard current recording |
|
|
251
|
+
| `.replay <file>` | Replay a recorded session |
|
|
252
|
+
| `.exit` | Exit REPL (also Ctrl+D) |
|
|
253
|
+
|
|
254
|
+
## Session Recording & Replay
|
|
255
|
+
|
|
256
|
+
Record your browser interactions and replay them later — great for regression tests, onboarding demos, or sharing reproducible flows.
|
|
257
|
+
|
|
258
|
+
### Record
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
# From CLI
|
|
262
|
+
playwright-repl --record my-test.pw --headed
|
|
263
|
+
|
|
264
|
+
# Or inside the REPL
|
|
265
|
+
pw> .record my-test
|
|
266
|
+
⏺ Recording to my-test.pw
|
|
267
|
+
pw> goto https://demo.playwright.dev/todomvc/
|
|
268
|
+
pw> fill "What needs to be done?" "Buy groceries"
|
|
269
|
+
pw> press Enter
|
|
270
|
+
pw> verify-text "1 item left"
|
|
271
|
+
pw> .save
|
|
272
|
+
✓ Saved 4 commands to my-test.pw
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Replay
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
# Full speed
|
|
279
|
+
playwright-repl --replay my-test.pw
|
|
280
|
+
|
|
281
|
+
# Step-through (press Enter between commands)
|
|
282
|
+
playwright-repl --replay my-test.pw --step --headed
|
|
283
|
+
|
|
284
|
+
# Or inside the REPL
|
|
285
|
+
pw> .replay my-test.pw
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### File Format
|
|
289
|
+
|
|
290
|
+
`.pw` files are plain text — human-readable, diffable, version-controllable:
|
|
291
|
+
|
|
292
|
+
```
|
|
293
|
+
# CI smoke test — quick add-and-verify
|
|
294
|
+
# App: https://demo.playwright.dev/todomvc/
|
|
295
|
+
|
|
296
|
+
goto https://demo.playwright.dev/todomvc/
|
|
297
|
+
fill "What needs to be done?" "Buy groceries"
|
|
298
|
+
press Enter
|
|
299
|
+
verify-text "Buy groceries"
|
|
300
|
+
verify-text "1 item left"
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Recording Controls
|
|
304
|
+
|
|
305
|
+
| Command | Description |
|
|
306
|
+
|---------|-------------|
|
|
307
|
+
| `.record [file]` | Start recording |
|
|
308
|
+
| `.pause` | Pause recording (toggle) |
|
|
309
|
+
| `.save` | Stop and save to file |
|
|
310
|
+
| `.discard` | Discard without saving |
|
|
311
|
+
|
|
312
|
+
## Examples
|
|
313
|
+
|
|
314
|
+
All examples use the [TodoMVC demo](https://demo.playwright.dev/todomvc/) and can be run directly:
|
|
315
|
+
|
|
316
|
+
| File | Description |
|
|
317
|
+
|------|-------------|
|
|
318
|
+
| [01-add-todos.pw](examples/01-add-todos.pw) | Add todos and verify with assertions |
|
|
319
|
+
| [02-complete-and-filter.pw](examples/02-complete-and-filter.pw) | Complete todos, use filters |
|
|
320
|
+
| [03-record-session.pw](examples/03-record-session.pw) | Record a test session |
|
|
321
|
+
| [04-replay-session.pw](examples/04-replay-session.pw) | Replay with step-through |
|
|
322
|
+
| [05-ci-pipe.pw](examples/05-ci-pipe.pw) | CI smoke test |
|
|
323
|
+
| [06-edit-todo.pw](examples/06-edit-todo.pw) | Double-click to edit a todo |
|
|
324
|
+
|
|
325
|
+
Try one:
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
# Run an example with a visible browser
|
|
329
|
+
playwright-repl --replay examples/01-add-todos.pw --headed
|
|
330
|
+
|
|
331
|
+
# Step through an example interactively
|
|
332
|
+
playwright-repl --replay examples/04-replay-session.pw --step --headed
|
|
333
|
+
|
|
334
|
+
# Run as a CI smoke test (headless, silent)
|
|
335
|
+
playwright-repl --replay examples/05-ci-pipe.pw --silent
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## Architecture
|
|
339
|
+
|
|
340
|
+
```
|
|
341
|
+
┌──────────────┐ Unix Socket ┌──────────────────┐ CDP ┌─────────┐
|
|
342
|
+
│ playwright- │◄──── JSON/newline ───►│ Daemon Process │◄────────────►│ Browser │
|
|
343
|
+
│ repl │ │ (Playwright │ │(Chrome/ │
|
|
344
|
+
│ │ │ MCP backend) │ │ FF/WK) │
|
|
345
|
+
└──────────────┘ └──────────────────┘ └─────────┘
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
The REPL replaces only the **client half** of playwright-cli. The daemon, browser, and all tool handlers are unchanged — both CLI and REPL produce identical wire messages.
|
|
349
|
+
|
|
350
|
+
### How It Works
|
|
351
|
+
|
|
352
|
+
1. **Startup**: The REPL starts the Playwright daemon (if not already running) and connects via Unix socket / Windows named pipe
|
|
353
|
+
2. **Input**: User types a command like `click e5`
|
|
354
|
+
3. **Parse**: Alias resolution (`c` → `click`) + minimist parsing → `{ _: ["click", "e5"] }`
|
|
355
|
+
4. **Send**: JSON message over socket to the daemon
|
|
356
|
+
5. **Execute**: Daemon maps the command to a Playwright API call and executes it
|
|
357
|
+
6. **Result**: Response rendered in the terminal
|
|
358
|
+
|
|
359
|
+
### Socket Path
|
|
360
|
+
|
|
361
|
+
The daemon socket includes a hash of the workspace directory:
|
|
362
|
+
|
|
363
|
+
```
|
|
364
|
+
Linux/macOS: /tmp/playwright-cli/{hash}/{session}.sock
|
|
365
|
+
Windows: \\.\pipe\{hash}-{session}.sock
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
Both REPL and daemon hash the same `package.json` path, so they always find each other.
|
|
369
|
+
|
|
370
|
+
## Requirements
|
|
371
|
+
|
|
372
|
+
- **Node.js** >= 18
|
|
373
|
+
- **playwright** >= 1.59.0-alpha (includes `lib/mcp/terminal/` daemon)
|
|
374
|
+
|
|
375
|
+
## License
|
|
376
|
+
|
|
377
|
+
MIT
|
package/RELEASES.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Releases
|
|
2
|
+
|
|
3
|
+
## v0.1.0 — Initial Release
|
|
4
|
+
|
|
5
|
+
**2026-02-09**
|
|
6
|
+
|
|
7
|
+
First public release of playwright-repl — an interactive REPL for Playwright browser automation.
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
**Interactive REPL**
|
|
12
|
+
- Persistent socket connection to the Playwright daemon (zero overhead per command)
|
|
13
|
+
- 50+ browser commands with short aliases (`c` for click, `s` for snapshot, etc.)
|
|
14
|
+
- Tab completion for commands, aliases, and meta-commands
|
|
15
|
+
- Command history (persisted across sessions)
|
|
16
|
+
- Automatic daemon startup and connection management
|
|
17
|
+
- Auto-reconnect on daemon disconnect
|
|
18
|
+
|
|
19
|
+
**Session Recording & Replay**
|
|
20
|
+
- Record browser interactions to `.pw` files (plain text, one command per line)
|
|
21
|
+
- Replay recorded sessions at full speed or step-by-step
|
|
22
|
+
- Pause/resume recording mid-session
|
|
23
|
+
- Start recording from CLI (`--record`) or inside the REPL (`.record`)
|
|
24
|
+
|
|
25
|
+
**Assertions**
|
|
26
|
+
- `verify-text` — assert text is visible on the page
|
|
27
|
+
- `verify-element` — assert element exists by role and accessible name
|
|
28
|
+
- `verify-value` — assert input/select/checkbox value
|
|
29
|
+
- `verify-list` — assert list contains expected items
|
|
30
|
+
|
|
31
|
+
**Browser Commands**
|
|
32
|
+
- Navigation: `goto`, `go-back`, `go-forward`, `reload`
|
|
33
|
+
- Interaction: `click`, `dblclick`, `fill`, `type`, `press`, `hover`, `select`, `check`, `uncheck`, `upload`, `drag`
|
|
34
|
+
- Inspection: `snapshot`, `screenshot`, `eval`, `console`, `network`, `run-code`
|
|
35
|
+
- Tabs: `tab-list`, `tab-new`, `tab-close`, `tab-select`
|
|
36
|
+
- Storage: cookies, localStorage, sessionStorage (list/get/set/delete/clear)
|
|
37
|
+
- Auth state: `state-save`, `state-load`
|
|
38
|
+
- Network: `route`, `route-list`, `unroute`
|
|
39
|
+
- Dialogs: `dialog-accept`, `dialog-dismiss`
|
|
40
|
+
- Layout: `resize`, `pdf`
|
|
41
|
+
- Sessions: `list`, `close`, `close-all`, `kill-all`
|
|
42
|
+
|
|
43
|
+
**CLI Options**
|
|
44
|
+
- `--headed` — visible browser mode
|
|
45
|
+
- `--browser` — choose chrome, firefox, webkit, or msedge
|
|
46
|
+
- `--session` — named sessions for parallel workflows
|
|
47
|
+
- `--persistent` / `--profile` — persistent browser profiles
|
|
48
|
+
- `--replay` / `--step` — session replay from CLI
|
|
49
|
+
- `--record` — start with recording enabled
|
|
50
|
+
- `--silent` — quiet mode for scripting
|
|
51
|
+
|
|
52
|
+
**Cross-Platform**
|
|
53
|
+
- Linux, macOS, Windows
|
|
54
|
+
- Unix sockets (Linux/macOS) and named pipes (Windows)
|
|
55
|
+
|
|
56
|
+
### Technical Details
|
|
57
|
+
|
|
58
|
+
- Pure ESM JavaScript (no build step, no TypeScript)
|
|
59
|
+
- Connects to Playwright's MCP terminal daemon over Unix socket / named pipe
|
|
60
|
+
- Wire-compatible with `playwright-cli` — produces identical JSON messages
|
|
61
|
+
- Requires `playwright >= 1.59.0-alpha` (daemon code in `lib/mcp/terminal/`)
|
|
62
|
+
- 218 tests, 96% statement coverage
|
|
63
|
+
|
|
64
|
+
### Known Limitations
|
|
65
|
+
|
|
66
|
+
- Low-level keyboard commands (`keydown`, `keyup`) not yet mapped
|
|
67
|
+
- Low-level mouse commands (`mousemove`, `mousedown`, `mouseup`, `mousewheel`) not yet mapped
|
|
68
|
+
- Tracing (`tracing-start`, `tracing-stop`) not yet mapped
|
|
69
|
+
- Video recording (`video-start`, `video-stop`) not yet mapped
|
|
70
|
+
- Element refs (e.g., `e5`) are ephemeral — they change between snapshots
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Daemon launcher — replaces @playwright/cli entirely.
|
|
5
|
+
* Same pattern, pointing to our own package.json for the socket hash.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { program } = require('playwright/lib/mcp/terminal/program');
|
|
9
|
+
const packageLocation = require.resolve('../package.json');
|
|
10
|
+
program(packageLocation).catch(e => {
|
|
11
|
+
console.error(e.message);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* playwright-repl CLI entry point.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* playwright-repl [options]
|
|
8
|
+
* playwright-repl --replay session.pw
|
|
9
|
+
* playwright-repl --replay session.pw --step
|
|
10
|
+
* playwright-repl --record my-test.pw
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { minimist } from '../src/resolve.mjs';
|
|
14
|
+
import { startRepl } from '../src/repl.mjs';
|
|
15
|
+
|
|
16
|
+
const args = minimist(process.argv.slice(2), {
|
|
17
|
+
boolean: ['headed', 'persistent', 'extension', 'help', 'step', 'silent'],
|
|
18
|
+
string: ['session', 'browser', 'profile', 'config', 'replay', 'record'],
|
|
19
|
+
alias: { s: 'session', h: 'help', b: 'browser', q: 'silent' },
|
|
20
|
+
default: { session: 'default' },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (args.help) {
|
|
24
|
+
console.log(`
|
|
25
|
+
playwright-repl - Interactive REPL for Playwright browser automation
|
|
26
|
+
|
|
27
|
+
Usage:
|
|
28
|
+
playwright-repl [options]
|
|
29
|
+
|
|
30
|
+
Options:
|
|
31
|
+
-s, --session <name> Session name (default: "default")
|
|
32
|
+
-b, --browser <type> Browser: chrome, firefox, webkit, msedge
|
|
33
|
+
--headed Run browser in headed mode
|
|
34
|
+
--persistent Use persistent browser profile
|
|
35
|
+
--profile <dir> Persistent profile directory
|
|
36
|
+
--config <file> Path to config file
|
|
37
|
+
--replay <file> Replay a .pw session file
|
|
38
|
+
--record <file> Start REPL with recording to file
|
|
39
|
+
--step Pause between commands during replay
|
|
40
|
+
-q, --silent Suppress banner and status messages
|
|
41
|
+
-h, --help Show this help
|
|
42
|
+
|
|
43
|
+
REPL Meta-Commands:
|
|
44
|
+
.help Show available commands
|
|
45
|
+
.aliases Show command aliases
|
|
46
|
+
.status Show connection status
|
|
47
|
+
.reconnect Reconnect to daemon
|
|
48
|
+
.record [filename] Start recording commands
|
|
49
|
+
.save Stop recording and save to file
|
|
50
|
+
.pause Pause/resume recording
|
|
51
|
+
.discard Discard current recording
|
|
52
|
+
.replay <filename> Replay a recorded session
|
|
53
|
+
.exit / Ctrl+D Exit REPL
|
|
54
|
+
|
|
55
|
+
Examples:
|
|
56
|
+
playwright-repl # start REPL
|
|
57
|
+
playwright-repl --headed # start with visible browser
|
|
58
|
+
playwright-repl --replay login.pw # replay a session
|
|
59
|
+
playwright-repl --replay login.pw --step # step through replay
|
|
60
|
+
echo "open https://example.com" | playwright-repl # pipe commands
|
|
61
|
+
`);
|
|
62
|
+
process.exit(0);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
startRepl({
|
|
66
|
+
session: args.session,
|
|
67
|
+
headed: args.headed,
|
|
68
|
+
browser: args.browser,
|
|
69
|
+
persistent: args.persistent,
|
|
70
|
+
profile: args.profile,
|
|
71
|
+
config: args.config,
|
|
72
|
+
replay: args.replay,
|
|
73
|
+
record: args.record,
|
|
74
|
+
step: args.step,
|
|
75
|
+
silent: args.silent,
|
|
76
|
+
}).catch((err) => {
|
|
77
|
+
console.error(`Fatal: ${err.message}`);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Add todos and verify they appear
|
|
2
|
+
# App: https://demo.playwright.dev/todomvc/
|
|
3
|
+
|
|
4
|
+
goto https://demo.playwright.dev/todomvc/
|
|
5
|
+
fill "What needs to be done?" "Buy groceries"
|
|
6
|
+
press Enter
|
|
7
|
+
fill "What needs to be done?" "Write tests"
|
|
8
|
+
press Enter
|
|
9
|
+
fill "What needs to be done?" "Deploy to production"
|
|
10
|
+
press Enter
|
|
11
|
+
verify-text "Buy groceries"
|
|
12
|
+
verify-text "Write tests"
|
|
13
|
+
verify-text "Deploy to production"
|
|
14
|
+
verify-text "3 items left"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Complete a todo and use filters
|
|
2
|
+
# App: https://demo.playwright.dev/todomvc/
|
|
3
|
+
|
|
4
|
+
goto https://demo.playwright.dev/todomvc/
|
|
5
|
+
fill "What needs to be done?" "Buy groceries"
|
|
6
|
+
press Enter
|
|
7
|
+
fill "What needs to be done?" "Write tests"
|
|
8
|
+
press Enter
|
|
9
|
+
fill "What needs to be done?" "Deploy to production"
|
|
10
|
+
press Enter
|
|
11
|
+
check "Buy groceries"
|
|
12
|
+
verify-text "2 items left"
|
|
13
|
+
click "Active"
|
|
14
|
+
verify-text "Write tests"
|
|
15
|
+
verify-text "Deploy to production"
|
|
16
|
+
click "Completed"
|
|
17
|
+
verify-text "Buy groceries"
|
|
18
|
+
click "All"
|
|
19
|
+
click "Clear completed"
|
|
20
|
+
verify-text "Write tests"
|
|
21
|
+
verify-text "Deploy to production"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Record and save a smoke test
|
|
2
|
+
# App: https://demo.playwright.dev/todomvc/
|
|
3
|
+
# Usage: playwright-repl --replay examples/03-record-session.pw --headed
|
|
4
|
+
|
|
5
|
+
goto https://demo.playwright.dev/todomvc/
|
|
6
|
+
fill "What needs to be done?" "Buy groceries"
|
|
7
|
+
press Enter
|
|
8
|
+
fill "What needs to be done?" "Write tests"
|
|
9
|
+
press Enter
|
|
10
|
+
check "Buy groceries"
|
|
11
|
+
verify-text "1 item left"
|
|
12
|
+
click "Clear completed"
|
|
13
|
+
verify-text "Write tests"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Replay demo — add todos, complete them, verify count
|
|
2
|
+
# App: https://demo.playwright.dev/todomvc/
|
|
3
|
+
# Full speed: playwright-repl --replay examples/04-replay-session.pw
|
|
4
|
+
# Step-through: playwright-repl --replay examples/04-replay-session.pw --step --headed
|
|
5
|
+
|
|
6
|
+
goto https://demo.playwright.dev/todomvc/
|
|
7
|
+
fill "What needs to be done?" "Buy groceries"
|
|
8
|
+
press Enter
|
|
9
|
+
fill "What needs to be done?" "Write tests"
|
|
10
|
+
press Enter
|
|
11
|
+
fill "What needs to be done?" "Deploy to production"
|
|
12
|
+
press Enter
|
|
13
|
+
verify-text "3 items left"
|
|
14
|
+
check "Buy groceries"
|
|
15
|
+
verify-text "2 items left"
|
|
16
|
+
check "Write tests"
|
|
17
|
+
verify-text "1 item left"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# CI smoke test — quick add-and-verify
|
|
2
|
+
# App: https://demo.playwright.dev/todomvc/
|
|
3
|
+
# Usage: playwright-repl --replay examples/05-ci-pipe.pw --silent
|
|
4
|
+
|
|
5
|
+
goto https://demo.playwright.dev/todomvc/
|
|
6
|
+
fill "What needs to be done?" "Buy groceries"
|
|
7
|
+
press Enter
|
|
8
|
+
verify-text "Buy groceries"
|
|
9
|
+
verify-text "1 item left"
|
|
10
|
+
fill "What needs to be done?" "Write tests"
|
|
11
|
+
press Enter
|
|
12
|
+
verify-text "2 items left"
|
|
13
|
+
check "Buy groceries"
|
|
14
|
+
verify-text "1 item left"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Double-click to edit a todo
|
|
2
|
+
# App: https://demo.playwright.dev/todomvc/
|
|
3
|
+
|
|
4
|
+
goto https://demo.playwright.dev/todomvc/
|
|
5
|
+
fill "What needs to be done?" "Buy groceries"
|
|
6
|
+
press Enter
|
|
7
|
+
dblclick "Buy groceries"
|
|
8
|
+
press Control+a
|
|
9
|
+
type "Buy organic groceries"
|
|
10
|
+
press Enter
|
|
11
|
+
verify-text "Buy organic groceries"
|