stably 4.10.3 → 4.10.5

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.
Files changed (39) hide show
  1. package/dist/index.mjs +1 -1
  2. package/dist/stably-plugin-cli/skills/browser-interaction-guide/SKILL.md +21 -0
  3. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/accessibility.md +359 -0
  4. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/annotations.md +526 -0
  5. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/assertions-waiting.md +361 -0
  6. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/browser-apis.md +391 -0
  7. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/browser-extensions.md +506 -0
  8. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/canvas-webgl.md +493 -0
  9. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/ci-cd.md +407 -0
  10. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/clock-mocking.md +364 -0
  11. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/component-testing.md +500 -0
  12. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/console-errors.md +420 -0
  13. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/debugging.md +491 -0
  14. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/electron.md +509 -0
  15. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/error-testing.md +360 -0
  16. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/file-operations.md +375 -0
  17. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/fixtures-hooks.md +417 -0
  18. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/flaky-tests.md +494 -0
  19. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/global-setup.md +434 -0
  20. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/i18n.md +508 -0
  21. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/iframes.md +403 -0
  22. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/locators.md +242 -0
  23. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/mobile-testing.md +409 -0
  24. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/multi-context.md +288 -0
  25. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/multi-user.md +393 -0
  26. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/network-advanced.md +452 -0
  27. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/page-object-model.md +315 -0
  28. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/performance-testing.md +476 -0
  29. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/performance.md +453 -0
  30. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/projects-dependencies.md +456 -0
  31. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/security-testing.md +430 -0
  32. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/service-workers.md +504 -0
  33. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/test-coverage.md +495 -0
  34. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/test-data.md +492 -0
  35. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/test-organization.md +361 -0
  36. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/third-party.md +464 -0
  37. package/dist/stably-plugin-cli/skills/playwright-best-practices/references/websockets.md +403 -0
  38. package/dist/stably-plugin-cli/skills/stably-cli/SKILL.md +254 -0
  39. package/package.json +2 -2
@@ -0,0 +1,491 @@
1
+ # Debugging & Troubleshooting
2
+
3
+ ## Table of Contents
4
+
5
+ 1. [Debug Tools](#debug-tools)
6
+ 2. [Trace Viewer](#trace-viewer)
7
+ 3. [Identifying Flaky Tests](#identifying-flaky-tests)
8
+ 4. [Debugging Network Issues](#debugging-network-issues)
9
+ 5. [Debugging in CI](#debugging-in-ci)
10
+ 6. [Debugging Authentication](#debugging-authentication)
11
+ 7. [Debugging Screenshots](#debugging-screenshots)
12
+ 8. [Common Issues](#common-issues)
13
+ 9. [Logging](#logging)
14
+
15
+ ## Debug Tools
16
+
17
+ ### Playwright Inspector
18
+
19
+ ```bash
20
+ # Run with inspector
21
+ PWDEBUG=1 npx playwright test
22
+ # Or specific test
23
+ PWDEBUG=1 npx playwright test login.spec.ts
24
+ ```
25
+
26
+ Features:
27
+
28
+ - Step through test actions
29
+ - Pick locators visually
30
+ - Inspect DOM state
31
+ - Edit and re-run
32
+
33
+ ### Headed Mode
34
+
35
+ ```bash
36
+ # Run with visible browser
37
+ npx playwright test --headed
38
+
39
+ # Slow down execution
40
+ npx playwright test --headed --slow-motion=500
41
+ ```
42
+
43
+ ### UI Mode
44
+
45
+ ```bash
46
+ # Interactive test runner
47
+ npx playwright test --ui
48
+ ```
49
+
50
+ Features:
51
+
52
+ - Watch mode
53
+ - Test timeline
54
+ - DOM snapshots
55
+ - Network logs
56
+ - Console logs
57
+
58
+ ### Debug in Code
59
+
60
+ ```typescript
61
+ test("debug example", async ({ page }) => {
62
+ await page.goto("/");
63
+
64
+ // Pause and open inspector
65
+ await page.pause();
66
+
67
+ // Continue test...
68
+ await page.click("button");
69
+ });
70
+ ```
71
+
72
+ ## Trace Viewer
73
+
74
+ ### Enable Traces
75
+
76
+ ```typescript
77
+ // playwright.config.ts
78
+ export default defineConfig({
79
+ use: {
80
+ trace: "on-first-retry", // Record on retry
81
+ // trace: 'on', // Always record
82
+ // trace: 'retain-on-failure', // Keep only failures
83
+ },
84
+ });
85
+ ```
86
+
87
+ ### View Traces
88
+
89
+ ```bash
90
+ # Open trace file
91
+ npx playwright show-trace trace.zip
92
+
93
+ # From test-results
94
+ npx playwright show-trace test-results/test-name/trace.zip
95
+ ```
96
+
97
+ ### Trace Contents
98
+
99
+ - Screenshots at each action
100
+ - DOM snapshots
101
+ - Network requests/responses
102
+ - Console logs
103
+ - Action timeline
104
+ - Source code
105
+
106
+ ### Programmatic Traces
107
+
108
+ ```typescript
109
+ test("manual trace", async ({ page, context }) => {
110
+ await context.tracing.start({ screenshots: true, snapshots: true });
111
+
112
+ await page.goto("/");
113
+ await page.click("button");
114
+
115
+ await context.tracing.stop({ path: "trace.zip" });
116
+ });
117
+ ```
118
+
119
+ ## Identifying Flaky Tests
120
+
121
+ If a test fails intermittently, it's likely flaky. Quick checks:
122
+
123
+ | Behavior | Likely Cause | Next Step |
124
+ | -------------------------------------- | ----------------------------- | -------------------------------------- |
125
+ | Fails sometimes, passes other times | Flaky - timing/race condition | [flaky-tests.md](flaky-tests.md) |
126
+ | Fails only with multiple workers | Flaky - parallelism/isolation | [flaky-tests.md](flaky-tests.md) |
127
+ | Fails only in CI | Environment difference | [CI Debugging](#debugging-in-ci) below |
128
+ | Always fails | Bug in test or app | Debug with tools above |
129
+ | Always passes locally, always fails CI | CI-specific issue | [ci-cd.md](ci-cd.md) |
130
+
131
+ > **For flaky test detection commands, root cause analysis, and fixing strategies**, see [flaky-tests.md](flaky-tests.md).
132
+
133
+ ## Debugging Network Issues
134
+
135
+ ### Monitor All Requests
136
+
137
+ ```typescript
138
+ test("debug network", async ({ page }) => {
139
+ const requests: string[] = [];
140
+ const failures: string[] = [];
141
+
142
+ page.on("request", (req) => requests.push(`>> ${req.method()} ${req.url()}`));
143
+ page.on("requestfinished", (req) => {
144
+ const resp = req.response();
145
+ requests.push(`<< ${resp?.status()} ${req.url()}`);
146
+ });
147
+ page.on("requestfailed", (req) => {
148
+ failures.push(`FAILED: ${req.url()} - ${req.failure()?.errorText}`);
149
+ });
150
+
151
+ await page.goto("/dashboard");
152
+
153
+ // Log summary
154
+ console.log("Requests:", requests.length);
155
+ if (failures.length) console.log("Failures:", failures);
156
+ });
157
+ ```
158
+
159
+ ### Wait for Specific API Response
160
+
161
+ When debugging network-dependent issues, wait for specific API responses instead of arbitrary timeouts.
162
+
163
+ ```typescript
164
+ // Start waiting BEFORE triggering the request
165
+ const responsePromise = page.waitForResponse(
166
+ (resp) => resp.url().includes("/api/data") && resp.status() === 200,
167
+ );
168
+ await page.getByRole("button", { name: "Load" }).click();
169
+ const response = await responsePromise;
170
+ console.log("Status:", response.status());
171
+ ```
172
+
173
+ > **For comprehensive waiting patterns** (navigation, element state, network, polling), see [assertions-waiting.md](assertions-waiting.md#waiting-strategies).
174
+
175
+ ### Debug Slow Requests
176
+
177
+ ```typescript
178
+ test("find slow requests", async ({ page }) => {
179
+ page.on("requestfinished", (request) => {
180
+ const timing = request.timing();
181
+ const total = timing.responseEnd - timing.requestStart;
182
+ if (total > 1000) {
183
+ console.log(`SLOW (${total}ms): ${request.url()}`);
184
+ }
185
+ });
186
+
187
+ await page.goto("/");
188
+ });
189
+ ```
190
+
191
+ ## Debugging in CI
192
+
193
+ ### Simulate CI Locally
194
+
195
+ ```bash
196
+ # Run in headless mode like CI
197
+ CI=true npx playwright test --headed=false
198
+
199
+ # Match CI browser versions
200
+ npx playwright install --with-deps
201
+
202
+ # Run in Docker (same as CI)
203
+ docker run --rm -v $(pwd):/work -w /work \
204
+ mcr.microsoft.com/playwright:v1.40.0-jammy \
205
+ npx playwright test
206
+ ```
207
+
208
+ ### CI-Specific Configuration
209
+
210
+ ```typescript
211
+ // playwright.config.ts
212
+ export default defineConfig({
213
+ // More artifacts in CI for debugging
214
+ use: {
215
+ trace: process.env.CI ? "on-first-retry" : "off",
216
+ video: process.env.CI ? "retain-on-failure" : "off",
217
+ screenshot: process.env.CI ? "only-on-failure" : "off",
218
+ },
219
+
220
+ // More retries in CI (but investigate failures!)
221
+ retries: process.env.CI ? 2 : 0,
222
+ });
223
+ ```
224
+
225
+ ### Debug CI Environment
226
+
227
+ ```typescript
228
+ test("CI environment check", async ({ page }, testInfo) => {
229
+ console.log("CI:", process.env.CI);
230
+ console.log("Project:", testInfo.project.name);
231
+ console.log("Worker:", testInfo.workerIndex);
232
+ console.log("Retry:", testInfo.retry);
233
+ console.log("Base URL:", testInfo.project.use.baseURL);
234
+
235
+ // Check viewport
236
+ const viewport = page.viewportSize();
237
+ console.log("Viewport:", viewport);
238
+ });
239
+ ```
240
+
241
+ ## Debugging Authentication
242
+
243
+ ```typescript
244
+ test("debug auth", async ({ page, context }) => {
245
+ // Inspect current storage state
246
+ const storage = await context.storageState();
247
+ console.log(
248
+ "Cookies:",
249
+ storage.cookies.map((c) => c.name),
250
+ );
251
+
252
+ // Check if auth cookies are present
253
+ const cookies = await context.cookies();
254
+ const authCookie = cookies.find((c) => c.name.includes("session"));
255
+ console.log("Auth cookie:", authCookie ? "present" : "MISSING");
256
+
257
+ await page.goto("/protected");
258
+
259
+ // Check if redirected to login (auth failed)
260
+ if (page.url().includes("/login")) {
261
+ console.error("Auth failed - redirected to login");
262
+ // Save state for inspection
263
+ await context.storageState({ path: "debug-auth.json" });
264
+ }
265
+ });
266
+ ```
267
+
268
+ ## Debugging Screenshots
269
+
270
+ ### Compare Visual State
271
+
272
+ ```typescript
273
+ test("visual debug", async ({ page }, testInfo) => {
274
+ await page.goto("/");
275
+
276
+ // Screenshot before action
277
+ await page.screenshot({
278
+ path: testInfo.outputPath("before.png"),
279
+ fullPage: true,
280
+ });
281
+
282
+ await page.getByRole("button", { name: "Open Menu" }).click();
283
+
284
+ // Screenshot after action
285
+ await page.screenshot({
286
+ path: testInfo.outputPath("after.png"),
287
+ fullPage: true,
288
+ });
289
+
290
+ // Attach to report
291
+ await testInfo.attach("before", {
292
+ path: testInfo.outputPath("before.png"),
293
+ contentType: "image/png",
294
+ });
295
+ });
296
+ ```
297
+
298
+ ### Screenshot Specific Element
299
+
300
+ ```typescript
301
+ test("element screenshot", async ({ page }) => {
302
+ await page.goto("/");
303
+
304
+ const element = page.getByTestId("problem-area");
305
+
306
+ // Screenshot just the element
307
+ await element.screenshot({ path: "element-debug.png" });
308
+
309
+ // Highlight element in full page screenshot
310
+ await element.evaluate((el) => (el.style.border = "3px solid red"));
311
+ await page.screenshot({ path: "highlighted.png" });
312
+ });
313
+ ```
314
+
315
+ ## Common Issues
316
+
317
+ ### Element Not Found
318
+
319
+ ```typescript
320
+ // Debug: Check if element exists
321
+ console.log(await page.getByRole("button").count());
322
+
323
+ // Debug: Log all buttons
324
+ const buttons = await page.getByRole("button").all();
325
+ for (const button of buttons) {
326
+ console.log(await button.textContent());
327
+ }
328
+
329
+ // Debug: Screenshot before action
330
+ await page.screenshot({ path: "debug.png" });
331
+ await page.getByRole("button").click();
332
+ ```
333
+
334
+ ### Timeout Issues
335
+
336
+ ```typescript
337
+ // Increase timeout for slow operations
338
+ await expect(page.getByText("Loaded")).toBeVisible({ timeout: 30000 });
339
+
340
+ // Global timeout increase
341
+ test.setTimeout(60000);
342
+
343
+ // Check what's blocking
344
+ test("debug timeout", async ({ page }) => {
345
+ await page.goto("/slow-page");
346
+
347
+ // Log network activity
348
+ page.on("request", (request) => console.log(">>", request.url()));
349
+ page.on("response", (response) =>
350
+ console.log("<<", response.url(), response.status()),
351
+ );
352
+ });
353
+ ```
354
+
355
+ ### Selector Issues
356
+
357
+ ```typescript
358
+ // Debug: Highlight element
359
+ await page.getByRole("button").highlight();
360
+
361
+ // Debug: Evaluate selector in browser console
362
+ // Run in Inspector console:
363
+ // playwright.locator('button').first().highlight()
364
+
365
+ // Debug: Get element info
366
+ const element = page.getByRole("button");
367
+ console.log("Count:", await element.count());
368
+ console.log("Visible:", await element.isVisible());
369
+ console.log("Enabled:", await element.isEnabled());
370
+ ```
371
+
372
+ ### Frame Issues
373
+
374
+ ```typescript
375
+ // Debug: List all frames
376
+ for (const frame of page.frames()) {
377
+ console.log("Frame:", frame.url());
378
+ }
379
+
380
+ // Debug: Check if element is in iframe
381
+ const frame = page.frameLocator("iframe").first();
382
+ console.log(await frame.getByRole("button").count());
383
+ ```
384
+
385
+ ## Logging
386
+
387
+ ### Capture Browser Console
388
+
389
+ ```typescript
390
+ test("with logging", async ({ page }) => {
391
+ page.on("console", (msg) => console.log("Browser:", msg.text()));
392
+ page.on("pageerror", (error) => console.log("Page error:", error.message));
393
+ await page.goto("/");
394
+ });
395
+ ```
396
+
397
+ > **For comprehensive console error handling** (fail on errors, allowed patterns, fixtures), see [console-errors.md](console-errors.md).
398
+
399
+ ### Custom Test Attachments
400
+
401
+ ```typescript
402
+ test("with attachments", async ({ page }, testInfo) => {
403
+ // Attach screenshot to report
404
+ const screenshot = await page.screenshot();
405
+ await testInfo.attach("screenshot", {
406
+ body: screenshot,
407
+ contentType: "image/png",
408
+ });
409
+
410
+ // Attach logs or data
411
+ await testInfo.attach("logs", {
412
+ body: "Custom log data",
413
+ contentType: "text/plain",
414
+ });
415
+
416
+ // Use testInfo for output paths
417
+ const outputPath = testInfo.outputPath("debug-file.json");
418
+ });
419
+ ```
420
+
421
+ ## Troubleshooting Checklist
422
+
423
+ ### By Symptom
424
+
425
+ | Symptom | Common Causes | Quick Fixes | Reference |
426
+ | --------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------------- | -------------------------------------------------------------------------- |
427
+ | **Element not found** | Wrong selector, element not visible, in iframe, timing issue | Check locator with Inspector, wait for visibility, use frameLocator | [locators.md](locators.md), [assertions-waiting.md](assertions-waiting.md) |
428
+ | **Timeout errors** | Slow network, heavy page load, waiting for wrong condition | Increase timeout, wait for specific response, check network tab | [assertions-waiting.md](assertions-waiting.md) |
429
+ | **Flaky tests** | Race conditions, shared state, timing dependencies | See comprehensive flaky test guide | [flaky-tests.md](flaky-tests.md) |
430
+ | **Tests pass locally, fail in CI** | Environment differences, missing dependencies, timing | Simulate CI locally, check CI logs, verify environment vars | [ci-cd.md](ci-cd.md), [flaky-tests.md](flaky-tests.md) |
431
+ | **Slow test execution** | Not parallelized, heavy network calls, unnecessary waits | Enable parallelization, mock APIs, optimize waits | [performance.md](performance.md) |
432
+ | **Selector works in browser but not in test** | Element not attached, wrong context, dynamic content | Use auto-waiting, check iframe, verify element state | [locators.md](locators.md) |
433
+ | **Test fails on retry** | Non-deterministic data, external dependencies | Use test data fixtures, mock external services | [fixtures-hooks.md](fixtures-hooks.md) |
434
+
435
+ ### Step-by-Step Debugging Process
436
+
437
+ 1. **Reproduce the issue**
438
+
439
+ ```bash
440
+ # Run with trace enabled
441
+ npx playwright test tests/failing.spec.ts --trace on
442
+
443
+ # If intermittent, run multiple times
444
+ npx playwright test --repeat-each=10
445
+ ```
446
+
447
+ 2. **Inspect the failure**
448
+
449
+ ```bash
450
+ # View trace
451
+ npx playwright show-trace test-results/path-to-trace.zip
452
+
453
+ # Run in headed mode to watch
454
+ npx playwright test --headed
455
+
456
+ # Use inspector for step-by-step
457
+ PWDEBUG=1 npx playwright test
458
+ ```
459
+
460
+ 3. **Isolate the problem**
461
+
462
+ ```typescript
463
+ // Add debugging points
464
+ await page.pause();
465
+
466
+ // Log element state
467
+ console.log("Element count:", await page.getByRole("button").count());
468
+ console.log("Element visible:", await page.getByRole("button").isVisible());
469
+
470
+ // Take screenshot at failure point
471
+ await page.screenshot({ path: "debug.png" });
472
+ ```
473
+
474
+ 4. **Check related areas**
475
+ - Network requests: Are API calls completing? (see [Debugging Network Issues](#debugging-network-issues))
476
+ - Timing: Is auto-waiting working correctly?
477
+ - State: Is the test isolated? (see [flaky-tests.md](flaky-tests.md))
478
+ - Environment: Does it work locally but fail in CI? (see [Debugging in CI](#debugging-in-ci))
479
+
480
+ 5. **Apply fix and verify**
481
+ - Fix the root cause (not just symptoms)
482
+ - Run multiple times to confirm stability: `--repeat-each=10`
483
+ - Check related tests aren't affected
484
+
485
+ ## Related References
486
+
487
+ - **Flaky tests**: See [flaky-tests.md](flaky-tests.md) for comprehensive flaky test guide
488
+ - **Locator issues**: See [locators.md](locators.md) for selector strategies
489
+ - **Waiting problems**: See [assertions-waiting.md](assertions-waiting.md) for waiting patterns
490
+ - **Test isolation**: See [fixtures-hooks.md](fixtures-hooks.md) for fixtures and isolation
491
+ - **CI issues**: See [ci-cd.md](ci-cd.md) for CI configuration