Configuring Axe Accessibility Tests
WCAG
ARIA
ADA
508
AUDIT
Steven Lambert (he/him)
Tech Lead / People Manager @ Deque Systems
Primary developer on axe-core
Contact:
@StevenKLambert
steven@sklambert.com
stevenklambert.com
What is axe?
Example Use
<script� src="https://unpkg.com/axe-core@latest/axe.js"�></script>�<script type="module">�const results = await axe.run();�console.log(results.violations);�</script>
Example Output
[
{id: 'landmark-one-main', impact: 'moderate', …}
{id: 'page-has-heading-one', impact: 'moderate', …}
{id: 'region', impact: 'moderate', …}
]
Where Can You Use axe?
Browser or Node
CLI And Test Frameworks
VSCode
Other Integrations
Other Integrations
Configuring Rules
Which Rules Does axe Run?
By default, axe runs all supported rules
Where to Find Support Rules
axe-core and integrations - https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md
axe Linter - https://marketplace.visualstudio.com/items?itemName=deque-systems.vscode-axe-linter#rules
Various Ways to Configure Which Rules Run
For each of the ways to configure axe, I’ll show an example of how to do it for axe-core, then for cli and test frameworks, and lastly for axe linter.
Disabling Rules
Axe-core
await axe.run({
rules: {
'button-name': { enabled: false },
'label': { enabled: false }
}
});
CLI And Test Frameworks
new AxeBuilder()
.disableRules('button-name')
.analyze();��new AxeBuilder()
.disableRules(['button-name', 'label'])
.analyze();
Axe Linter
# axe-linter.yml
rules:
button-name: false
label: false
Run Certain Rules
Axe-core
await axe.run({ runOnly: 'button-name' });
await axe.run({ runOnly: ['button-name', 'label'] });
CLI And Test Frameworks
new AxeBuilder()
.withRules('button-name')
.analyze();
�new AxeBuilder()
.withRules(['button-name', 'label'])
.analyze();
Axe Linter
No API for this, so you’ll have to disable all other rules
# axe-linter.yml
rules:
button-name: true
label: true
area-alt: false
aria-allowed-attr: false
# …
Run Rules Matching Tag
What is a Tag?
Tags are ways to categorize rules into groups. In most cases, they are used to group rules by their WCAG version and conformance level.
For example, the “wcag2aa” tag is used to group rules for WCAG 2.0, AA conformance.
Where to Find Support Tags
Axe-core and integrations - https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#axe-core-tags
Axe Linter - https://marketplace.visualstudio.com/items?itemName=deque-systems.vscode-axe-linter#accessibility-tags
List of rules and their tags -
https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md
Axe-core
await axe.run({ runOnly: 'wcag2aa' });
await axe.run({ runOnly: ['wcag2aa', 'wcag2a'] });
CLI And Test Frameworks
new AxeBuilder()
.withTags('wcag2aa')
.analyze();��new AxeBuilder()
.withTags(['wcag2aa', 'wcag2a'])
.analyze();
Axe Linter
# axe-linter.yml
tags:
- wcag2aa
- wcag2a
Axe Run Options
Run Options
Shortlist of Run Options
Axe-core
await axe.run({ resultTypes: ['violations'] });
CLI And Test Frameworks
new AxeBuilder()
.options({ resultTypes: ['violations'] })
.analyze();
Connect with us