Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:MarketSquare Robotframework browser Coverage Keywords

From Leeroopedia
Knowledge Sources
Domains Coverage, Testing
Last Updated 2026-02-12 05:40 GMT

Overview

Provides keywords for collecting CSS and JavaScript code coverage data from browser pages using Playwright's Coverage API and monocart-coverage-reports.

Description

The Coverage class extends LibraryComponent and provides three Robot Framework keywords for code coverage collection. Start Coverage begins coverage collection on the current page with configurable options including coverage_type (all, css, or js), an optional config_file for monocart-coverage-reports options, a path for the output directory (relative to ${OUTPUT_DIR}/browser/coverage/), raw mode for saving raw V8 coverage data needed for merging, reportAnonymousScripts for JS coverage, and resetOnNavigation to control whether coverage resets on page navigation. Stop Coverage ends collection and generates an HTML coverage report via monocart-coverage-reports, returning the path to the report file. Merge Coverage Reports combines multiple raw coverage reports from separate pages or test runs into a single unified report. It accepts input_folder and output_folder paths, an optional config_file, a report name, and a list of reports formats (defaulting to "v8"). A module-level helper function _find_coverage_files recursively locates raw coverage data files within subdirectories. All keywords tagged as Experimental communicate with the Playwright Node.js backend via gRPC.

Usage

Use these keywords when you need to measure CSS and JavaScript code coverage during browser tests. Start coverage before performing actions on the page, stop it afterward to generate reports, and optionally merge reports from multiple test sessions for comprehensive coverage analysis.

Code Reference

Source Location

Signature

class Coverage(LibraryComponent):

    def start_coverage(
        self,
        *,
        config_file: PathLike | None = None,
        coverage_type: CoverageType = CoverageType.all,
        path: Path = Path(),
        raw: bool = False,
        reportAnonymousScripts: bool = False,
        resetOnNavigation: bool = True,
    ) -> str:

    def stop_coverage(self) -> Path:

    def merge_coverage_reports(
        self,
        input_folder: Path,
        output_folder: Path,
        config_file: Path | None = None,
        name: str | None = None,
        reports: list[str] | None = None,
    ) -> Path:

def _find_coverage_files(input_folder: Path) -> Iterator:

Import

from Browser.keywords.coverage import Coverage

I/O Contract

Inputs

Name Type Required Description
config_file PathLike or None No Path to a monocart-coverage-reports options file for customizing report generation.
coverage_type CoverageType No Type of coverage to collect: all (CSS and JS), css, or js. Default is all.
path Path No Relative or absolute directory path where coverage data is stored. Relative paths are resolved against ${OUTPUT_DIR}/browser/coverage/.
raw bool No Whether to save raw V8 coverage data for later merging. Default is False.
reportAnonymousScripts bool No Whether to report anonymous scripts in JS coverage. Default is False.
resetOnNavigation bool No Whether to reset coverage counters on page navigation. Default is True.
input_folder Path Yes (for merge) Base folder containing raw coverage report subdirectories.
output_folder Path Yes (for merge) Destination folder for the merged coverage report.
name str or None No Optional name for the merged coverage report.
reports list[str] or None No List of reporter formats. Default is ["v8"].

Outputs

Name Type Description
coverage_type str String representation of the started coverage type (from start_coverage).
report_path Path Path to the generated HTML coverage report file or the coverage directory (from stop_coverage).
output_folder Path Path to the folder containing the merged coverage report (from merge_coverage_reports).

Usage Examples

Robot Framework

*** Test Cases ***
Collect Coverage For Single Page
    New Page
    Start Coverage
    Go To    ${LOGIN_URL}
    Do Something In The Page
    ${report}=    Stop Coverage
    Log    Coverage report at: ${report}

Merge Multiple Coverage Reports
    New Page
    Start Coverage    raw=True
    Go To    ${LOGIN_URL}
    Test Feature X In The Page
    Stop Coverage
    New Page
    Start Coverage    raw=True
    Go To    ${LOGIN_URL}
    Test Feature Y In The Page
    Stop Coverage
    ${merged}=    Merge Coverage Reports    ${OUTPUT_DIR}/browser/coverage    ${OUTPUT_DIR}/browser/combined-coverage
    Log    Merged report at: ${merged}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment