Skip to main content

Puppeteer API

Overview

Use the Puppeteer API configuration to customize how Level CI runs accessibility analysis in your Puppeteer tests. You can configure Level CI globally with levelSetup() or override settings for individual runs with levelAnalyze().

API Methods

levelAnalyze

levelAnalyze(page: Page, config?: LaunchConfig): Promise<AnalysisResultData>

Runs a static accessibility analysis on the current page and generates a folder with analysis result data.

Properties

Property Type Default Description
page Puppeteer.Page Puppeteer Page object to analyze
config LaunchConfig {} Optional configuration object

Returns

Returns a Promise, which should resolve, otherwise return value will contain error object.

Usage

Important: Make sure to use levelAnalyze after your tests have run successfully. If you add it to a teardown or cleanup hook, add a condition to check the success of execution. Otherwise, every rerun will produce a new report that is to be uploaded and processed, even when the run fails in the middle.

levelSetup

levelSetup(config: LaunchConfig): void

Configure global settings for all Level CI analysis runs. Use this in a setup file or before your scripts for a clean setup.

Properties

Property Type Default Description
config LaunchConfig Global configuration object

Returns

No return value (void). Configuration is stored globally and applied to all subsequent levelAnalyze calls.

Note: Global configuration can be overridden per run. For this provide config per levelAnalyze call. Arrays and objects are merged with run-level config.

Usage

Call levelSetup once in a setup file or at the start of your script.

Config

Component-level screenshots (experimental)

To enable component-level screenshots for detected accessibility issues, add the experimental.elementScreenshots option to your cy.levelAnalyze() configuration.

This setting is currently experimental. Enabling component-level screenshots may increase scan execution time because screenshots are   captured during the accessibility analysis.

LaunchConfig

Configuration options

Option Type Description
switchOff boolean Disable rules check globally or per specific run. Default: false. Environment variable: LEVEL_CI_SWITCH_OFF. Example value: true.
reportPath string Folder path to store analysis artifacts. Default: level-ci-reports. Environment variable: LEVEL_CI_REPORT_PATH. Example value: my-custom-report-path.
ignoreUrls RegExp[] Skip analysis for URLs matching these patterns. Example value: [/home/, /settings\/privacy/, /articles\/*/].
customTags string[] Add custom tags for scan identification. Example values: ['alpha', 'beta', 'scenario-1'].
stableSelectorAttributes string[] Add to reliably identify elements with dynamic IDs. Example values: ['data-testid'].

Custom tags

If you pass scenario-1 as a custom tag, you will see it among the other tags for the newly found issues on the dashboard. This way you can identify which issue appeared, while testing scenario-1.

Stable selector attributes

Flaky issues often occur when elements have dynamic IDs. Level CI tracks elements across scans to monitor accessibility issues, but if an element’s id changes between scans, it treats it as a new element. This causes old issues to close and new issues to open for the same element.

Examples

Use these examples to set a custom report path, add stable selector attributes, disable rule checks, add tags, and ignore specific URLs during analysis.

Powered by Zendesk