Playwright test coverage
Playwright test coverage for the code behind every page
Playwright can collect coverage of the JavaScript in the browser, but not of the services the page calls. CoverOps measures those: a reporter and one fixture label every request a test makes, agents inside your services record what ran, and each test in the HTML report links to the backend lines, methods and services it reached.
By the CoverOps team · Last updated
Why teams choose CoverOps for Playwright test coverage
The server half of every Playwright test
Line-level coverage of the services behind the page, per test, from the first page load on, with a link on every test in the HTML report. A reporter and one beforeEach; no change to your tests.
Skip tests safely, with a reason for every skip
A test is skipped only when its recorded footprint misses every changed line, and the report says why. Observation mode shows what would have been skipped before anything is, and when the change cannot be read in full, everything runs.
A merge gate on the code that changed
Block or flag a pull request when its changed lines were not executed by the tests of its build, with the verdict on the commit status and, on GitHub, a comment listing the lines no test ran.
Flaky tests caught, not hidden by retries
Passes on retry, different results on one commit and flips on a branch are all counted, flips per branch, and a confirmed flake can be quarantined so it stops blocking builds.
Cloud, self-hosted or air-gapped
Use the hosted service in AWS Frankfurt, or run CoverOps in your private cloud, on your own servers or fully offline.
ISO/IEC 27001, 27701 and ISO 9001
Certified to ISO/IEC 27001:2022, ISO/IEC 27701 and ISO 9001. SOC 2 Type 2 is coming soon.
Two halves of Playwright coverage
Most guides to Playwright code coverage are about the front end: build the app with Istanbul instrumentation, or read V8 coverage from Chromium, then merge the results into one report after the run. That tells you which components and client-side functions the suite exercised. It is useful, and CoverOps does not replace it.
The other half is the code a click sets off on the server: the API handler, the pricing rule, the service it calls. In a multi-service system that is usually where the business logic lives, and where a change is most likely to break something an end-to-end test should have caught. Measuring it needs an agent in each service and a way to tell which test sent each request.
Playwright makes the second part easy: unlike a plain WebDriver session, a browser context can add headers to every request it sends, including the first page load.
How it works with Playwright
- Start the services under test with the CoverOps agent for their language (Java, .NET, Node.js, Python, Go or PHP).
- Install
@coverageops/playwrightfrom your CoverOps address and add it as a reporter. It opens the run before the first test and posts every verdict, one per test and project, with retries counted. - In a
beforeEach, put the CoverOps headers on the browser context. Every request the page makes then carries the test'sspec::title, its optional id and the run. - Set
COVERAGEOPS_ENDPOINTandCOVERAGEOPS_TOKENin CI. The run key defaults to the CI build id, so the services' coverage and the suite's verdicts land in the same run, shards included.
reporter: [['list'], ['@coverageops/playwright']],
import { attachFootprint, coverageOpsHeaders } from '@coverageops/playwright';
test.beforeEach(async ({ context }, testInfo) => {
await context.setExtraHTTPHeaders(coverageOpsHeaders(testInfo));
attachFootprint(testInfo); // a 'coverops' link in the HTML report
});
// optional: the test's id in TestRail / Jira
test('buys a desk',
{ annotation: { type: 'test-id', description: 'AUT-45' } },
async ({ page }) => { … });Playwright for Python uses the pytest plugin instead: context.set_extra_http_headers(coverops.headers()). With --shard=2/3 the run waits for every shard before it closes, and the CI log prints each failed test with a link to what it did on the backend.
What you get
Backend footprint in the HTML report
Each test carries a coverops annotation linking to its footprint in this run: endpoints called, services crossed, methods run, lines executed. The run page draws the test's journey through the services.
Skip the specs a change cannot reach
coverageops select --base origin/main --format skip writes the skip list; selectionSkip(testInfo) in its own beforeEach skips those tests before a browser context opens. Start with --observe, which records what would have been skipped and skips nothing.
A changed-code gate
Of the lines a pull request changed, how many did the tests of its build execute? coverageops gate answers in CI and can post the verdict as a commit status on GitHub, GitLab, Azure DevOps or Bitbucket.
Playwright's flaky outcome, kept
With retries set, a test that failed and then passed is posted once with its attempts. It still passes the run and the gate; the Flaky tests page counts it. The same spec on Chromium and Firefox stays two results, not a retry.
What is measured, and what is not
Measured
- Server-side lines, methods and services each Playwright test reached, on every service with an agent, branches included on Java and Node.js.
- Every request in order, from the first page load on, because the headers are on the browser context.
- Verdicts per test and per Playwright project, with attempts and the branch and commit under test.
Not measured
- The front-end JavaScript in the browser. Keep your Istanbul or V8 coverage for that; CoverOps has no browser agent.
- Calls to third-party services you do not run with an agent, such as a payment provider's API.
- Exact lines per test when Playwright workers hit the same service process at the same time: lines of the shared span go to each overlapping test, and the overlap is shown. Requests and methods stay exact.
Frequently asked questions
How do I get code coverage from Playwright tests?
For the browser: instrument the front-end build with Istanbul or collect V8 coverage in Chromium. For the backend: run the services with a coverage agent and label each test's requests. CoverOps covers the backend part, per test, across services.
Does it work with Playwright sharding and workers?
Yes. With --shard each shard joins the same run, and the run closes only after the last one, plus a short grace for the services' final coverage. Parallel workers are fine; overlapping tests share lines for the time they overlap, which the run page shows.
Do I need to change my Playwright tests?
No test body changes. You add the reporter to the config and one beforeEach that sets the headers and, if you want the link in the report, calls attachFootprint.
Is Playwright for Python supported?
Yes, through the pytest plugin: it opens the run, names each test and reports verdicts, and context.set_extra_http_headers(coverops.headers()) labels the browser's requests.
Can I run only the Playwright tests a pull request affects?
Yes, once the suite has run with CoverOps and every test has a footprint. A test is skipped only when its footprint misses every changed line; if the change cannot be read in full or touches code no agent measures, everything runs.
Keep reading
Related pages
In the documentation
The documentation is in English.
See what your Playwright suite reaches on the server
In a demo we run Playwright tests against a multi-service app and open each test's backend footprint.