@assertrx/dino 1.0.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/README.md +293 -0
- package/extensions/dino.ts +70 -0
- package/extensions/mabl-mcp.ts +306 -0
- package/extensions/playwright-mcp.ts +142 -0
- package/package.json +47 -0
- package/prompts/create-pr.md +110 -0
- package/prompts/generate-bdd-from-url.md +65 -0
- package/prompts/generate-pom-from-url-cli.md +48 -0
- package/prompts/generate-pom-from-url.md +45 -0
- package/prompts/generate-spec-from-feature.md +64 -0
- package/prompts/heal-playwright-failures.md +106 -0
- package/prompts/setup-playwright.md +81 -0
- package/scripts/start-dino.cmd +8 -0
- package/scripts/start-dino.mjs +226 -0
- package/scripts/start-dino.ps1 +9 -0
- package/scripts/start-dino.sh +10 -0
- package/skills/acli/SKILL.md +292 -0
- package/skills/bdd-gherkin/SKILL.md +552 -0
- package/skills/build-review-interface/SKILL.md +96 -0
- package/skills/error-analysis/SKILL.md +164 -0
- package/skills/eval-audit/SKILL.md +183 -0
- package/skills/evaluate-rag/SKILL.md +177 -0
- package/skills/generate-synthetic-data/SKILL.md +131 -0
- package/skills/mabl-mcp/SKILL.md +79 -0
- package/skills/playwright-cli/SKILL.md +246 -0
- package/skills/playwright-cli/advanced-workflows.md +679 -0
- package/skills/playwright-cli/core-commands.md +375 -0
- package/skills/playwright-cli/device-emulation.md +475 -0
- package/skills/playwright-cli/request-mocking.md +373 -0
- package/skills/playwright-cli/running-custom-code.md +553 -0
- package/skills/playwright-cli/screenshots-and-media.md +457 -0
- package/skills/playwright-cli/session-management.md +425 -0
- package/skills/playwright-cli/storage-and-auth.md +487 -0
- package/skills/playwright-cli/test-generation.md +336 -0
- package/skills/playwright-cli/tracing-and-debugging.md +501 -0
- package/skills/playwright-core/SKILL.md +101 -0
- package/skills/playwright-core/accessibility.md +1517 -0
- package/skills/playwright-core/angular.md +1086 -0
- package/skills/playwright-core/api-testing.md +1623 -0
- package/skills/playwright-core/assertions-and-waiting.md +703 -0
- package/skills/playwright-core/auth-flows.md +1081 -0
- package/skills/playwright-core/authentication.md +1409 -0
- package/skills/playwright-core/browser-apis.md +673 -0
- package/skills/playwright-core/browser-extensions.md +319 -0
- package/skills/playwright-core/canvas-and-webgl.md +494 -0
- package/skills/playwright-core/clock-and-time-mocking.md +427 -0
- package/skills/playwright-core/common-pitfalls.md +1318 -0
- package/skills/playwright-core/component-testing.md +1179 -0
- package/skills/playwright-core/configuration.md +731 -0
- package/skills/playwright-core/crud-testing.md +945 -0
- package/skills/playwright-core/debugging.md +827 -0
- package/skills/playwright-core/drag-and-drop.md +992 -0
- package/skills/playwright-core/electron-testing.md +622 -0
- package/skills/playwright-core/error-and-edge-cases.md +1181 -0
- package/skills/playwright-core/error-index.md +1903 -0
- package/skills/playwright-core/file-operations.md +749 -0
- package/skills/playwright-core/file-upload-download.md +1012 -0
- package/skills/playwright-core/fixtures-and-hooks.md +1072 -0
- package/skills/playwright-core/flaky-tests.md +883 -0
- package/skills/playwright-core/forms-and-validation.md +1056 -0
- package/skills/playwright-core/i18n-and-localization.md +622 -0
- package/skills/playwright-core/iframes-and-shadow-dom.md +488 -0
- package/skills/playwright-core/locator-strategy.md +588 -0
- package/skills/playwright-core/locators.md +743 -0
- package/skills/playwright-core/mobile-and-responsive.md +1669 -0
- package/skills/playwright-core/multi-context-and-popups.md +581 -0
- package/skills/playwright-core/multi-user-and-collaboration.md +477 -0
- package/skills/playwright-core/network-mocking.md +1395 -0
- package/skills/playwright-core/nextjs.md +1013 -0
- package/skills/playwright-core/performance-testing.md +608 -0
- package/skills/playwright-core/react.md +1082 -0
- package/skills/playwright-core/search-and-filter.md +1366 -0
- package/skills/playwright-core/security-testing.md +624 -0
- package/skills/playwright-core/service-workers-and-pwa.md +524 -0
- package/skills/playwright-core/test-architecture.md +569 -0
- package/skills/playwright-core/test-data-management.md +1209 -0
- package/skills/playwright-core/test-organization.md +947 -0
- package/skills/playwright-core/third-party-integrations.md +754 -0
- package/skills/playwright-core/trace-analysis.md +161 -0
- package/skills/playwright-core/visual-regression.md +1027 -0
- package/skills/playwright-core/vue.md +1162 -0
- package/skills/playwright-core/websockets-and-realtime.md +623 -0
- package/skills/playwright-core/when-to-mock.md +827 -0
- package/skills/playwright-pom/SKILL.md +94 -0
- package/skills/playwright-pom/page-object-model.md +921 -0
- package/skills/playwright-pom/pom-vs-fixtures-vs-helpers.md +937 -0
- package/skills/validate-evaluator/SKILL.md +215 -0
- package/skills/write-judge-prompt/SKILL.md +144 -0
- package/themes/dino.json +66 -0
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
# Storage and Authentication
|
|
2
|
+
|
|
3
|
+
> **When to use**: Managing cookies, localStorage, sessionStorage, browser storage state, saving and restoring authentication, or testing storage-dependent features.
|
|
4
|
+
> **Prerequisites**: [core-commands.md](core-commands.md) for basic CLI usage
|
|
5
|
+
|
|
6
|
+
## Quick Reference
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
# Save all browser state (cookies + localStorage) to file
|
|
10
|
+
playwright-cli state-save auth.json
|
|
11
|
+
|
|
12
|
+
# Restore state in a new session
|
|
13
|
+
playwright-cli state-load auth.json
|
|
14
|
+
|
|
15
|
+
# Quick cookie operations
|
|
16
|
+
playwright-cli cookie-list
|
|
17
|
+
playwright-cli cookie-set session_id abc123 --domain=example.com --httpOnly --secure
|
|
18
|
+
playwright-cli cookie-delete session_id
|
|
19
|
+
playwright-cli cookie-clear
|
|
20
|
+
|
|
21
|
+
# localStorage
|
|
22
|
+
playwright-cli localstorage-set theme dark
|
|
23
|
+
playwright-cli localstorage-get theme
|
|
24
|
+
playwright-cli localstorage-clear
|
|
25
|
+
|
|
26
|
+
# sessionStorage
|
|
27
|
+
playwright-cli sessionstorage-set step 3
|
|
28
|
+
playwright-cli sessionstorage-get step
|
|
29
|
+
playwright-cli sessionstorage-clear
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Storage State (Save & Restore)
|
|
33
|
+
|
|
34
|
+
The most powerful feature — save the entire browser state (cookies + localStorage for all origins) to a JSON file, then restore it later to skip login flows.
|
|
35
|
+
|
|
36
|
+
### Save Storage State
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Save to auto-generated filename (storage-state-{timestamp}.json)
|
|
40
|
+
playwright-cli state-save
|
|
41
|
+
|
|
42
|
+
# Save to specific file
|
|
43
|
+
playwright-cli state-save auth.json
|
|
44
|
+
playwright-cli state-save ./states/admin-session.json
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Restore Storage State
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Load state from file
|
|
51
|
+
playwright-cli state-load auth.json
|
|
52
|
+
|
|
53
|
+
# Navigate after loading — cookies and localStorage are already set
|
|
54
|
+
playwright-cli goto https://app.example.com/dashboard
|
|
55
|
+
# Already authenticated!
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Storage State File Format
|
|
59
|
+
|
|
60
|
+
The saved JSON contains both cookies and localStorage:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"cookies": [
|
|
65
|
+
{
|
|
66
|
+
"name": "session_id",
|
|
67
|
+
"value": "abc123",
|
|
68
|
+
"domain": "example.com",
|
|
69
|
+
"path": "/",
|
|
70
|
+
"expires": 1735689600,
|
|
71
|
+
"httpOnly": true,
|
|
72
|
+
"secure": true,
|
|
73
|
+
"sameSite": "Lax"
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"origins": [
|
|
77
|
+
{
|
|
78
|
+
"origin": "https://example.com",
|
|
79
|
+
"localStorage": [
|
|
80
|
+
{ "name": "theme", "value": "dark" },
|
|
81
|
+
{ "name": "user_id", "value": "12345" },
|
|
82
|
+
{ "name": "auth_token", "value": "jwt.token.here" }
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Authentication Pattern
|
|
90
|
+
|
|
91
|
+
The most common workflow — log in once, save state, reuse across sessions.
|
|
92
|
+
|
|
93
|
+
### Step 1: Log In and Save
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
playwright-cli open https://app.example.com/login
|
|
97
|
+
playwright-cli snapshot
|
|
98
|
+
|
|
99
|
+
playwright-cli fill e1 "admin@example.com"
|
|
100
|
+
playwright-cli fill e2 "secure-password"
|
|
101
|
+
playwright-cli click e3
|
|
102
|
+
|
|
103
|
+
# Wait for redirect to confirm login succeeded
|
|
104
|
+
playwright-cli run-code "async page => {
|
|
105
|
+
await page.waitForURL('**/dashboard');
|
|
106
|
+
return 'Login successful: ' + page.url();
|
|
107
|
+
}"
|
|
108
|
+
|
|
109
|
+
# Save the authenticated state
|
|
110
|
+
playwright-cli state-save auth.json
|
|
111
|
+
playwright-cli close
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Step 2: Reuse Auth State
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# New session — skip login entirely
|
|
118
|
+
playwright-cli open https://app.example.com
|
|
119
|
+
playwright-cli state-load auth.json
|
|
120
|
+
playwright-cli goto https://app.example.com/dashboard
|
|
121
|
+
# Already logged in as admin!
|
|
122
|
+
|
|
123
|
+
playwright-cli snapshot # See the dashboard
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Multi-Role Authentication
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Save state for each role
|
|
130
|
+
playwright-cli open https://app.example.com/login
|
|
131
|
+
playwright-cli fill e1 "admin@example.com"
|
|
132
|
+
playwright-cli fill e2 "admin-pass"
|
|
133
|
+
playwright-cli click e3
|
|
134
|
+
playwright-cli state-save admin-auth.json
|
|
135
|
+
playwright-cli close
|
|
136
|
+
|
|
137
|
+
playwright-cli open https://app.example.com/login
|
|
138
|
+
playwright-cli fill e1 "user@example.com"
|
|
139
|
+
playwright-cli fill e2 "user-pass"
|
|
140
|
+
playwright-cli click e3
|
|
141
|
+
playwright-cli state-save user-auth.json
|
|
142
|
+
playwright-cli close
|
|
143
|
+
|
|
144
|
+
# Now use them
|
|
145
|
+
playwright-cli -s=admin open https://app.example.com
|
|
146
|
+
playwright-cli -s=admin state-load admin-auth.json
|
|
147
|
+
playwright-cli -s=admin goto https://app.example.com/admin
|
|
148
|
+
|
|
149
|
+
playwright-cli -s=user open https://app.example.com
|
|
150
|
+
playwright-cli -s=user state-load user-auth.json
|
|
151
|
+
playwright-cli -s=user goto https://app.example.com/profile
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### OAuth / SSO Authentication
|
|
155
|
+
|
|
156
|
+
For OAuth flows that involve redirects and popups:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
playwright-cli run-code "async page => {
|
|
160
|
+
await page.goto('https://app.example.com/login');
|
|
161
|
+
|
|
162
|
+
// Click 'Login with Google'
|
|
163
|
+
const [popup] = await Promise.all([
|
|
164
|
+
page.waitForEvent('popup'),
|
|
165
|
+
page.click('button:text(\"Login with Google\")')
|
|
166
|
+
]);
|
|
167
|
+
|
|
168
|
+
// Fill credentials in the popup
|
|
169
|
+
await popup.fill('input[type=email]', 'user@gmail.com');
|
|
170
|
+
await popup.click('#identifierNext');
|
|
171
|
+
await popup.fill('input[type=password]', 'password');
|
|
172
|
+
await popup.click('#passwordNext');
|
|
173
|
+
|
|
174
|
+
// Wait for popup to close and main page to redirect
|
|
175
|
+
await popup.waitForEvent('close');
|
|
176
|
+
await page.waitForURL('**/dashboard');
|
|
177
|
+
|
|
178
|
+
// Save authenticated state
|
|
179
|
+
await page.context().storageState({ path: 'oauth-auth.json' });
|
|
180
|
+
return 'OAuth login complete';
|
|
181
|
+
}"
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Cookies
|
|
185
|
+
|
|
186
|
+
### List All Cookies
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
playwright-cli cookie-list
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Filter by Domain
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
playwright-cli cookie-list --domain=example.com
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Filter by Path
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
playwright-cli cookie-list --path=/api
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Get a Specific Cookie
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
playwright-cli cookie-get session_id
|
|
208
|
+
playwright-cli cookie-get __cf_bm
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Set a Cookie
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
# Basic cookie
|
|
215
|
+
playwright-cli cookie-set session abc123
|
|
216
|
+
|
|
217
|
+
# Cookie with full options
|
|
218
|
+
playwright-cli cookie-set session abc123 \
|
|
219
|
+
--domain=example.com \
|
|
220
|
+
--path=/ \
|
|
221
|
+
--httpOnly \
|
|
222
|
+
--secure \
|
|
223
|
+
--sameSite=Lax
|
|
224
|
+
|
|
225
|
+
# Cookie with expiration (Unix timestamp)
|
|
226
|
+
playwright-cli cookie-set remember_me token123 --expires=1735689600
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Delete a Cookie
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
playwright-cli cookie-delete session_id
|
|
233
|
+
playwright-cli cookie-delete __cf_bm
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Clear All Cookies
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
playwright-cli cookie-clear
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Advanced: Multiple Cookies at Once
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
playwright-cli run-code "async page => {
|
|
246
|
+
await page.context().addCookies([
|
|
247
|
+
{
|
|
248
|
+
name: 'session_id',
|
|
249
|
+
value: 'sess_abc123',
|
|
250
|
+
domain: 'example.com',
|
|
251
|
+
path: '/',
|
|
252
|
+
httpOnly: true,
|
|
253
|
+
secure: true,
|
|
254
|
+
sameSite: 'Strict'
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
name: 'preferences',
|
|
258
|
+
value: JSON.stringify({ theme: 'dark', lang: 'en' }),
|
|
259
|
+
domain: 'example.com',
|
|
260
|
+
path: '/'
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
name: 'tracking_opt_out',
|
|
264
|
+
value: 'true',
|
|
265
|
+
domain: '.example.com',
|
|
266
|
+
path: '/'
|
|
267
|
+
}
|
|
268
|
+
]);
|
|
269
|
+
}"
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Advanced: Read All Cookies Programmatically
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
playwright-cli run-code "async page => {
|
|
276
|
+
const cookies = await page.context().cookies();
|
|
277
|
+
return cookies.map(c => ({
|
|
278
|
+
name: c.name,
|
|
279
|
+
value: c.value.substring(0, 20) + '...',
|
|
280
|
+
domain: c.domain,
|
|
281
|
+
httpOnly: c.httpOnly,
|
|
282
|
+
secure: c.secure,
|
|
283
|
+
expires: new Date(c.expires * 1000).toISOString()
|
|
284
|
+
}));
|
|
285
|
+
}"
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Local Storage
|
|
289
|
+
|
|
290
|
+
### List All Items
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
playwright-cli localstorage-list
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Get a Value
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
playwright-cli localstorage-get theme
|
|
300
|
+
playwright-cli localstorage-get auth_token
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Set a Value
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
playwright-cli localstorage-set theme dark
|
|
307
|
+
playwright-cli localstorage-set language en-US
|
|
308
|
+
|
|
309
|
+
# Set JSON values (quote the JSON)
|
|
310
|
+
playwright-cli localstorage-set user_settings '{"theme":"dark","fontSize":14,"sidebar":true}'
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Delete an Item
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
playwright-cli localstorage-delete auth_token
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### Clear All
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
playwright-cli localstorage-clear
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Advanced: Bulk Operations
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
playwright-cli run-code "async page => {
|
|
329
|
+
await page.evaluate(() => {
|
|
330
|
+
localStorage.setItem('token', 'jwt_abc123');
|
|
331
|
+
localStorage.setItem('user_id', '12345');
|
|
332
|
+
localStorage.setItem('user_name', 'Jane Doe');
|
|
333
|
+
localStorage.setItem('preferences', JSON.stringify({
|
|
334
|
+
theme: 'dark',
|
|
335
|
+
notifications: true,
|
|
336
|
+
language: 'en'
|
|
337
|
+
}));
|
|
338
|
+
localStorage.setItem('onboarding_complete', 'true');
|
|
339
|
+
});
|
|
340
|
+
}"
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### Advanced: Read All localStorage
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
playwright-cli run-code "async page => {
|
|
347
|
+
return await page.evaluate(() => {
|
|
348
|
+
const items = {};
|
|
349
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
350
|
+
const key = localStorage.key(i);
|
|
351
|
+
items[key] = localStorage.getItem(key);
|
|
352
|
+
}
|
|
353
|
+
return items;
|
|
354
|
+
});
|
|
355
|
+
}"
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
## Session Storage
|
|
359
|
+
|
|
360
|
+
Session storage is per-tab and cleared when the tab closes.
|
|
361
|
+
|
|
362
|
+
### List All Items
|
|
363
|
+
|
|
364
|
+
```bash
|
|
365
|
+
playwright-cli sessionstorage-list
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### Get / Set / Delete
|
|
369
|
+
|
|
370
|
+
```bash
|
|
371
|
+
playwright-cli sessionstorage-get form_step
|
|
372
|
+
playwright-cli sessionstorage-set form_step 3
|
|
373
|
+
playwright-cli sessionstorage-set form_data '{"name":"Jane","email":"jane@example.com"}'
|
|
374
|
+
playwright-cli sessionstorage-delete form_step
|
|
375
|
+
playwright-cli sessionstorage-clear
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
## IndexedDB
|
|
379
|
+
|
|
380
|
+
IndexedDB requires `run-code` for access:
|
|
381
|
+
|
|
382
|
+
### List Databases
|
|
383
|
+
|
|
384
|
+
```bash
|
|
385
|
+
playwright-cli run-code "async page => {
|
|
386
|
+
return await page.evaluate(async () => {
|
|
387
|
+
const databases = await indexedDB.databases();
|
|
388
|
+
return databases.map(db => ({ name: db.name, version: db.version }));
|
|
389
|
+
});
|
|
390
|
+
}"
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### Delete a Database
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
playwright-cli run-code "async page => {
|
|
397
|
+
await page.evaluate(dbName => {
|
|
398
|
+
indexedDB.deleteDatabase(dbName);
|
|
399
|
+
}, 'myDatabase');
|
|
400
|
+
return 'Database deleted';
|
|
401
|
+
}"
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### Read Data from an Object Store
|
|
405
|
+
|
|
406
|
+
```bash
|
|
407
|
+
playwright-cli run-code "async page => {
|
|
408
|
+
return await page.evaluate(() => {
|
|
409
|
+
return new Promise((resolve, reject) => {
|
|
410
|
+
const request = indexedDB.open('myDatabase');
|
|
411
|
+
request.onsuccess = () => {
|
|
412
|
+
const db = request.result;
|
|
413
|
+
const tx = db.transaction('myStore', 'readonly');
|
|
414
|
+
const store = tx.objectStore('myStore');
|
|
415
|
+
const getAll = store.getAll();
|
|
416
|
+
getAll.onsuccess = () => resolve(getAll.result);
|
|
417
|
+
getAll.onerror = () => reject(getAll.error);
|
|
418
|
+
};
|
|
419
|
+
request.onerror = () => reject(request.error);
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
}"
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
## Common Patterns
|
|
426
|
+
|
|
427
|
+
### Token Refresh Testing
|
|
428
|
+
|
|
429
|
+
```bash
|
|
430
|
+
# Set an expired token to test refresh logic
|
|
431
|
+
playwright-cli localstorage-set auth_token "expired-jwt-token"
|
|
432
|
+
playwright-cli localstorage-set token_expiry "1609459200"
|
|
433
|
+
|
|
434
|
+
# Navigate to trigger token refresh
|
|
435
|
+
playwright-cli goto https://app.example.com/dashboard
|
|
436
|
+
|
|
437
|
+
# Check if token was refreshed
|
|
438
|
+
playwright-cli localstorage-get auth_token
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### Feature Flag Testing
|
|
442
|
+
|
|
443
|
+
```bash
|
|
444
|
+
# Enable a feature flag via localStorage
|
|
445
|
+
playwright-cli localstorage-set feature_flags '{"newCheckout":true,"darkMode":true,"betaFeatures":false}'
|
|
446
|
+
|
|
447
|
+
# Reload to apply
|
|
448
|
+
playwright-cli reload
|
|
449
|
+
playwright-cli snapshot
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
### Clear Everything and Start Fresh
|
|
453
|
+
|
|
454
|
+
```bash
|
|
455
|
+
playwright-cli cookie-clear
|
|
456
|
+
playwright-cli localstorage-clear
|
|
457
|
+
playwright-cli sessionstorage-clear
|
|
458
|
+
playwright-cli reload
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
### Save and Restore Roundtrip
|
|
462
|
+
|
|
463
|
+
```bash
|
|
464
|
+
# Set up state manually
|
|
465
|
+
playwright-cli open https://example.com
|
|
466
|
+
playwright-cli cookie-set session abc123 --domain=example.com
|
|
467
|
+
playwright-cli localstorage-set user john
|
|
468
|
+
playwright-cli localstorage-set theme dark
|
|
469
|
+
|
|
470
|
+
# Save everything
|
|
471
|
+
playwright-cli state-save my-session.json
|
|
472
|
+
|
|
473
|
+
# Later — restore state in a new session
|
|
474
|
+
playwright-cli open https://example.com
|
|
475
|
+
playwright-cli state-load my-session.json
|
|
476
|
+
playwright-cli reload
|
|
477
|
+
# Cookies and localStorage are restored
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
## Security Notes
|
|
481
|
+
|
|
482
|
+
- **Never commit auth state files** — add `*.auth-state.json` and `auth.json` to `.gitignore`
|
|
483
|
+
- **Delete state files after use** — `rm auth.json` when done with automation
|
|
484
|
+
- **Use environment variables for credentials** — never hardcode passwords in scripts
|
|
485
|
+
- **In-memory sessions are safer** — default sessions don't persist to disk, reducing exposure
|
|
486
|
+
- **Rotate saved states** — auth tokens expire; regenerate state files regularly
|
|
487
|
+
- **Avoid saving state on shared machines** — storage state files contain session tokens and personal data
|