@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,373 @@
|
|
|
1
|
+
# Request Mocking
|
|
2
|
+
|
|
3
|
+
> **When to use**: Intercepting, mocking, modifying, or blocking network requests during browser automation — API stubbing, simulating errors, testing offline behavior, removing tracking, or speeding up pages by blocking heavy assets.
|
|
4
|
+
> **Prerequisites**: [core-commands.md](core-commands.md) for basic CLI usage
|
|
5
|
+
|
|
6
|
+
## Quick Reference
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
# Block all images
|
|
10
|
+
playwright-cli route "**/*.jpg" --status=404
|
|
11
|
+
|
|
12
|
+
# Mock API response with JSON body
|
|
13
|
+
playwright-cli route "**/api/users" --body='[{"id":1,"name":"Alice"}]' --content-type=application/json
|
|
14
|
+
|
|
15
|
+
# Add custom response headers
|
|
16
|
+
playwright-cli route "**/api/data" --body='{"ok":true}' --header="X-Custom: value"
|
|
17
|
+
|
|
18
|
+
# Strip request headers (e.g., remove auth for testing)
|
|
19
|
+
playwright-cli route "**/*" --remove-header=cookie,authorization
|
|
20
|
+
|
|
21
|
+
# List active routes
|
|
22
|
+
playwright-cli route-list
|
|
23
|
+
|
|
24
|
+
# Remove a specific route
|
|
25
|
+
playwright-cli unroute "**/*.jpg"
|
|
26
|
+
|
|
27
|
+
# Remove all routes
|
|
28
|
+
playwright-cli unroute
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## URL Patterns
|
|
32
|
+
|
|
33
|
+
playwright-cli uses glob patterns for URL matching:
|
|
34
|
+
|
|
35
|
+
| Pattern | Matches | Example URLs |
|
|
36
|
+
|---------|---------|-------------|
|
|
37
|
+
| `**/api/users` | Exact path on any origin | `https://api.example.com/api/users` |
|
|
38
|
+
| `**/api/*/details` | Wildcard in path segment | `https://api.example.com/api/123/details` |
|
|
39
|
+
| `**/*.{png,jpg,jpeg}` | Multiple file extensions | `https://cdn.example.com/hero.png` |
|
|
40
|
+
| `**/search?q=*` | Query parameters | `https://example.com/search?q=test` |
|
|
41
|
+
| `https://api.example.com/**` | All requests to a specific origin | `https://api.example.com/v2/users` |
|
|
42
|
+
| `**/*` | All requests | Everything |
|
|
43
|
+
|
|
44
|
+
## CLI Route Commands
|
|
45
|
+
|
|
46
|
+
### Mock with Status Code
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Return 404 for all image requests
|
|
50
|
+
playwright-cli route "**/*.jpg" --status=404
|
|
51
|
+
|
|
52
|
+
# Return 503 Service Unavailable
|
|
53
|
+
playwright-cli route "**/api/health" --status=503
|
|
54
|
+
|
|
55
|
+
# Return 401 Unauthorized
|
|
56
|
+
playwright-cli route "**/api/protected" --status=401
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Mock with JSON Response
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Simple JSON body
|
|
63
|
+
playwright-cli route "**/api/users" --body='[{"id":1,"name":"Alice"},{"id":2,"name":"Bob"}]' --content-type=application/json
|
|
64
|
+
|
|
65
|
+
# Mock a single resource
|
|
66
|
+
playwright-cli route "**/api/users/1" --body='{"id":1,"name":"Alice","email":"alice@example.com"}' --content-type=application/json
|
|
67
|
+
|
|
68
|
+
# Return empty array (no results scenario)
|
|
69
|
+
playwright-cli route "**/api/search*" --body='[]' --content-type=application/json
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Mock with Custom Headers
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Set CORS headers for testing
|
|
76
|
+
playwright-cli route "**/api/**" --body='{"ok":true}' --header="Access-Control-Allow-Origin: *" --header="X-Request-Id: mock-123"
|
|
77
|
+
|
|
78
|
+
# Set caching headers
|
|
79
|
+
playwright-cli route "**/static/**" --header="Cache-Control: max-age=3600"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Remove Request Headers
|
|
83
|
+
|
|
84
|
+
Strip headers from outgoing requests — useful for testing unauthenticated access:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Remove authentication headers
|
|
88
|
+
playwright-cli route "**/*" --remove-header=cookie,authorization
|
|
89
|
+
|
|
90
|
+
# Remove tracking headers
|
|
91
|
+
playwright-cli route "**/*" --remove-header=x-tracking-id
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Manage Active Routes
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# See what's currently being intercepted
|
|
98
|
+
playwright-cli route-list
|
|
99
|
+
|
|
100
|
+
# Remove a specific route
|
|
101
|
+
playwright-cli unroute "**/*.jpg"
|
|
102
|
+
|
|
103
|
+
# Clear all routes
|
|
104
|
+
playwright-cli unroute
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Advanced Mocking with run-code
|
|
108
|
+
|
|
109
|
+
For conditional responses, request body inspection, response modification, or timed delays, use `run-code` to access the full Playwright route API.
|
|
110
|
+
|
|
111
|
+
### Conditional Response Based on Request Body
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
playwright-cli run-code "async page => {
|
|
115
|
+
await page.route('**/api/login', route => {
|
|
116
|
+
const body = route.request().postDataJSON();
|
|
117
|
+
if (body.username === 'admin' && body.password === 'secret') {
|
|
118
|
+
route.fulfill({
|
|
119
|
+
status: 200,
|
|
120
|
+
contentType: 'application/json',
|
|
121
|
+
body: JSON.stringify({ token: 'mock-jwt-token', user: { role: 'admin' } })
|
|
122
|
+
});
|
|
123
|
+
} else {
|
|
124
|
+
route.fulfill({
|
|
125
|
+
status: 401,
|
|
126
|
+
contentType: 'application/json',
|
|
127
|
+
body: JSON.stringify({ error: 'Invalid credentials' })
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}"
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Conditional Response Based on HTTP Method
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
playwright-cli run-code "async page => {
|
|
138
|
+
await page.route('**/api/users', route => {
|
|
139
|
+
const method = route.request().method();
|
|
140
|
+
switch (method) {
|
|
141
|
+
case 'GET':
|
|
142
|
+
route.fulfill({
|
|
143
|
+
contentType: 'application/json',
|
|
144
|
+
body: JSON.stringify([{ id: 1, name: 'Alice' }])
|
|
145
|
+
});
|
|
146
|
+
break;
|
|
147
|
+
case 'POST':
|
|
148
|
+
route.fulfill({
|
|
149
|
+
status: 201,
|
|
150
|
+
contentType: 'application/json',
|
|
151
|
+
body: JSON.stringify({ id: 2, name: 'New User' })
|
|
152
|
+
});
|
|
153
|
+
break;
|
|
154
|
+
case 'DELETE':
|
|
155
|
+
route.fulfill({ status: 204 });
|
|
156
|
+
break;
|
|
157
|
+
default:
|
|
158
|
+
route.continue();
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}"
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Modify a Real Response
|
|
165
|
+
|
|
166
|
+
Let the real request go through, then modify the response before the page sees it:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
playwright-cli run-code "async page => {
|
|
170
|
+
await page.route('**/api/user/profile', async route => {
|
|
171
|
+
const response = await route.fetch();
|
|
172
|
+
const json = await response.json();
|
|
173
|
+
|
|
174
|
+
// Override specific fields
|
|
175
|
+
json.isPremium = true;
|
|
176
|
+
json.subscription = 'enterprise';
|
|
177
|
+
|
|
178
|
+
await route.fulfill({ response, json });
|
|
179
|
+
});
|
|
180
|
+
}"
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Add Headers to Real Response
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
playwright-cli run-code "async page => {
|
|
187
|
+
await page.route('**/api/**', async route => {
|
|
188
|
+
const response = await route.fetch();
|
|
189
|
+
const headers = { ...response.headers(), 'x-mock': 'true' };
|
|
190
|
+
await route.fulfill({ response, headers });
|
|
191
|
+
});
|
|
192
|
+
}"
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Simulate Network Failures
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
# Internet disconnected
|
|
199
|
+
playwright-cli run-code "async page => {
|
|
200
|
+
await page.route('**/api/offline', route => route.abort('internetdisconnected'));
|
|
201
|
+
}"
|
|
202
|
+
|
|
203
|
+
# Connection refused
|
|
204
|
+
playwright-cli run-code "async page => {
|
|
205
|
+
await page.route('**/api/down', route => route.abort('connectionrefused'));
|
|
206
|
+
}"
|
|
207
|
+
|
|
208
|
+
# Timeout
|
|
209
|
+
playwright-cli run-code "async page => {
|
|
210
|
+
await page.route('**/api/slow', route => route.abort('timedout'));
|
|
211
|
+
}"
|
|
212
|
+
|
|
213
|
+
# Connection reset
|
|
214
|
+
playwright-cli run-code "async page => {
|
|
215
|
+
await page.route('**/api/reset', route => route.abort('connectionreset'));
|
|
216
|
+
}"
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Available abort reasons: `connectionrefused`, `timedout`, `connectionreset`, `internetdisconnected`, `blockedbyclient`, `failed`
|
|
220
|
+
|
|
221
|
+
### Simulate Slow Responses (Latency)
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
playwright-cli run-code "async page => {
|
|
225
|
+
await page.route('**/api/slow-endpoint', async route => {
|
|
226
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
227
|
+
route.fulfill({
|
|
228
|
+
contentType: 'application/json',
|
|
229
|
+
body: JSON.stringify({ data: 'finally loaded' })
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
}"
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Mock with Response from File
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
playwright-cli run-code "async page => {
|
|
239
|
+
const fs = require('fs');
|
|
240
|
+
await page.route('**/api/config', route => {
|
|
241
|
+
const body = fs.readFileSync('./fixtures/mock-config.json', 'utf8');
|
|
242
|
+
route.fulfill({
|
|
243
|
+
contentType: 'application/json',
|
|
244
|
+
body
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
}"
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Request Counting and Verification
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
playwright-cli run-code "async page => {
|
|
254
|
+
let apiCallCount = 0;
|
|
255
|
+
await page.route('**/api/analytics', route => {
|
|
256
|
+
apiCallCount++;
|
|
257
|
+
route.continue();
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// ... perform actions ...
|
|
261
|
+
// Later, check count:
|
|
262
|
+
return \`API was called \${apiCallCount} times\`;
|
|
263
|
+
}"
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Common Patterns
|
|
267
|
+
|
|
268
|
+
### Block Heavy Assets for Speed
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Block images, fonts, and stylesheets
|
|
272
|
+
playwright-cli route "**/*.{png,jpg,jpeg,gif,svg,webp}" --status=404
|
|
273
|
+
playwright-cli route "**/*.{woff,woff2,ttf,eot}" --status=404
|
|
274
|
+
playwright-cli route "**/*.css" --status=404
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Block Third-Party Scripts
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
# Block analytics and tracking
|
|
281
|
+
playwright-cli run-code "async page => {
|
|
282
|
+
await page.route('**/*', route => {
|
|
283
|
+
const url = route.request().url();
|
|
284
|
+
const blocked = [
|
|
285
|
+
'google-analytics.com',
|
|
286
|
+
'googletagmanager.com',
|
|
287
|
+
'facebook.net',
|
|
288
|
+
'hotjar.com',
|
|
289
|
+
'segment.io'
|
|
290
|
+
];
|
|
291
|
+
if (blocked.some(domain => url.includes(domain))) {
|
|
292
|
+
route.abort('blockedbyclient');
|
|
293
|
+
} else {
|
|
294
|
+
route.continue();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}"
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Mock GraphQL Requests
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
playwright-cli run-code "async page => {
|
|
304
|
+
await page.route('**/graphql', route => {
|
|
305
|
+
const { query } = route.request().postDataJSON();
|
|
306
|
+
|
|
307
|
+
if (query.includes('GetUser')) {
|
|
308
|
+
route.fulfill({
|
|
309
|
+
contentType: 'application/json',
|
|
310
|
+
body: JSON.stringify({
|
|
311
|
+
data: { user: { id: '1', name: 'Alice', email: 'alice@example.com' } }
|
|
312
|
+
})
|
|
313
|
+
});
|
|
314
|
+
} else if (query.includes('ListProducts')) {
|
|
315
|
+
route.fulfill({
|
|
316
|
+
contentType: 'application/json',
|
|
317
|
+
body: JSON.stringify({
|
|
318
|
+
data: { products: [{ id: '1', name: 'Widget', price: 9.99 }] }
|
|
319
|
+
})
|
|
320
|
+
});
|
|
321
|
+
} else {
|
|
322
|
+
route.continue();
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}"
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### HAR-Based Replay
|
|
329
|
+
|
|
330
|
+
Record real network traffic and replay it later — perfect for deterministic testing:
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
# Record all network traffic to a HAR file
|
|
334
|
+
playwright-cli run-code "async page => {
|
|
335
|
+
await page.routeFromHAR('./recordings/api-traffic.har', {
|
|
336
|
+
update: true,
|
|
337
|
+
url: '**/api/**'
|
|
338
|
+
});
|
|
339
|
+
await page.goto('https://example.com');
|
|
340
|
+
// Interact with the page — all matching requests are recorded
|
|
341
|
+
}"
|
|
342
|
+
|
|
343
|
+
# Later, replay from the HAR file (no real network needed)
|
|
344
|
+
playwright-cli run-code "async page => {
|
|
345
|
+
await page.routeFromHAR('./recordings/api-traffic.har', {
|
|
346
|
+
url: '**/api/**'
|
|
347
|
+
});
|
|
348
|
+
await page.goto('https://example.com');
|
|
349
|
+
// API responses come from the HAR file
|
|
350
|
+
}"
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### Mock WebSocket Messages
|
|
354
|
+
|
|
355
|
+
```bash
|
|
356
|
+
playwright-cli run-code "async page => {
|
|
357
|
+
const ws = await page.waitForEvent('websocket');
|
|
358
|
+
ws.on('framereceived', event => {
|
|
359
|
+
console.log('WS received:', event.payload);
|
|
360
|
+
});
|
|
361
|
+
ws.on('framesent', event => {
|
|
362
|
+
console.log('WS sent:', event.payload);
|
|
363
|
+
});
|
|
364
|
+
}"
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## Tips
|
|
368
|
+
|
|
369
|
+
- **Order matters**: Routes are evaluated in the order they were added. More specific patterns should be added before catch-all patterns.
|
|
370
|
+
- **`route.continue()`**: Lets the request proceed to the real server — use this in conditional routes for the "pass-through" case.
|
|
371
|
+
- **`route.fetch()`**: Makes the real request and returns the response, so you can inspect or modify it before fulfilling.
|
|
372
|
+
- **Performance**: Blocking images and third-party scripts can dramatically speed up page loads during automation.
|
|
373
|
+
- **Cleanup**: Always `unroute` when done, or routes persist for the entire session and may interfere with later operations.
|