API
Level CI – WebdriverIO API: levelAnalyze
Runs a static accessibility analysis on the current page and returns a result object containing violations.
By default, asserts that the number of violations is zero.
Default Config
await levelAnalyze(browser, {
strict: true,
})Manual assertion:
await levelAnalyze(browser, { strict: false }).then((res) => {
expect(res.violations).to.have.length(0)
})Access configuration object from results:
await levelAnalyze(browser, { strict: false }).then((res) => {
console.log(res.fullReport.config)
})Full Config
type AnalyzeConfig = {
includeRules?: string[] // Only include these rules
excludeRules?: string[] // Exclude rules (overrides includeRules)
strict?: boolean // Set false to manually process results
saveReport?: 'json' // Format for report
reportPath?: string // Folder to store artifacts (global config only)
includeIframes?: boolean // Include subdocuments (iframes)
ignoreSelectors?: string[] // Default: ["data-level-ci-app-ignore"]
ignoreUrls?: RegExp[] // Skip analysis for specific URLs
switchOff?: boolean // Disable rules check globally or per test
onResult?: (data: AnalysisResultData) => void // Hook called when result is ready
}Examples
// Save HTML report and screenshots
await levelAnalyze(browser, {
saveReport: 'html',
issueScreenshots: true,
})
// Enable only includeRules
await levelAnalyze(browser, {
level: null,
includeRules: ['duplicate-id', 'color-contrast'],
})
// Disable all rules
await levelAnalyze(browser, { level: null })
// Manual assertion
await levelAnalyze(browser, { strict: false }).then((res) => {
console.log(res.fullReport)
expect(res.violations).to.have.length(0)
})Global Setup – setupLevel(config: AnalyzeConfig)
Set global configuration once to avoid passing config on every call:
// wdio.conf.js
const { setupLevel } = require('@level-ci/a11y-webdriverio')
setupLevel({
reportPath: 'level-ci-reports',
})Example WebdriverIO Usage
await browser.url('http://localhost:5000')
await levelAnalyze(browser, {
issueScreenshots: true,
})Global config can be overridden per test. Arrays and objects are merged.
Config Defaults
| Field | Default |
|---|---|
strict | true |
ignoreSelectors | ["data-level-ci-app-ignore"] |
saveReport | 'json' |
reportPath | 'level-ci-reports' |
includeRules | [] |
excludeRules | [] |
includeIframes | false |
switchOff | false (can also use env variable) |
Report Structure
level-ci-reports/
├─ reports/ # Accessibility reports (HTML/JSON/CSV)
├─ pages/ # Original HTML of tested pages
└─ screenshots/ # Screenshots (if enabled)- Reports grouped by execution timestamp.
- Violations include
errorMessageandrecommendation. - Grouped issues (like duplicate IDs) use
issuesGroup.
Global Switch – Enable/Disable Analysis
setupLevel({ switchOff: true }) // Disable globally
await levelAnalyze(browser, { switchOff: true }) // Disable per testOr via environment variable:
LEVEL_CI_SWITCH_OFF=true node ./dev/webdriverio.test.jsLast updated on