@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,475 @@
|
|
|
1
|
+
# Device and Environment Emulation
|
|
2
|
+
|
|
3
|
+
> **When to use**: Testing how your application behaves on different devices, screen sizes, geolocation, locales, timezones, color schemes, and network conditions — all from the CLI without needing physical devices.
|
|
4
|
+
> **Prerequisites**: [core-commands.md](core-commands.md) for basic CLI usage, [running-custom-code.md](running-custom-code.md) for `run-code` syntax
|
|
5
|
+
|
|
6
|
+
## Quick Reference
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
# Device emulation via config
|
|
10
|
+
playwright-cli open https://example.com --config=iphone.json
|
|
11
|
+
|
|
12
|
+
# Viewport resizing
|
|
13
|
+
playwright-cli resize 375 812 # iPhone viewport
|
|
14
|
+
playwright-cli resize 1920 1080 # Desktop viewport
|
|
15
|
+
|
|
16
|
+
# Geolocation
|
|
17
|
+
playwright-cli run-code "async page => {
|
|
18
|
+
await page.context().grantPermissions(['geolocation']);
|
|
19
|
+
await page.context().setGeolocation({ latitude: 40.7128, longitude: -74.0060 });
|
|
20
|
+
}"
|
|
21
|
+
|
|
22
|
+
# Color scheme
|
|
23
|
+
playwright-cli run-code "async page => {
|
|
24
|
+
await page.emulateMedia({ colorScheme: 'dark' });
|
|
25
|
+
}"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Viewport Emulation
|
|
29
|
+
|
|
30
|
+
The simplest form of device testing — set the viewport size to match a target device:
|
|
31
|
+
|
|
32
|
+
### Common Viewport Sizes
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Desktop
|
|
36
|
+
playwright-cli resize 1920 1080 # Full HD monitor
|
|
37
|
+
playwright-cli resize 1440 900 # MacBook Pro 15"
|
|
38
|
+
playwright-cli resize 1366 768 # Common laptop
|
|
39
|
+
playwright-cli resize 2560 1440 # QHD / 2K monitor
|
|
40
|
+
|
|
41
|
+
# Tablet
|
|
42
|
+
playwright-cli resize 1024 768 # iPad landscape
|
|
43
|
+
playwright-cli resize 768 1024 # iPad portrait
|
|
44
|
+
playwright-cli resize 834 1194 # iPad Pro 11"
|
|
45
|
+
playwright-cli resize 1194 834 # iPad Pro 11" landscape
|
|
46
|
+
playwright-cli resize 820 1180 # iPad Air
|
|
47
|
+
|
|
48
|
+
# Mobile
|
|
49
|
+
playwright-cli resize 430 932 # iPhone 14 Pro Max
|
|
50
|
+
playwright-cli resize 393 852 # iPhone 14 Pro
|
|
51
|
+
playwright-cli resize 390 844 # iPhone 14 / 13 / 12
|
|
52
|
+
playwright-cli resize 375 812 # iPhone X / 11
|
|
53
|
+
playwright-cli resize 360 800 # Samsung Galaxy S21
|
|
54
|
+
playwright-cli resize 412 915 # Pixel 7
|
|
55
|
+
playwright-cli resize 320 568 # iPhone SE (1st gen)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Test Responsive Breakpoints
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Common CSS breakpoints
|
|
62
|
+
playwright-cli resize 320 568 # xs: Extra small
|
|
63
|
+
playwright-cli screenshot --filename=responsive-xs.png
|
|
64
|
+
|
|
65
|
+
playwright-cli resize 576 768 # sm: Small
|
|
66
|
+
playwright-cli screenshot --filename=responsive-sm.png
|
|
67
|
+
|
|
68
|
+
playwright-cli resize 768 1024 # md: Medium
|
|
69
|
+
playwright-cli screenshot --filename=responsive-md.png
|
|
70
|
+
|
|
71
|
+
playwright-cli resize 992 768 # lg: Large
|
|
72
|
+
playwright-cli screenshot --filename=responsive-lg.png
|
|
73
|
+
|
|
74
|
+
playwright-cli resize 1200 900 # xl: Extra large
|
|
75
|
+
playwright-cli screenshot --filename=responsive-xl.png
|
|
76
|
+
|
|
77
|
+
playwright-cli resize 1400 900 # xxl: Extra extra large
|
|
78
|
+
playwright-cli screenshot --filename=responsive-xxl.png
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Full Device Emulation
|
|
82
|
+
|
|
83
|
+
For accurate device testing, you need more than just viewport — device scale factor, user agent, touch support, and mobile behavior. Use a config file or `run-code`.
|
|
84
|
+
|
|
85
|
+
### Config File Approach
|
|
86
|
+
|
|
87
|
+
Create a config file for a specific device:
|
|
88
|
+
|
|
89
|
+
**`iphone14.json`**
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"viewport": { "width": 390, "height": 844 },
|
|
93
|
+
"deviceScaleFactor": 3,
|
|
94
|
+
"userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1",
|
|
95
|
+
"isMobile": true,
|
|
96
|
+
"hasTouch": true
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
playwright-cli open https://example.com --config=iphone14.json
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**`pixel7.json`**
|
|
105
|
+
```json
|
|
106
|
+
{
|
|
107
|
+
"viewport": { "width": 412, "height": 915 },
|
|
108
|
+
"deviceScaleFactor": 2.625,
|
|
109
|
+
"userAgent": "Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36",
|
|
110
|
+
"isMobile": true,
|
|
111
|
+
"hasTouch": true
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**`ipad-pro.json`**
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"viewport": { "width": 834, "height": 1194 },
|
|
119
|
+
"deviceScaleFactor": 2,
|
|
120
|
+
"userAgent": "Mozilla/5.0 (iPad; CPU OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1",
|
|
121
|
+
"isMobile": true,
|
|
122
|
+
"hasTouch": true
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Programmatic Device Emulation
|
|
127
|
+
|
|
128
|
+
Use `run-code` to check or modify device properties:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# Check current device properties
|
|
132
|
+
playwright-cli run-code "async page => {
|
|
133
|
+
return await page.evaluate(() => ({
|
|
134
|
+
userAgent: navigator.userAgent,
|
|
135
|
+
viewport: { width: window.innerWidth, height: window.innerHeight },
|
|
136
|
+
devicePixelRatio: window.devicePixelRatio,
|
|
137
|
+
touchSupport: 'ontouchstart' in window,
|
|
138
|
+
platform: navigator.platform
|
|
139
|
+
}));
|
|
140
|
+
}"
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Geolocation
|
|
144
|
+
|
|
145
|
+
Override the browser's reported GPS location — test store locators, delivery zones, location-based content.
|
|
146
|
+
|
|
147
|
+
### Set Location
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# New York
|
|
151
|
+
playwright-cli run-code "async page => {
|
|
152
|
+
await page.context().grantPermissions(['geolocation']);
|
|
153
|
+
await page.context().setGeolocation({ latitude: 40.7128, longitude: -74.0060 });
|
|
154
|
+
}"
|
|
155
|
+
|
|
156
|
+
# London
|
|
157
|
+
playwright-cli run-code "async page => {
|
|
158
|
+
await page.context().grantPermissions(['geolocation']);
|
|
159
|
+
await page.context().setGeolocation({ latitude: 51.5074, longitude: -0.1278 });
|
|
160
|
+
}"
|
|
161
|
+
|
|
162
|
+
# Tokyo
|
|
163
|
+
playwright-cli run-code "async page => {
|
|
164
|
+
await page.context().grantPermissions(['geolocation']);
|
|
165
|
+
await page.context().setGeolocation({ latitude: 35.6762, longitude: 139.6503 });
|
|
166
|
+
}"
|
|
167
|
+
|
|
168
|
+
# Sydney
|
|
169
|
+
playwright-cli run-code "async page => {
|
|
170
|
+
await page.context().grantPermissions(['geolocation']);
|
|
171
|
+
await page.context().setGeolocation({ latitude: -33.8688, longitude: 151.2093 });
|
|
172
|
+
}"
|
|
173
|
+
|
|
174
|
+
# São Paulo
|
|
175
|
+
playwright-cli run-code "async page => {
|
|
176
|
+
await page.context().grantPermissions(['geolocation']);
|
|
177
|
+
await page.context().setGeolocation({ latitude: -23.5505, longitude: -46.6333 });
|
|
178
|
+
}"
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Update Location Mid-Session
|
|
182
|
+
|
|
183
|
+
Simulate a user moving between locations:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
# Start in San Francisco
|
|
187
|
+
playwright-cli run-code "async page => {
|
|
188
|
+
await page.context().grantPermissions(['geolocation']);
|
|
189
|
+
await page.context().setGeolocation({ latitude: 37.7749, longitude: -122.4194 });
|
|
190
|
+
}"
|
|
191
|
+
|
|
192
|
+
playwright-cli goto https://example.com/nearby-stores
|
|
193
|
+
playwright-cli screenshot --filename=sf-stores.png
|
|
194
|
+
|
|
195
|
+
# Move to Los Angeles
|
|
196
|
+
playwright-cli run-code "async page => {
|
|
197
|
+
await page.context().setGeolocation({ latitude: 34.0522, longitude: -118.2437 });
|
|
198
|
+
}"
|
|
199
|
+
|
|
200
|
+
playwright-cli reload
|
|
201
|
+
playwright-cli screenshot --filename=la-stores.png
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Clear Geolocation Override
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
playwright-cli run-code "async page => {
|
|
208
|
+
await page.context().clearPermissions();
|
|
209
|
+
}"
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Geolocation via Config
|
|
213
|
+
|
|
214
|
+
Set geolocation when opening the browser:
|
|
215
|
+
|
|
216
|
+
**`geo-nyc.json`**
|
|
217
|
+
```json
|
|
218
|
+
{
|
|
219
|
+
"geolocation": { "latitude": 40.7128, "longitude": -74.0060 },
|
|
220
|
+
"permissions": ["geolocation"]
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
playwright-cli open https://example.com --config=geo-nyc.json
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Locale and Timezone
|
|
229
|
+
|
|
230
|
+
Test internationalization by changing the browser's locale and timezone.
|
|
231
|
+
|
|
232
|
+
### Via Config File
|
|
233
|
+
|
|
234
|
+
**`locale-de.json`**
|
|
235
|
+
```json
|
|
236
|
+
{
|
|
237
|
+
"locale": "de-DE",
|
|
238
|
+
"timezoneId": "Europe/Berlin"
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**`locale-ja.json`**
|
|
243
|
+
```json
|
|
244
|
+
{
|
|
245
|
+
"locale": "ja-JP",
|
|
246
|
+
"timezoneId": "Asia/Tokyo"
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
playwright-cli open https://example.com --config=locale-de.json
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Verify Locale and Timezone
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
playwright-cli run-code "async page => {
|
|
258
|
+
return await page.evaluate(() => ({
|
|
259
|
+
language: navigator.language,
|
|
260
|
+
languages: navigator.languages,
|
|
261
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
262
|
+
dateFormat: new Date('2024-01-15').toLocaleDateString(),
|
|
263
|
+
numberFormat: (1234567.89).toLocaleString(),
|
|
264
|
+
currencyFormat: new Intl.NumberFormat(navigator.language, {
|
|
265
|
+
style: 'currency',
|
|
266
|
+
currency: 'USD'
|
|
267
|
+
}).format(1234.56)
|
|
268
|
+
}));
|
|
269
|
+
}"
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Common Locale + Timezone Combinations
|
|
273
|
+
|
|
274
|
+
| Region | Locale | Timezone |
|
|
275
|
+
|--------|--------|----------|
|
|
276
|
+
| US East | `en-US` | `America/New_York` |
|
|
277
|
+
| US West | `en-US` | `America/Los_Angeles` |
|
|
278
|
+
| UK | `en-GB` | `Europe/London` |
|
|
279
|
+
| Germany | `de-DE` | `Europe/Berlin` |
|
|
280
|
+
| France | `fr-FR` | `Europe/Paris` |
|
|
281
|
+
| Japan | `ja-JP` | `Asia/Tokyo` |
|
|
282
|
+
| China | `zh-CN` | `Asia/Shanghai` |
|
|
283
|
+
| India | `hi-IN` | `Asia/Kolkata` |
|
|
284
|
+
| Brazil | `pt-BR` | `America/Sao_Paulo` |
|
|
285
|
+
| Australia | `en-AU` | `Australia/Sydney` |
|
|
286
|
+
| Arabia | `ar-SA` | `Asia/Riyadh` |
|
|
287
|
+
|
|
288
|
+
## Color Scheme
|
|
289
|
+
|
|
290
|
+
Test dark mode, light mode, and high contrast:
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
# Dark mode
|
|
294
|
+
playwright-cli run-code "async page => {
|
|
295
|
+
await page.emulateMedia({ colorScheme: 'dark' });
|
|
296
|
+
}"
|
|
297
|
+
playwright-cli screenshot --filename=dark-mode.png
|
|
298
|
+
|
|
299
|
+
# Light mode
|
|
300
|
+
playwright-cli run-code "async page => {
|
|
301
|
+
await page.emulateMedia({ colorScheme: 'light' });
|
|
302
|
+
}"
|
|
303
|
+
playwright-cli screenshot --filename=light-mode.png
|
|
304
|
+
|
|
305
|
+
# System preference (no override)
|
|
306
|
+
playwright-cli run-code "async page => {
|
|
307
|
+
await page.emulateMedia({ colorScheme: 'no-preference' });
|
|
308
|
+
}"
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## Reduced Motion
|
|
312
|
+
|
|
313
|
+
Test accessibility for users who prefer reduced motion:
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
# Enable reduced motion
|
|
317
|
+
playwright-cli run-code "async page => {
|
|
318
|
+
await page.emulateMedia({ reducedMotion: 'reduce' });
|
|
319
|
+
}"
|
|
320
|
+
|
|
321
|
+
# Check if your CSS respects it
|
|
322
|
+
playwright-cli run-code "async page => {
|
|
323
|
+
return await page.evaluate(() =>
|
|
324
|
+
window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
325
|
+
);
|
|
326
|
+
}"
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
## Forced Colors (High Contrast)
|
|
330
|
+
|
|
331
|
+
Test Windows High Contrast mode:
|
|
332
|
+
|
|
333
|
+
```bash
|
|
334
|
+
playwright-cli run-code "async page => {
|
|
335
|
+
await page.emulateMedia({ forcedColors: 'active' });
|
|
336
|
+
}"
|
|
337
|
+
playwright-cli screenshot --filename=high-contrast.png
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## Permissions
|
|
341
|
+
|
|
342
|
+
Grant or deny browser permissions:
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
# Grant multiple permissions
|
|
346
|
+
playwright-cli run-code "async page => {
|
|
347
|
+
await page.context().grantPermissions([
|
|
348
|
+
'geolocation',
|
|
349
|
+
'notifications',
|
|
350
|
+
'camera',
|
|
351
|
+
'microphone'
|
|
352
|
+
]);
|
|
353
|
+
}"
|
|
354
|
+
|
|
355
|
+
# Grant for specific origin
|
|
356
|
+
playwright-cli run-code "async page => {
|
|
357
|
+
await page.context().grantPermissions(['notifications'], {
|
|
358
|
+
origin: 'https://example.com'
|
|
359
|
+
});
|
|
360
|
+
}"
|
|
361
|
+
|
|
362
|
+
# Clear all permissions (reset to defaults)
|
|
363
|
+
playwright-cli run-code "async page => {
|
|
364
|
+
await page.context().clearPermissions();
|
|
365
|
+
}"
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
Available permissions: `geolocation`, `notifications`, `camera`, `microphone`, `clipboard-read`, `clipboard-write`, `payment-handler`, `midi`, `midi-sysex`, `ambient-light-sensor`, `accelerometer`, `gyroscope`, `magnetometer`, `background-sync`
|
|
369
|
+
|
|
370
|
+
## Network Condition Emulation
|
|
371
|
+
|
|
372
|
+
Simulate slow networks to test loading states and performance:
|
|
373
|
+
|
|
374
|
+
```bash
|
|
375
|
+
# Simulate slow 3G
|
|
376
|
+
playwright-cli run-code "async page => {
|
|
377
|
+
const client = await page.context().newCDPSession(page);
|
|
378
|
+
await client.send('Network.emulateNetworkConditions', {
|
|
379
|
+
offline: false,
|
|
380
|
+
downloadThroughput: 500 * 1024 / 8, // 500 kbps
|
|
381
|
+
uploadThroughput: 500 * 1024 / 8, // 500 kbps
|
|
382
|
+
latency: 400 // 400ms RTT
|
|
383
|
+
});
|
|
384
|
+
}"
|
|
385
|
+
|
|
386
|
+
# Simulate offline mode
|
|
387
|
+
playwright-cli run-code "async page => {
|
|
388
|
+
const client = await page.context().newCDPSession(page);
|
|
389
|
+
await client.send('Network.emulateNetworkConditions', {
|
|
390
|
+
offline: true,
|
|
391
|
+
downloadThroughput: 0,
|
|
392
|
+
uploadThroughput: 0,
|
|
393
|
+
latency: 0
|
|
394
|
+
});
|
|
395
|
+
}"
|
|
396
|
+
|
|
397
|
+
# Restore normal network
|
|
398
|
+
playwright-cli run-code "async page => {
|
|
399
|
+
const client = await page.context().newCDPSession(page);
|
|
400
|
+
await client.send('Network.emulateNetworkConditions', {
|
|
401
|
+
offline: false,
|
|
402
|
+
downloadThroughput: -1,
|
|
403
|
+
uploadThroughput: -1,
|
|
404
|
+
latency: 0
|
|
405
|
+
});
|
|
406
|
+
}"
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
**Note**: CDP sessions only work with Chromium-based browsers.
|
|
410
|
+
|
|
411
|
+
## Common Patterns
|
|
412
|
+
|
|
413
|
+
### Multi-Device Screenshot Suite
|
|
414
|
+
|
|
415
|
+
```bash
|
|
416
|
+
#!/bin/bash
|
|
417
|
+
URL="https://example.com"
|
|
418
|
+
playwright-cli open $URL
|
|
419
|
+
|
|
420
|
+
devices=("1920:1080:desktop" "768:1024:tablet" "375:812:mobile")
|
|
421
|
+
for device in "${devices[@]}"; do
|
|
422
|
+
IFS=':' read -r w h name <<< "$device"
|
|
423
|
+
playwright-cli resize $w $h
|
|
424
|
+
playwright-cli screenshot --filename="device-$name.png"
|
|
425
|
+
done
|
|
426
|
+
|
|
427
|
+
playwright-cli close
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
### Geo-Based Content Testing
|
|
431
|
+
|
|
432
|
+
```bash
|
|
433
|
+
locations=("40.7128:-74.0060:nyc" "51.5074:-0.1278:london" "35.6762:139.6503:tokyo")
|
|
434
|
+
|
|
435
|
+
for loc in "${locations[@]}"; do
|
|
436
|
+
IFS=':' read -r lat lng name <<< "$loc"
|
|
437
|
+
playwright-cli run-code "async page => {
|
|
438
|
+
await page.context().grantPermissions(['geolocation']);
|
|
439
|
+
await page.context().setGeolocation({ latitude: $lat, longitude: $lng });
|
|
440
|
+
}"
|
|
441
|
+
playwright-cli reload
|
|
442
|
+
playwright-cli screenshot --filename="geo-$name.png"
|
|
443
|
+
done
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
### Accessibility Emulation Suite
|
|
447
|
+
|
|
448
|
+
```bash
|
|
449
|
+
playwright-cli open https://example.com
|
|
450
|
+
|
|
451
|
+
# Standard view
|
|
452
|
+
playwright-cli screenshot --filename=a11y-standard.png
|
|
453
|
+
|
|
454
|
+
# Dark mode
|
|
455
|
+
playwright-cli run-code "async page => { await page.emulateMedia({ colorScheme: 'dark' }); }"
|
|
456
|
+
playwright-cli screenshot --filename=a11y-dark.png
|
|
457
|
+
|
|
458
|
+
# High contrast
|
|
459
|
+
playwright-cli run-code "async page => { await page.emulateMedia({ forcedColors: 'active' }); }"
|
|
460
|
+
playwright-cli screenshot --filename=a11y-high-contrast.png
|
|
461
|
+
|
|
462
|
+
# Reduced motion
|
|
463
|
+
playwright-cli run-code "async page => { await page.emulateMedia({ reducedMotion: 'reduce', forcedColors: 'none' }); }"
|
|
464
|
+
playwright-cli screenshot --filename=a11y-reduced-motion.png
|
|
465
|
+
|
|
466
|
+
playwright-cli close
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
## Tips
|
|
470
|
+
|
|
471
|
+
- **Viewport alone isn't device emulation** — real device testing needs user agent, touch support, and device scale factor via config files
|
|
472
|
+
- **Geolocation requires permission** — always `grantPermissions(['geolocation'])` before `setGeolocation()`
|
|
473
|
+
- **Locale/timezone must be set at open time** — use config files since they can't be changed mid-session
|
|
474
|
+
- **CDP features are Chromium-only** — network throttling via CDP doesn't work in Firefox or WebKit
|
|
475
|
+
- **Test the combination** — dark mode + reduced motion + specific locale together reveals issues that each alone won't catch
|