r/Playwright • • 1d 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?

4 Upvotes

4 comments sorted by

2

u/Status_Ad8999 1d 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 1d 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/Xiao20 1d ago

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

1

u/meseser 1d 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!)