@andrii_kremlovskyi/playwright-traces-reader 1.3.1 → 2.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 +42 -2
- package/dist/cli/formatters.d.ts +14 -0
- package/dist/cli/formatters.d.ts.map +1 -0
- package/dist/cli/formatters.js +174 -0
- package/dist/cli/formatters.js.map +1 -0
- package/dist/cli/helpers.d.ts +6 -0
- package/dist/cli/helpers.d.ts.map +1 -0
- package/dist/cli/helpers.js +84 -0
- package/dist/cli/helpers.js.map +1 -0
- package/dist/cli/json.d.ts +59 -0
- package/dist/cli/json.d.ts.map +1 -0
- package/dist/cli/json.js +76 -0
- package/dist/cli/json.js.map +1 -0
- package/dist/cli.d.ts +5 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +154 -65
- package/dist/cli.js.map +1 -1
- package/package.json +3 -2
- package/templates/skills/analyze-playwright-traces/SKILL.md +92 -324
|
@@ -1,393 +1,161 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: analyze-playwright-traces
|
|
3
|
-
description: Analyze Playwright
|
|
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
|
|
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
|
+
- Prefer `--format json` when the output needs to be consumed by the agent or follow-up tooling.
|
|
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
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
## How to Use
|
|
20
|
-
|
|
21
|
-
### 1. Find failed tests
|
|
26
|
+
Supported local inputs:
|
|
22
27
|
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
35
|
+
### Report-level analysis
|
|
45
36
|
|
|
46
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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 --format json
|
|
58
41
|
```
|
|
59
42
|
|
|
60
|
-
|
|
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
|
-
|
|
111
|
-
|
|
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 --format json
|
|
142
47
|
```
|
|
143
48
|
|
|
144
|
-
|
|
49
|
+
What it returns:
|
|
145
50
|
|
|
146
|
-
|
|
51
|
+
- unique failing tests only
|
|
52
|
+
- retries already deduplicated
|
|
53
|
+
- structured failure summaries with steps, network calls, and failure DOM state
|
|
147
54
|
|
|
148
|
-
|
|
149
|
-
import { prepareTraceDir, getNetworkTraffic } from '@andrii_kremlovskyi/playwright-traces-reader';
|
|
55
|
+
### Single-trace summary
|
|
150
56
|
|
|
151
|
-
|
|
152
|
-
const traffic = await getNetworkTraffic(ctx);
|
|
57
|
+
Use `summary` when the user wants one complete summary for a specific trace.
|
|
153
58
|
|
|
154
|
-
|
|
155
|
-
|
|
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
|
|
59
|
+
```bash
|
|
60
|
+
npx playwright-traces-reader summary /path/to/playwright-report/data/<sha1> --format json
|
|
162
61
|
```
|
|
163
62
|
|
|
164
|
-
|
|
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';
|
|
63
|
+
If report metadata should be loaded explicitly, pass `--report`:
|
|
171
64
|
|
|
172
|
-
|
|
173
|
-
|
|
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
|
|
65
|
+
```bash
|
|
66
|
+
npx playwright-traces-reader summary /path/to/playwright-report/data/<sha1> --report /path/to/playwright-report --format json
|
|
180
67
|
```
|
|
181
68
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
`getDomSnapshots()` accepts an optional `options` argument to filter the results — especially useful for long traces with many snapshots.
|
|
69
|
+
Important behavior:
|
|
185
70
|
|
|
186
|
-
|
|
187
|
-
|
|
71
|
+
- `summary` works for both passed and failed traces
|
|
72
|
+
- failed traces may include `failureDomSnapshot`
|
|
73
|
+
- passed traces return `status: "passed"` and `failureDomSnapshot: null`
|
|
188
74
|
|
|
189
|
-
|
|
75
|
+
### Slow steps
|
|
190
76
|
|
|
191
|
-
|
|
192
|
-
const all = await getDomSnapshots(ctx);
|
|
77
|
+
Use `slow-steps` to inspect the slowest steps in one trace.
|
|
193
78
|
|
|
194
|
-
|
|
195
|
-
|
|
79
|
+
```bash
|
|
80
|
+
npx playwright-traces-reader slow-steps /path/to/playwright-report/data/<sha1> --limit 5 --format json
|
|
81
|
+
```
|
|
196
82
|
|
|
197
|
-
|
|
198
|
-
const window = await getDomSnapshots(ctx, { near: 'call@585', limit: 5 });
|
|
83
|
+
### Step tree
|
|
199
84
|
|
|
200
|
-
|
|
201
|
-
const afterOnly = await getDomSnapshots(ctx, { phase: 'after' });
|
|
85
|
+
Use `steps` to inspect the reconstructed test step hierarchy.
|
|
202
86
|
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
}
|
|
87
|
+
```bash
|
|
88
|
+
npx playwright-traces-reader steps /path/to/playwright-report/data/<sha1>
|
|
212
89
|
```
|
|
213
90
|
|
|
214
|
-
|
|
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
|
-
```
|
|
91
|
+
### Network traffic
|
|
269
92
|
|
|
270
|
-
`
|
|
271
|
-
- `timestamp` — wall-clock time in milliseconds since epoch
|
|
272
|
-
- `type` — `'step'` | `'screenshot'` | `'dom'` | `'network'`
|
|
273
|
-
- `data` — cast based on `type` (see above)
|
|
93
|
+
Use `network` to inspect API and browser traffic for one trace.
|
|
274
94
|
|
|
275
|
-
|
|
95
|
+
```bash
|
|
96
|
+
npx playwright-traces-reader network /path/to/playwright-report/data/<sha1> --source all --format json
|
|
97
|
+
```
|
|
276
98
|
|
|
277
|
-
|
|
99
|
+
Source filters:
|
|
278
100
|
|
|
279
|
-
|
|
101
|
+
- `all`
|
|
102
|
+
- `api`
|
|
103
|
+
- `browser`
|
|
280
104
|
|
|
281
|
-
|
|
282
|
-
import { listTraces, getSummary, getReportMetadata, buildReportTraceMaps } from '@andrii_kremlovskyi/playwright-traces-reader';
|
|
105
|
+
### DOM snapshots
|
|
283
106
|
|
|
284
|
-
|
|
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;
|
|
107
|
+
Use `dom` to inspect UI state before, during, or after actions.
|
|
289
108
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
// ... process results per test (includes passing, failing, and retries)
|
|
293
|
-
}
|
|
109
|
+
```bash
|
|
110
|
+
npx playwright-traces-reader dom /path/to/playwright-report/data/<sha1> --near last --limit 3 --format json
|
|
294
111
|
```
|
|
295
112
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
## Low-Level Utilities
|
|
113
|
+
Useful filters:
|
|
299
114
|
|
|
300
|
-
|
|
115
|
+
- `--near last`
|
|
116
|
+
- `--near <callId>`
|
|
117
|
+
- `--phase before|action|after`
|
|
118
|
+
- `--limit <count>`
|
|
301
119
|
|
|
302
|
-
|
|
120
|
+
### Timeline
|
|
303
121
|
|
|
304
|
-
|
|
305
|
-
import { prepareTraceDir, getSummary, getReportMetadata } from '@andrii_kremlovskyi/playwright-traces-reader';
|
|
122
|
+
Use `timeline` to build a merged chronological trace narrative.
|
|
306
123
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const summary = await getSummary(ctx, { reportMetadata: meta });
|
|
310
|
-
console.log(`[${summary.status.toUpperCase()}] ${summary.testTitle ?? summary.title}`);
|
|
124
|
+
```bash
|
|
125
|
+
npx playwright-traces-reader timeline /path/to/playwright-report/data/<sha1> --format json
|
|
311
126
|
```
|
|
312
127
|
|
|
313
|
-
###
|
|
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.
|
|
128
|
+
### Screenshots
|
|
316
129
|
|
|
317
|
-
|
|
318
|
-
import { prepareTraceDir } from '@andrii_kremlovskyi/playwright-traces-reader';
|
|
130
|
+
Use `screenshots` only when a human needs extracted image files.
|
|
319
131
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const ctx = await prepareTraceDir('/path/to/playwright-report/data/<sha1>.zip');
|
|
132
|
+
```bash
|
|
133
|
+
npx playwright-traces-reader screenshots /path/to/playwright-report/data/<sha1> --out-dir /tmp/pw-screenshots --format json
|
|
323
134
|
```
|
|
324
135
|
|
|
325
|
-
###
|
|
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.
|
|
136
|
+
### Skill scaffold
|
|
328
137
|
|
|
329
|
-
|
|
330
|
-
import { prepareTraceDir, getResourceBuffer } from '@andrii_kremlovskyi/playwright-traces-reader';
|
|
138
|
+
Use `init-skills` to install this skill into another repository.
|
|
331
139
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
if (buf) {
|
|
335
|
-
// e.g. write to disk, pass to an image model, etc.
|
|
336
|
-
console.log(`blob size: ${buf.byteLength} bytes`);
|
|
337
|
-
}
|
|
140
|
+
```bash
|
|
141
|
+
npx playwright-traces-reader init-skills
|
|
338
142
|
```
|
|
339
143
|
|
|
340
|
-
|
|
144
|
+
## Recommended Workflow
|
|
341
145
|
|
|
342
|
-
|
|
146
|
+
1. Identify whether the task is report-level or single-trace.
|
|
147
|
+
2. Choose the narrowest CLI command that answers the question.
|
|
148
|
+
3. Prefer `--format json` for agent reasoning or follow-up processing.
|
|
149
|
+
4. Use text output when the user wants a direct terminal-style summary.
|
|
150
|
+
5. Do not fall back to library APIs unless the requested workflow is not covered by a supported command.
|
|
343
151
|
|
|
344
|
-
|
|
345
|
-
import { prepareTraceDir, readNdjson } from '@andrii_kremlovskyi/playwright-traces-reader';
|
|
346
|
-
import * as path from 'path';
|
|
152
|
+
## Output Guidance
|
|
347
153
|
|
|
348
|
-
|
|
349
|
-
|
|
154
|
+
- All CLI JSON outputs use versioned envelopes.
|
|
155
|
+
- See `CLI_JSON_CONTRACTS.md` in the package for payload structure.
|
|
156
|
+
- For screenshots, the JSON output contains file metadata, not image understanding.
|
|
350
157
|
|
|
351
|
-
|
|
352
|
-
if (event.type === 'screencast-frame') {
|
|
353
|
-
console.log('screencast frame:', event);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
```
|
|
158
|
+
## More Documentation
|
|
357
159
|
|
|
358
|
-
|
|
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.
|
|
160
|
+
- Use the CLI reference for detailed command docs: `CLI_REFERENCE.md`
|
|
161
|
+
- Use the library integration guide only for in-process integrations such as `playwright-reports`: `LIBRARY_INTEGRATION.md`
|