@andrii_kremlovskyi/playwright-traces-reader 1.3.2 → 2.1.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.
@@ -1,393 +1,162 @@
1
1
  ---
2
2
  name: analyze-playwright-traces
3
- description: Analyze Playwright test traces to find test failures, extract network request/response payloads, identify slow steps, locate UI screenshots, and inspect DOM state before/during/after each browser action.
3
+ description: Analyze Playwright reports and traces using the playwright-traces-reader CLI to find failures, inspect single-test summaries, review network traffic, inspect DOM snapshots, extract screenshots, and build trace timelines.
4
4
  ---
5
5
 
6
6
  # Analyze Playwright Traces
7
7
 
8
- Use this skill when the user asks about test failures, API payloads in tests, slow steps, or UI screenshots from Playwright test runs.
8
+ Use this skill when the user asks to analyze Playwright reports or traces.
9
+
10
+ ## Rules
11
+
12
+ - Use only supported `npx playwright-traces-reader ...` CLI commands.
13
+ - Do not generate temporary `.mjs`, `.js`, or `.ts` analysis scripts.
14
+ - Do not import parser methods directly when a CLI command covers the workflow.
15
+ - JSON is the default output mode. Use `--format text` only when a human-readable terminal summary is preferable.
16
+ - Use screenshots only for human visual inspection. For agent-readable UI state, prefer `dom` and `summary`.
9
17
 
10
18
  ## Prerequisites
11
19
 
12
- This skill requires the `@andrii_kremlovskyi/playwright-traces-reader` npm package in the project:
20
+ Install the package locally in the repository:
21
+
13
22
  ```bash
14
23
  npm install @andrii_kremlovskyi/playwright-traces-reader
15
24
  ```
16
25
 
17
- And a built trace directory under `playwright-report/data/<sha1>/` (or a `.zip` of the same).
18
-
19
- ## How to Use
20
-
21
- ### 1. Find failed tests
26
+ Supported local inputs:
22
27
 
23
- Use `getFailedTestSummaries()` — a single call that returns `TraceSummary[]` for every **unique** failing test in a report. It handles three tricky cases internally:
28
+ - a Playwright report root containing `index.html` and `data/`
29
+ - a `playwright-report/data/` directory
30
+ - a single extracted trace directory
31
+ - a single trace zip
24
32
 
25
- - **Passing tests** skipped cheaply (no full summary built)
26
- - **Retries** deduplicated by the full unique title from `context-options` (spec path + describe + test name). The **last retry** is used — highest root step `endTime` — so the summary reflects the most recent execution with the most relevant DOM snapshot and network traffic
27
- - **Pure API traces** (no browser context) deduplicated by trace directory name
28
-
29
- ```typescript
30
- import { getFailedTestSummaries } from '@andrii_kremlovskyi/playwright-traces-reader';
31
-
32
- const failures = await getFailedTestSummaries('/path/to/playwright-report/data');
33
- // failures.length = number of distinct failing tests
34
- // Retries and passing tests are already excluded
35
- // Each result has an `outcome` field: 'unexpected' | 'flaky' | 'skipped' | null
36
-
37
- console.log(`Unique failed tests: ${failures.length}`);
38
- for (const f of failures) {
39
- console.log(`[${f.outcome ?? 'unknown'}] ${f.testTitle ?? f.title}`);
40
- console.log(`Error: ${f.error?.message}`);
41
- }
42
- ```
33
+ ## Command Selection
43
34
 
44
- Each returned `TraceSummary` has an `outcome` field (`'unexpected'`, `'flaky'`, `'skipped'`, or `null`) populated from `report.json` when `index.html` is available alongside the trace data. Results are deduplicated by `testId` from `report.json` (falls back to `testTitle` then `traceDir`). You can filter by outcome on the caller side, or pass `{ excludeSkipped: true }` to exclude skipped tests automatically.
35
+ ### Report-level analysis
45
36
 
46
- ```typescript
47
- import { getFailedTestSummaries } from '@andrii_kremlovskyi/playwright-traces-reader';
37
+ Use `failures` when the user wants all unique failing tests in a report.
48
38
 
49
- // Option A: get all non-passing results and filter by outcome
50
- const all = await getFailedTestSummaries('/path/to/playwright-report/data');
51
- const failed = all.filter(f => f.outcome === 'unexpected');
52
- const skipped = all.filter(f => f.outcome === 'skipped');
53
- const flaky = all.filter(f => f.outcome === 'flaky');
54
-
55
- // Option B: exclude skipped tests automatically
56
- const failures = await getFailedTestSummaries('/path/to/playwright-report/data', { excludeSkipped: true });
57
- // pre-annotated skips (suite annotations / conditional test.skip(condition)) are always excluded
39
+ ```bash
40
+ npx playwright-traces-reader failures /path/to/playwright-report
58
41
  ```
59
42
 
60
- ### 2. Inspect failure details
61
-
62
- Each item returned by `getFailedTestSummaries()` is a `TraceSummary` — it already contains everything needed for failure analysis. No second call required.
63
-
64
- ```typescript
65
- import { getFailedTestSummaries } from '@andrii_kremlovskyi/playwright-traces-reader';
66
-
67
- const failures = await getFailedTestSummaries('/path/to/playwright-report/data');
68
-
69
- for (const f of failures) {
70
- console.log(`[FAILED] ${f.testTitle ?? f.title}`);
71
- console.log(`Duration: ${f.durationMs}ms`);
72
- console.log(`Error: ${f.error?.message}`);
73
-
74
- console.log('Test steps:');
75
- for (const step of f.topLevelSteps) {
76
- const failed = step.error ? ' ✗' : '';
77
- console.log(` ${step.title} (${step.durationMs}ms)${failed}`);
78
- }
79
-
80
- console.log('Slowest 5 steps:');
81
- for (const step of f.slowestSteps) {
82
- console.log(` ${step.durationMs}ms — ${step.title}`);
83
- }
84
-
85
- console.log(`Network calls: ${f.networkCalls.length}`);
86
- for (const call of f.networkCalls) {
87
- console.log(` ${call.method} ${call.url} → ${call.status}`);
88
- }
89
-
90
- if (f.failureDomSnapshot?.after) {
91
- // DOM state at the time of failure — AI-readable HTML
92
- console.log('DOM at failure:', f.failureDomSnapshot.after.html.slice(0, 500));
93
- }
94
-
95
- // Drill into the nested step tree to find the specific failing assertion/action
96
- function collectErrors(steps, out = []) {
97
- for (const s of steps) {
98
- if (s.error) out.push(s);
99
- collectErrors(s.children, out);
100
- }
101
- return out;
102
- }
103
- const deepFailures = f.topLevelSteps.flatMap(s => collectErrors(s.children));
104
- for (const s of deepFailures) {
105
- console.log(` nested failure: ${s.title} — ${s.error.message}`);
106
- }
107
- }
108
- ```
43
+ Use `--exclude-skipped` to omit skipped tests:
109
44
 
110
- `TraceSummary` fields:
111
- - **`testTitle`** — **full unique test title** from `context-options` (spec path + describe + test name). Use for display. `null` for pure API traces with no browser context.
112
- - **`title`** — root `test.step()` title (from `test.trace`). The failing step or longest non-hook step.
113
- - **`outcome`** — `'expected'` | `'unexpected'` | `'flaky'` | `'skipped'` | `null`. Populated from `report.json` when `reportMetadata` is passed to `getSummary()` or automatically by `getFailedTestSummaries()`; `null` when report metadata is unavailable.
114
- - **`status`** — `'passed'` | `'failed'`
115
- - **`durationMs`** — duration of the main test step
116
- - **`error`** — the top-level error, or `null` if passed
117
- - **`topLevelSteps`** — non-hook root steps (the visible `test.step()` blocks), each with `.children` for drilling down
118
- - **`slowestSteps`** — top 5 slowest steps across the full step tree
119
- - **`networkCalls`** — all HTTP calls made during the test (`source: 'api'` = Node.js `APIRequestContext`; `source: 'browser'` = XHR / fetch / navigation)
120
- - **`failureDomSnapshot`** — `ActionDomSnapshots` closest in time to the failure, or `null`
121
-
122
- ### 3. Find slow steps
123
-
124
- ```typescript
125
- import { prepareTraceDir, getTestSteps } from '@andrii_kremlovskyi/playwright-traces-reader';
126
-
127
- const ctx = await prepareTraceDir('/path/to/trace-dir');
128
- const steps = await getTestSteps(ctx);
129
-
130
- function flatten(steps: TestStep[], out: TestStep[] = []): TestStep[] {
131
- for (const s of steps) { out.push(s); flatten(s.children, out); }
132
- return out;
133
- }
134
-
135
- const allSteps = flatten(steps);
136
- const sorted = allSteps
137
- .filter(s => s.durationMs !== null)
138
- .sort((a, b) => (b.durationMs ?? 0) - (a.durationMs ?? 0));
139
-
140
- console.log('Top 5 slowest steps:');
141
- sorted.slice(0, 5).forEach(s => console.log(` ${s.durationMs}ms — ${s.title}`));
45
+ ```bash
46
+ npx playwright-traces-reader failures /path/to/playwright-report/data --exclude-skipped
142
47
  ```
143
48
 
144
- > **Shortcut**: `getSummary()` already returns the top 5 slowest steps in `summary.slowestSteps` — no manual flattening needed.
49
+ What it returns:
145
50
 
146
- ### 4. Extract network traffic
51
+ - unique failing tests only
52
+ - retries already deduplicated
53
+ - compact triage records with `tracePath` and `traceSha1`
54
+ - enough information to follow up with `summary <tracePath>` for one selected failure
147
55
 
148
- ```typescript
149
- import { prepareTraceDir, getNetworkTraffic } from '@andrii_kremlovskyi/playwright-traces-reader';
56
+ ### Single-trace summary
150
57
 
151
- const ctx = await prepareTraceDir('/path/to/trace-dir');
152
- const traffic = await getNetworkTraffic(ctx);
58
+ Use `summary` when the user wants one complete summary for a specific trace.
153
59
 
154
- for (const call of traffic) {
155
- console.log(`[${call.source}] ${call.method} ${call.url} → ${call.status}`);
156
- if (call.responseBody) console.log('Response:', call.responseBody.slice(0, 500));
157
- }
158
-
159
- // Filter by source if needed:
160
- const apiOnly = traffic.filter(e => e.source === 'api'); // Node.js APIRequestContext
161
- const browserOnly = traffic.filter(e => e.source === 'browser'); // XHR / fetch / navigation
60
+ ```bash
61
+ npx playwright-traces-reader summary /path/to/playwright-report/data/<sha1>
162
62
  ```
163
63
 
164
- ### 5. Extract screenshots for human visual inspection
165
-
166
- > **AI agent limitation**: AI agents cannot read or understand JPEG/PNG image files from disk. `extractScreenshots()` is for **human visual inspection only** — open the `savedPath` files in your image viewer. For AI analysis of UI state, use `getDomSnapshots()` (section 6), which returns full HTML that an AI can read and reason about.
167
-
168
- ```typescript
169
- import { prepareTraceDir, extractScreenshots } from '@andrii_kremlovskyi/playwright-traces-reader';
170
- import * as os from 'os';
64
+ If report metadata should be loaded explicitly, pass `--report`:
171
65
 
172
- const ctx = await prepareTraceDir('/path/to/trace-dir');
173
- const screenshots = await extractScreenshots(ctx, `${os.tmpdir()}/pw-screenshots`);
174
-
175
- for (const s of screenshots) {
176
- console.log(`Screenshot at ${s.timestamp}ms: ${s.savedPath}`);
177
- }
178
- // Open savedPath files in an image viewer for visual inspection
179
- // An AI agent cannot interpret these files — use getDomSnapshots() for AI analysis
66
+ ```bash
67
+ npx playwright-traces-reader summary /path/to/playwright-report/data/<sha1> --report /path/to/playwright-report
180
68
  ```
181
69
 
182
- ### 6. Inspect DOM state before/during/after each action
183
-
184
- `getDomSnapshots()` accepts an optional `options` argument to filter the results — especially useful for long traces with many snapshots.
70
+ Important behavior:
185
71
 
186
- ```typescript
187
- import { prepareTraceDir, getDomSnapshots } from '@andrii_kremlovskyi/playwright-traces-reader';
72
+ - `summary` works for both passed and failed traces
73
+ - failed traces may include `failureDomSnapshot`
74
+ - passed traces return `status: "passed"` and `failureDomSnapshot: null`
188
75
 
189
- const ctx = await prepareTraceDir('/path/to/trace-dir');
76
+ ### Slow steps
190
77
 
191
- // Full list (may be large — 40+ entries per trace)
192
- const all = await getDomSnapshots(ctx);
78
+ Use `slow-steps` to inspect the slowest steps in one trace.
193
79
 
194
- // Most useful for AI failure analysis: just the last 3 actions before the test ended
195
- const last3 = await getDomSnapshots(ctx, { near: 'last', limit: 3 });
80
+ ```bash
81
+ npx playwright-traces-reader slow-steps /path/to/playwright-report/data/<sha1> --limit 5
82
+ ```
196
83
 
197
- // Window of 5 entries around a specific action (e.g. from getSummary().failureDomSnapshot.callId)
198
- const window = await getDomSnapshots(ctx, { near: 'call@585', limit: 5 });
84
+ ### Step tree
199
85
 
200
- // Only 'after' phase snapshots (post-action DOM state, most useful for debugging)
201
- const afterOnly = await getDomSnapshots(ctx, { phase: 'after' });
86
+ Use `steps` to inspect the reconstructed test step hierarchy.
202
87
 
203
- for (const action of last3) {
204
- const snap = action.after ?? action.before;
205
- if (!snap) continue;
206
- console.log(`callId: ${action.callId} | url: ${snap.frameUrl}`);
207
- if (snap.targetElement) {
208
- console.log(` targeted element (callId attr): ${snap.targetElement}`);
209
- }
210
- console.log(` DOM snippet: ${snap.html.slice(0, 300)}`);
211
- }
88
+ ```bash
89
+ npx playwright-traces-reader steps /path/to/playwright-report/data/<sha1>
212
90
  ```
213
91
 
214
- `DomSnapshotOptions`:
215
- - `near: 'last'` — return the last `limit` entries (default 5). Best for "what was the page doing just before it failed?"
216
- - `near: 'call@N'` — return a window of `limit` entries centred on that callId
217
- - `phase: 'before' | 'action' | 'after'` — filter to one snapshot phase
218
- - `limit: number` — max entries to return; meaning varies by `near` (see above), or caps from the beginning when `near` is omitted
219
-
220
- Each `DomSnapshot` includes:
221
- - `html` — full serialized HTML string (back-references resolved, `<script>` tags stripped)
222
- - `phase` — `"before"` | `"action"` | `"after"`
223
- - `frameUrl` — URL of the page frame at snapshot time
224
- - `targetElement` — `callId` of the action that targeted an element (from `__playwright_target__` attr), or `null`
225
- - `viewport` — `{ width, height }` at snapshot time
226
-
227
- ### 7. Get a merged chronological timeline
228
-
229
- `getTimeline()` merges all event types into a single chronologically sorted array, eliminating the need for manual timestamp correlation across four separate API calls.
230
-
231
- ```typescript
232
- import { prepareTraceDir, getTimeline } from '@andrii_kremlovskyi/playwright-traces-reader';
233
- import type { TestStep, ScreenshotMetadata, ActionDomSnapshots, NetworkEntry } from '@andrii_kremlovskyi/playwright-traces-reader';
234
-
235
- const ctx = await prepareTraceDir('/path/to/trace-dir');
236
- const timeline = await getTimeline(ctx);
237
-
238
- for (const entry of timeline) {
239
- switch (entry.type) {
240
- case 'step': {
241
- const step = entry.data as TestStep;
242
- console.log(`[step] ${step.title} (${step.durationMs}ms)`);
243
- break;
244
- }
245
- case 'screenshot': {
246
- const shot = entry.data as ScreenshotMetadata;
247
- // No savedPath — call extractScreenshots() if you need the files
248
- console.log(`[screenshot] sha1=${shot.sha1}`);
249
- break;
250
- }
251
- case 'dom': {
252
- const dom = entry.data as ActionDomSnapshots;
253
- console.log(`[dom] callId=${dom.callId}`);
254
- break;
255
- }
256
- case 'network': {
257
- const net = entry.data as NetworkEntry;
258
- console.log(`[network] ${net.method} ${net.url} → ${net.status}`);
259
- break;
260
- }
261
- }
262
- }
263
-
264
- // Focus on the last events before the test ended
265
- for (const entry of timeline.slice(-10)) {
266
- console.log(`[${entry.type}] @${entry.timestamp}`);
267
- }
268
- ```
92
+ ### Network traffic
269
93
 
270
- `TimelineEntry` fields:
271
- - `timestamp` — wall-clock time in milliseconds since epoch
272
- - `type` — `'step'` | `'screenshot'` | `'dom'` | `'network'`
273
- - `data` — cast based on `type` (see above)
94
+ Use `network` to inspect API and browser traffic for one trace.
274
95
 
275
- > Note: screenshot entries in the timeline are `ScreenshotMetadata` (no `savedPath`). Screenshots are metadata-only to avoid unexpected disk writes. Call `extractScreenshots()` separately if you need the files.
96
+ ```bash
97
+ npx playwright-traces-reader network /path/to/playwright-report/data/<sha1> --source all
98
+ ```
276
99
 
277
- ## Locating Trace Directories
100
+ Source filters:
278
101
 
279
- A Playwright report's `data/` directory holds **one SHA1 entry per test execution** (including retries). `getFailedTestSummaries()` handles this automatically. For lower-level iteration use `listTraces()`:
102
+ - `all`
103
+ - `api`
104
+ - `browser`
280
105
 
281
- ```typescript
282
- import { listTraces, getSummary, getReportMetadata, buildReportTraceMaps } from '@andrii_kremlovskyi/playwright-traces-reader';
106
+ ### DOM snapshots
283
107
 
284
- // Works for 1 test or many — automatically discovers all SHA1 trace entries (dirs and zips)
285
- const traces = await listTraces('/path/to/playwright-report/data');
286
- const meta = await getReportMetadata('/path/to/playwright-report/data');
287
- // Pre-build maps once for the loop to avoid redundant work
288
- const maps = meta ? buildReportTraceMaps(meta) : null;
108
+ Use `dom` to inspect UI state before, during, or after actions.
289
109
 
290
- for (const ctx of traces) {
291
- const summary = await getSummary(ctx, { reportMetadata: meta, reportTraceMaps: maps });
292
- // ... process results per test (includes passing, failing, and retries)
293
- }
110
+ ```bash
111
+ npx playwright-traces-reader dom /path/to/playwright-report/data/<sha1> --near last --limit 3
294
112
  ```
295
113
 
296
- Each entry is either a directory (already extracted) or a `.zip` (auto-extracted). Non-trace files in `data/` (`.md`, `.png`, etc.) are ignored automatically.
297
-
298
- ## Low-Level Utilities
114
+ Useful filters:
299
115
 
300
- ### `getSummary(ctx, options)`
116
+ - `--near last`
117
+ - `--near <callId>`
118
+ - `--phase before|action|after`
119
+ - `--limit <count>`
301
120
 
302
- Builds a `TraceSummary` for a single `TraceContext`. Requires `options: { reportMetadata: ReportMetadata | null }`. Optionally accepts `reportTraceMaps` (pre-built via `buildReportTraceMaps()`) to avoid rebuilding maps on every call in a loop. Use this when you already have a specific `ctx` (e.g. from `listTraces()` without filtering). For report-level failure analysis, prefer `getFailedTestSummaries()` which calls this internally only for unique failures.
121
+ ### Timeline
303
122
 
304
- ```typescript
305
- import { prepareTraceDir, getSummary, getReportMetadata } from '@andrii_kremlovskyi/playwright-traces-reader';
123
+ Use `timeline` to build a merged chronological trace narrative.
306
124
 
307
- const ctx = await prepareTraceDir('/path/to/trace-dir');
308
- const meta = await getReportMetadata('/path/to/playwright-report');
309
- const summary = await getSummary(ctx, { reportMetadata: meta });
310
- console.log(`[${summary.status.toUpperCase()}] ${summary.testTitle ?? summary.title}`);
125
+ ```bash
126
+ npx playwright-traces-reader timeline /path/to/playwright-report/data/<sha1>
311
127
  ```
312
128
 
313
- ### `prepareTraceDir(tracePath)`
314
-
315
- Takes a single path (directory or `.zip`) and returns a `TraceContext`. Use this when you have a specific trace path rather than a whole `data/` directory.
129
+ ### Screenshots
316
130
 
317
- ```typescript
318
- import { prepareTraceDir } from '@andrii_kremlovskyi/playwright-traces-reader';
131
+ Use `screenshots` only when a human needs extracted image files.
319
132
 
320
- const ctx = await prepareTraceDir('/path/to/playwright-report/data/<sha1>');
321
- // or a zip:
322
- const ctx = await prepareTraceDir('/path/to/playwright-report/data/<sha1>.zip');
133
+ ```bash
134
+ npx playwright-traces-reader screenshots /path/to/playwright-report/data/<sha1> --out-dir /tmp/pw-screenshots
323
135
  ```
324
136
 
325
- ### `getResourceBuffer(ctx, sha1)`
326
-
327
- Resolves a SHA1 filename to its raw `Buffer` from the trace's `resources/` directory. Returns `null` if the blob is not found. Useful when you need the raw bytes of a request/response body or a screenshot blob.
137
+ ### Skill scaffold
328
138
 
329
- ```typescript
330
- import { prepareTraceDir, getResourceBuffer } from '@andrii_kremlovskyi/playwright-traces-reader';
139
+ Use `init-skills` to install this skill into another repository.
331
140
 
332
- const ctx = await prepareTraceDir('/path/to/trace-dir');
333
- const buf = await getResourceBuffer(ctx, 'a1b2c3d4...');
334
- if (buf) {
335
- // e.g. write to disk, pass to an image model, etc.
336
- console.log(`blob size: ${buf.byteLength} bytes`);
337
- }
141
+ ```bash
142
+ npx playwright-traces-reader init-skills
338
143
  ```
339
144
 
340
- ### `readNdjson<T>(filePath)`
145
+ ## Recommended Workflow
341
146
 
342
- Async generator that streams and parses an NDJSON file line by line. Silently skips malformed lines. Useful for reading raw trace events when the built-in extractors don't cover your use case.
147
+ 1. Identify whether the task is report-level or single-trace.
148
+ 2. Choose the narrowest CLI command that answers the question.
149
+ 3. Use the default JSON output for agent reasoning or follow-up processing.
150
+ 4. Use `--format text` when the user wants a direct terminal-style summary.
151
+ 5. Do not fall back to library APIs unless the requested workflow is not covered by a supported command.
343
152
 
344
- ```typescript
345
- import { prepareTraceDir, readNdjson } from '@andrii_kremlovskyi/playwright-traces-reader';
346
- import * as path from 'path';
153
+ ## Output Guidance
347
154
 
348
- const ctx = await prepareTraceDir('/path/to/trace-dir');
349
- const traceFile = path.join(ctx.traceDir, '0-trace.trace');
155
+ - All CLI JSON outputs use versioned envelopes.
156
+ - See `CLI_JSON_CONTRACTS.md` in the package for payload structure.
157
+ - For screenshots, the JSON output contains file metadata, not image understanding.
350
158
 
351
- for await (const event of readNdjson<{ type: string }>(traceFile)) {
352
- if (event.type === 'screencast-frame') {
353
- console.log('screencast frame:', event);
354
- }
355
- }
356
- ```
159
+ ## More Documentation
357
160
 
358
- ## Execution Pattern
359
-
360
- All code snippets in this skill use ES module `import` syntax. Write them to a temporary `.mjs` file and execute with Node.js — the `.mjs` extension tells Node to treat the file as an ES module without requiring a `package.json` change.
361
-
362
- **Recommended workflow (works on macOS, Linux, and Windows):**
363
-
364
- 1. Use the `create_file` tool to write the script to a fixed filename:
365
- ```
366
- <workspace-root>/__trace_analysis__.mjs
367
- ```
368
- 2. Run it:
369
- ```bash
370
- node __trace_analysis__.mjs
371
- ```
372
- 3. Clean up after the session:
373
- ```bash
374
- # macOS / Linux
375
- rm __trace_analysis__.mjs
376
- # Windows PowerShell
377
- Remove-Item __trace_analysis__.mjs
378
- ```
379
-
380
- Using a fixed, recognisable filename makes it easy to spot and clean up if the agent session ends unexpectedly.
381
-
382
- ## Tips
383
-
384
- - **Starting point for report-level failures**: Use `getFailedTestSummaries(dataDir)` — returns `TraceSummary[]` for every unique failing test with retries deduplicated (by `testId` from `report.json`) and passing tests excluded. Each result has an `outcome` field (`'unexpected'`, `'flaky'`, `'skipped'`, or `null`). Pass `{ excludeSkipped: true }` to exclude skipped tests.
385
- - **Starting point for per-context analysis**: Use `getSummary(ctx, { reportMetadata: meta })` on a specific `TraceContext` from `listTraces()` — it gives `testTitle`, status, error, slowest steps, API calls, and the DOM snapshot closest to the failure in one call. Pass `reportMetadata: null` if `index.html` is unavailable.
386
- - **Accurate failure count**: `getFailedTestSummaries()` deduplicates by `testId` from `report.json` (falls back to `testTitle` then `traceDir`).
387
- - **Drill into failures**: Each `TestStep` in `topLevelSteps` includes `.children`. Walk them recursively to find the specific assertion or action that failed within the test.
388
- - **Failures**: The `error.message` in a `TraceSummary` contains the full diff for assertion failures.
389
- - **Network issues**: `summary.networkCalls` contains all HTTP calls (API and browser). Filter by `source === 'api'` for Node.js `APIRequestContext` calls or `source === 'browser'` for XHR/fetch/navigation. Check `status >= 400` for HTTP errors.
390
- - **Slow tests**: `getSummary().slowestSteps` gives top 5 instantly. For the full picture use `getTestSteps()` and sort by `durationMs`.
391
- - **Visual state (AI)**: Use `getDomSnapshots()` with `{ near: 'last', limit: 3 }` — returns full HTML that an AI can read and reason about. `failureDomSnapshot` on each `TraceSummary` gives the DOM closest to the failure directly.
392
- - **Visual state (human)**: Use `extractScreenshots()` to get JPEG files for human inspection in an image viewer. AI agents cannot read image files from disk.
393
- - **Timeline**: Use `getTimeline()` to build a chronological narrative merging steps, screenshots, DOM snapshots, and network calls — ideal for correlating what was happening at the exact moment of failure.
161
+ - Use the CLI reference for detailed command docs: `CLI_REFERENCE.md`
162
+ - Use the library integration guide only for in-process integrations such as `playwright-reports`: `LIBRARY_INTEGRATION.md`