r/Playwright • • 7d ago

Check API/steps performance regression - Playwright

Hi all,

QA engineer here. Our e2e/api suites hit the backend thousands of times a day, but nobody looked at how long those requests took. A slow endpoint only got noticed once users complained. So I built playwright-performance-regression (MIT, free).

What it does:
- Measures the backend requests your browser makes (and `request` calls in API tests) while your existing tests run. No new tests to write.
- Groups them into endpoint keys like `GET /api/orders/:id` and computes median, p95, p99 and error rate. It can also time your `test.step` blocks.
- Derives thresholds into JSON files that you review and commit like code.
- Fails the run when an endpoint gets slower or starts erroring, with a console summary, a self-contained HTML report and `junit.xml` for CI.

Zero maintenance, by design:

- Setup takes minutes: one command, a guided setup, done. No new tests, no page objects, no instrumentation.
- Coverage grows on its own: every new e2e test that hits a new endpoint gets measured automatically. The more you test, the more performance coverage you get, with zero extra work.
- Your normal `npx playwright test` runs stay untouched. Measuring is a separate run you switch on with an env variable: `PW_PERF_MODE=test npm run e2e`.

Setup:

npm init playwright-performance-regression

A guided setup asks a few questions and shows a diff of every change before writing it. It never touches `package.json`. Then you generate thresholds once on CI, commit them, and forget about it.

Statistics:

Timings are noisy, so the run repeats your suite a few times (passes) and the thresholds are derived from those samples. I validated this on a benchmark before building the tool. CI recipes are included for GitHub Actions, GitLab, Jenkins and Azure.

- Live demo report: https://meser6.github.io/playwright-performance-regression/

- GitHub: https://github.com/Meser6/playwright-performance-regression

It's 1.0.0, so I'd really appreciate feedback: does it work on your setup, what's confusing, what's missing?

5 Upvotes

8 comments sorted by

2

u/Status_Ad8999 7d ago

Grouping dynamic URLs into route templates like GET /api/orders/:id automatically is the trickiest part of passive network timing. How are you handling numeric vs UUID/ULID path segments so high-cardinality IDs do not explode the baseline JSON file? Also worth separating cold first-hit calls after container spin-up in CI from warm samples, since the first request often skews p95 on small sample counts.

1

u/meseser 7d ago

Route templates and ID segments. Every path segment is matched as a whole against a set of ID patterns. If one matches, the segment becomes :id:

- numbers: 42, 0007;
- UUIDs in any version;
- hex of 16+ characters, e.g. Mongo ObjectIds;
- token-like strings: 24+ characters with a digit, which covers ULIDs (01ARZ3NDEKTSV4RRFFQ69G5FAV) and JWTs;
- mixed-case ids like nanoid (V1StGXR8_Z5jdHi6B-myT) or Stripe-style cus_NffrFeUfNV2Hib;
- prefixed ids: ORD-1000, inv_58, txn_a1b2c3d4;
- e-mails become :email, so they never land in a committed file.

Matching the whole segment is deliberate: partial matching would also rewrite things like v2, dates or file names. Query values are dropped and only the parameter names are kept, unless you opt in per name. If your IDs look different, you can add your own patterns (keys.extraIdPatterns) or a custom keyBuilder.

Cardinality guard. If 10+ keys differ only in the same segment position, the run warns with the template (e.g. GET /api/files/*) and suggests the fix. There is also a warning above 1,000 endpoint keys. So a missed ID pattern shows up on the first run, before it bloats the thresholds file. The rules are covered by a golden test suite.

Cold vs warm. Right now all samples count. Two things soften the cold-start effect:

- each measurement run repeats the suite several times (passes), so one cold first hit is a small share of the samples;
- p95 isn't evaluated at all below 20 samples, so on small counts the gate relies on the median.

Still, you're right that a cold first call after a container spins up can push p95 around. Separating cold first-hit samples from warm ones is going into the next release (1.1.0): they'll be reported separately and won't skew the evaluated percentiles. Thanks for the push!

1

u/meseser 3d ago

In version 1.1.0, a feature for separating cold runs has been added. The full list of changes can be found here: https://www.npmjs.com/package/playwright-performance-regression/v/1.1.0?activeTab=code

2

u/Alternative-Ruin275 5d ago

One more baseline check I'd want: do you report latency for successful responses separately from failed responses? If an endpoint starts returning fast 401s or 500s, its aggregate median can improve while the application gets worse. The error-rate gate helps, but showing both distributions would make that failure easier to understand. I'd also put sample count, worker count and the measured endpoint mix beside each comparison. Repeating a suite after a fixture or concurrency change isn't necessarily the same workload. A tiny example report with a fast-failure regression would make it easier to assess how the latency and error gates interact.

1

u/meseser 5d ago

Thanks, this is a really useful check. It also exposed a real gap. What exists today (1.0.1) and what's planned:

Already there
- Latency stats (median, p95, p99, Apdex) are computed only from successful responses (measure.successStatuses, default 2xx/3xx). Fast 500s don't improve the median. They're left out of the timings and counted by the error-rate rule (default 5xx, network failures and requests still pending at test end).
- Worker count is fixed at 1 in a measurement run. Passing --workers or --repeat-each stops the run with an error, so concurrency can't silently differ between baseline and check.
- The report shows the sample count per endpoint. The run warns when the thresholds file came from different conditions (browser, Playwright version, machine, URL normalization rules) and when endpoints from the baseline weren't seen at all.

The gap you found
By default, 4xx responses are neither timed nor counted as errors. If an endpoint flips entirely to fast 401s, it has no successful samples left. Its checks then fall below their minimum sample count, so it's skipped instead of failed. The HTML report only shows a note like "5 × 401 (not timed)". That's exactly the fast-failure regression you described, and it shouldn't pass quietly.

Planned for the next minor release
- Make non-success statuses count in the gate: either a non-success-rate rule or 4xx counted as errors by default (with room for expected 404s). Plus a warning when an endpoint with thresholds drops below its sample minimum because of non-success responses.
- A separate latency distribution for failed responses per endpoint (count, median, p95 by status), shown next to the successful-response latencies but kept out of the latency gate.
- Baseline context next to each comparison: the per-endpoint sample count from the baseline, stored in the thresholds file, with baseline n → current n, passes, workers and the endpoint's share of the mix. Plus a warning when the endpoint mix shifts, for example after fixture or test-scope changes.
- A small example report with a fast-failure regression (200 at ~120 ms → 401/500 at ~8 ms) that shows how the latency and error rules interact.

1

u/meseser 3d ago

Added in version 1.1.0. You can view the full changelog here: https://www.npmjs.com/package/playwright-performance-regression/v/1.1.0?activeTab=code

1

u/Xiao20 7d ago

It's interesting that Claude chose a very similar UI design to a Triathlon app I had it build.

1

u/meseser 7d ago

From what I’ve noticed – unless given specific instructions to the contrary – it always produces a very similar UI. Here, I’ve focused more on making the package as hands-off as possible rather than on the report’s appearance. Please do have a look, and I’d appreciate your feedback (especially the critical sort!)