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