API Methods
levelAnalyze
levelAnalyze(browser: Browser, 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 |
|---|---|---|---|
browser | WebdriverIO.Browser | — | WebdriverIO Browser object to analyze |
config | LaunchConfig | {} | Optional configuration object |
Returns
Returns a Promise, which should resolve, otherwise return value will contain error object.
Usage
it('homepage accessibility', async () => {
await levelAnalyze(browser, {
reportPath: './custom-reports-folder',
})
})Important: Make sure to use
levelAnalyzeafter your tests have run successfully. If you add it to some kind of anafterEachhook, add a condition to check the success of test execution:afterTest: async (_test, _context, { passed }) => { if (passed) { await levelAnalyze(browser) } }Otherwise, every rerun of a test (if you have retries) will produce a new report that is to be uploaded and processed, even when the test fails in the middle of execution.
levelSetup
levelSetup(config: LaunchConfig): voidConfigure global settings for all Level CI analysis runs. Use this in your WebdriverIO support file or before tests 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 test. For this provide config per
levelAnalyzecall. Arrays and objects are merged with test-level config.
Usage
You can use levelSetup in your support file so all tests use the same defaults.
Option 1: Pass browser to analyze function
// webdriverio/support/e2e.ts
import { levelSetup } from '@level-ci/a11y-webdriverio'
levelSetup({
reportPath: 'level-ci-reports-custom',
})Then in your tests:
// webdriverio/e2e/demo.spec.ts
import { levelAnalyze } from '@level-ci/a11y-webdriverio'
describe('test', () => {
it('runs Level CI analysis on the home page', async () => {
await browser.url('/')
const config = {}
await levelAnalyze(browser, config)
})
})Option 2: Override config per test
await levelAnalyze(browser, {
reportPath: './per-test-reports',
customTags: ['smoke'],
})Config
LaunchConfig
interface LaunchConfig {
switchOff?: boolean
reportPath?: string
ignoreUrls?: RegExp[]
customTags?: string[]
experimental?: {
cssSelector?: {
stableAttributes?: string[]
includeClasses?: boolean
ignoredClassPatterns?: string[]
}
}
}switchOff boolean
Disable rules check globally or per specific test.
Default: false
Environment variable: LEVEL_CI_SWITCH_OFF
Example value: true
See code examples here.
reportPath string
Folder path to store analysis artifacts.
Default: 'level-ci-reports'
Environment variable: LEVEL_CI_REPORT_PATH
Example value: 'my-custom-report-path'
See code examples here.
ignoreUrls RegExp[]
Skip analysis for URLs matching these patterns.
Example value: [/home/, /settings\/privacy/, /articles\/*/]
See code examples here.
customTags string[]
Add custom tags for scan identification.
Example values: ['alpha', 'beta', 'scenario-1']
See code examples here.
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.
Experimental selector configuration
Tune how Level CI builds CSS selectors for elements with accessibility issues. When omitted, Level CI uses its default selector behavior.
stableAttributes string[]
Use stable attributes when element IDs or generated classes can change between runs. Level CI uses the selector to recognize the same issue over time. If the selector changes, an existing issue can appear resolved and return as a new issue.
Add an attribute whose value stays stable:
<button data-testid="submit-order">Submit order</button>List attribute names in priority order. Level CI uses the first one that uniquely identifies the element.
Default: ['id']
Example values: ['data-testid'], ['data-testid', 'data-qa']
await levelAnalyze(browser, {
experimental: {
cssSelector: {
stableAttributes: ['data-testid', 'data-qa'],
},
},
})includeClasses boolean
Set this to false when your application generates class names that change between builds. Level CI then omits all class names from generated selectors.
await levelAnalyze(browser, {
experimental: {
cssSelector: {
includeClasses: false,
},
},
})ignoredClassPatterns string[]
Use this option when only some class names are unstable. Each value is a regular expression pattern for class names Level CI should omit. Write the pattern without leading or trailing /.
Example values: ['^sc-', '^css-']
await levelAnalyze(browser, {
experimental: {
cssSelector: {
ignoredClassPatterns: ['^sc-', '^css-'],
},
},
})Examples
Set custom report path
Option 1: Globally with levelSetup
levelSetup({
reportPath: './custom-reports-folder',
})Option 2: Per test with levelAnalyze
await levelAnalyze(browser, {
reportPath: './custom-reports-folder',
})Option 3: Using environment variable
LEVEL_CI_REPORT_PATH=./custom-reportsConfigure experimental CSS selectors
Option 1: Globally with levelSetup
levelSetup({
experimental: {
cssSelector: {
stableAttributes: ['data-testid', 'data-qa'],
includeClasses: false,
ignoredClassPatterns: ['^sc-', '^css-'],
},
},
})Option 2: Per test with levelAnalyze
await levelAnalyze(browser, {
experimental: {
cssSelector: {
stableAttributes: ['data-testid', 'data-qa'],
includeClasses: false,
ignoredClassPatterns: ['^sc-', '^css-'],
},
},
})Disable rule check
Option 1: Globally with levelSetup
levelSetup({
switchOff: true,
})Option 2: Per test with levelAnalyze
await levelAnalyze(browser, {
switchOff: true,
})Option 3: Using environment variable
LEVEL_CI_SWITCH_OFF=trueAdd specific tags for this analysis run
Option 1: Globally with levelSetup
levelSetup({
customTags: ['my-tag', 'regression'],
})Option 2: Per test with levelAnalyze
await levelAnalyze(browser, {
customTags: ['my-tag', 'regression'],
})Ignore specific URLs during analysis
Option 1: Globally with levelSetup
levelSetup({
ignoreUrls: [/localhost:3000/, /example.com/],
})Option 2: Per test with levelAnalyze
await levelAnalyze(browser, {
ignoreUrls: [/localhost:3000/, /example.com/],
})