|
| 1 | +--- |
| 2 | +name: playwright-cli |
| 3 | +description: Automates browser interactions for web testing, form filling, screenshots, and data extraction. Use when the user needs to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages. |
| 4 | +allowed-tools: Bash(playwright-cli:*) |
| 5 | +--- |
| 6 | + |
| 7 | +# Browser Automation with playwright-cli |
| 8 | + |
| 9 | +## Quick start |
| 10 | + |
| 11 | +```bash |
| 12 | +playwright-cli open https://playwright.dev |
| 13 | +playwright-cli click e15 |
| 14 | +playwright-cli type "page.click" |
| 15 | +playwright-cli press Enter |
| 16 | +``` |
| 17 | + |
| 18 | +## Core workflow |
| 19 | + |
| 20 | +1. Navigate: `playwright-cli open https://example.com` |
| 21 | +2. Interact using refs from the snapshot |
| 22 | +3. Re-snapshot after significant changes |
| 23 | + |
| 24 | +## Commands |
| 25 | + |
| 26 | +### Core |
| 27 | + |
| 28 | +```bash |
| 29 | +playwright-cli open https://example.com/ |
| 30 | +playwright-cli close |
| 31 | +playwright-cli type "search query" |
| 32 | +playwright-cli click e3 |
| 33 | +playwright-cli dblclick e7 |
| 34 | +playwright-cli fill e5 "user@example.com" |
| 35 | +playwright-cli drag e2 e8 |
| 36 | +playwright-cli hover e4 |
| 37 | +playwright-cli select e9 "option-value" |
| 38 | +playwright-cli upload ./document.pdf |
| 39 | +playwright-cli check e12 |
| 40 | +playwright-cli uncheck e12 |
| 41 | +playwright-cli snapshot |
| 42 | +playwright-cli snapshot --filename=after-click.yaml |
| 43 | +playwright-cli eval "document.title" |
| 44 | +playwright-cli eval "el => el.textContent" e5 |
| 45 | +playwright-cli dialog-accept |
| 46 | +playwright-cli dialog-accept "confirmation text" |
| 47 | +playwright-cli dialog-dismiss |
| 48 | +playwright-cli resize 1920 1080 |
| 49 | +``` |
| 50 | +
|
| 51 | +### Navigation |
| 52 | +
|
| 53 | +```bash |
| 54 | +playwright-cli go-back |
| 55 | +playwright-cli go-forward |
| 56 | +playwright-cli reload |
| 57 | +``` |
| 58 | +
|
| 59 | +### Keyboard |
| 60 | +
|
| 61 | +```bash |
| 62 | +playwright-cli press Enter |
| 63 | +playwright-cli press ArrowDown |
| 64 | +playwright-cli keydown Shift |
| 65 | +playwright-cli keyup Shift |
| 66 | +``` |
| 67 | +
|
| 68 | +### Mouse |
| 69 | +
|
| 70 | +```bash |
| 71 | +playwright-cli mousemove 150 300 |
| 72 | +playwright-cli mousedown |
| 73 | +playwright-cli mousedown right |
| 74 | +playwright-cli mouseup |
| 75 | +playwright-cli mouseup right |
| 76 | +playwright-cli mousewheel 0 100 |
| 77 | +``` |
| 78 | +
|
| 79 | +### Save as |
| 80 | +
|
| 81 | +```bash |
| 82 | +playwright-cli screenshot |
| 83 | +playwright-cli screenshot e5 |
| 84 | +playwright-cli screenshot --filename=page.png |
| 85 | +playwright-cli pdf --filename=page.pdf |
| 86 | +``` |
| 87 | +
|
| 88 | +### Tabs |
| 89 | +
|
| 90 | +```bash |
| 91 | +playwright-cli tab-list |
| 92 | +playwright-cli tab-new |
| 93 | +playwright-cli tab-new https://example.com/page |
| 94 | +playwright-cli tab-close |
| 95 | +playwright-cli tab-close 2 |
| 96 | +playwright-cli tab-select 0 |
| 97 | +``` |
| 98 | +
|
| 99 | +### Storage |
| 100 | +
|
| 101 | +```bash |
| 102 | +playwright-cli state-save |
| 103 | +playwright-cli state-save auth.json |
| 104 | +playwright-cli state-load auth.json |
| 105 | + |
| 106 | +# Cookies |
| 107 | +playwright-cli cookie-list |
| 108 | +playwright-cli cookie-list --domain=example.com |
| 109 | +playwright-cli cookie-get session_id |
| 110 | +playwright-cli cookie-set session_id abc123 |
| 111 | +playwright-cli cookie-set session_id abc123 --domain=example.com --httpOnly --secure |
| 112 | +playwright-cli cookie-delete session_id |
| 113 | +playwright-cli cookie-clear |
| 114 | + |
| 115 | +# LocalStorage |
| 116 | +playwright-cli localstorage-list |
| 117 | +playwright-cli localstorage-get theme |
| 118 | +playwright-cli localstorage-set theme dark |
| 119 | +playwright-cli localstorage-delete theme |
| 120 | +playwright-cli localstorage-clear |
| 121 | + |
| 122 | +# SessionStorage |
| 123 | +playwright-cli sessionstorage-list |
| 124 | +playwright-cli sessionstorage-get step |
| 125 | +playwright-cli sessionstorage-set step 3 |
| 126 | +playwright-cli sessionstorage-delete step |
| 127 | +playwright-cli sessionstorage-clear |
| 128 | +``` |
| 129 | +
|
| 130 | +### Network |
| 131 | +
|
| 132 | +```bash |
| 133 | +playwright-cli route "**/*.jpg" --status=404 |
| 134 | +playwright-cli route "https://api.example.com/**" --body='{"mock": true}' |
| 135 | +playwright-cli route-list |
| 136 | +playwright-cli unroute "**/*.jpg" |
| 137 | +playwright-cli unroute |
| 138 | +``` |
| 139 | +
|
| 140 | +### DevTools |
| 141 | +
|
| 142 | +```bash |
| 143 | +playwright-cli console |
| 144 | +playwright-cli console warning |
| 145 | +playwright-cli network |
| 146 | +playwright-cli run-code "async page => await page.context().grantPermissions(['geolocation'])" |
| 147 | +playwright-cli tracing-start |
| 148 | +playwright-cli tracing-stop |
| 149 | +playwright-cli video-start |
| 150 | +playwright-cli video-stop video.webm |
| 151 | +``` |
| 152 | +
|
| 153 | +### Install |
| 154 | +
|
| 155 | +```bash |
| 156 | +playwright-cli install-browser |
| 157 | +playwright-cli install-skills |
| 158 | +``` |
| 159 | +
|
| 160 | +### Configuration |
| 161 | +```bash |
| 162 | +# Use specific browser when creating session |
| 163 | +playwright-cli open --browser=chrome |
| 164 | +playwright-cli open --browser=firefox |
| 165 | +playwright-cli open --browser=webkit |
| 166 | +playwright-cli open --browser=msedge |
| 167 | +# Connect to browser via extension |
| 168 | +playwright-cli open --extension |
| 169 | + |
| 170 | +# Use persistent profile (by default profile is in-memory) |
| 171 | +playwright-cli open --persistent |
| 172 | +# Use persistent profile with custom directory |
| 173 | +playwright-cli open --profile=/path/to/profile |
| 174 | + |
| 175 | +# Start with config file |
| 176 | +playwright-cli open --config=my-config.json |
| 177 | + |
| 178 | +# Close the browser |
| 179 | +playwright-cli close |
| 180 | +# Delete user data for the default session |
| 181 | +playwright-cli delete-data |
| 182 | +``` |
| 183 | +
|
| 184 | +### Browser Sessions |
| 185 | +
|
| 186 | +```bash |
| 187 | +playwright-cli -s=mysession open example.com |
| 188 | +playwright-cli -s=mysession click e6 |
| 189 | +playwright-cli -s=mysession close # stop a named browser |
| 190 | +playwright-cli -s=mysession delete-data # delete user data for named browser |
| 191 | + |
| 192 | +playwright-cli list |
| 193 | +# Close all browsers |
| 194 | +playwright-cli close-all |
| 195 | +# Forcefully kill all browser processes |
| 196 | +playwright-cli kill-all |
| 197 | +``` |
| 198 | +
|
| 199 | +## Example: Form submission |
| 200 | +
|
| 201 | +```bash |
| 202 | +playwright-cli open https://example.com/form |
| 203 | +playwright-cli snapshot |
| 204 | + |
| 205 | +playwright-cli fill e1 "user@example.com" |
| 206 | +playwright-cli fill e2 "password123" |
| 207 | +playwright-cli click e3 |
| 208 | +playwright-cli snapshot |
| 209 | +``` |
| 210 | +
|
| 211 | +## Example: Multi-tab workflow |
| 212 | +
|
| 213 | +```bash |
| 214 | +playwright-cli open https://example.com |
| 215 | +playwright-cli tab-new https://example.com/other |
| 216 | +playwright-cli tab-list |
| 217 | +playwright-cli tab-select 0 |
| 218 | +playwright-cli snapshot |
| 219 | +``` |
| 220 | +
|
| 221 | +## Example: Debugging with DevTools |
| 222 | +
|
| 223 | +```bash |
| 224 | +playwright-cli open https://example.com |
| 225 | +playwright-cli click e4 |
| 226 | +playwright-cli fill e7 "test" |
| 227 | +playwright-cli console |
| 228 | +playwright-cli network |
| 229 | +``` |
| 230 | +
|
| 231 | +```bash |
| 232 | +playwright-cli open https://example.com |
| 233 | +playwright-cli tracing-start |
| 234 | +playwright-cli click e4 |
| 235 | +playwright-cli fill e7 "test" |
| 236 | +playwright-cli tracing-stop |
| 237 | +``` |
| 238 | +
|
| 239 | +## Specific tasks |
| 240 | +
|
| 241 | +* **Request mocking** [references/request-mocking.md](references/request-mocking.md) |
| 242 | +* **Running Playwright code** [references/running-code.md](references/running-code.md) |
| 243 | +* **Browser session management** [references/session-management.md](references/session-management.md) |
| 244 | +* **Storage state (cookies, localStorage)** [references/storage-state.md](references/storage-state.md) |
| 245 | +* **Test generation** [references/test-generation.md](references/test-generation.md) |
| 246 | +* **Tracing** [references/tracing.md](references/tracing.md) |
| 247 | +* **Video recording** [references/video-recording.md](references/video-recording.md) |
0 commit comments