Skip to main content
The Coverage class enables collecting JavaScript and CSS coverage information during test execution. This helps identify which parts of your code are executed during tests.

Overview

Access coverage through the page object:

JavaScript Coverage

startJSCoverage

Starts collecting JavaScript coverage.
boolean
default:"true"
Whether to reset coverage on every navigation.
boolean
default:"false"
Whether to report anonymous scripts.
Returns: Promise<void>

stopJSCoverage

Stops collecting JavaScript coverage and returns results.
Returns: Promise<JSCoverageEntry[]> Each entry contains:
string
Script URL.
Array<{ start: number, end: number }>
Executed code ranges. Each range specifies:
  • start: Start offset in the script
  • end: End offset in the script
string
Script source code.

CSS Coverage

startCSSCoverage

Starts collecting CSS coverage.
boolean
default:"true"
Whether to reset coverage on every navigation.
Returns: Promise<void>

stopCSSCoverage

Stops collecting CSS coverage and returns results.
Returns: Promise<CSSCoverageEntry[]> Each entry contains:
string
Stylesheet URL.
Array<{ start: number, end: number }>
Used CSS ranges. Each range specifies:
  • start: Start offset in the stylesheet
  • end: End offset in the stylesheet
string
Stylesheet source code.

Examples

Collecting JavaScript coverage

Collecting CSS coverage

Collecting both JS and CSS coverage

Coverage across multiple pages

Filtering coverage results

Calculating coverage percentage