Accessibility
DrevOps\BehatSteps\Steps\Web\AccessibilityTrait - Source, Example, Helpers
Assess accessibility of rendered pages.
Supported tags:
@accessibilityAuto-mode, default threshold.@accessibility:criticalAuto-mode, fail only on critical impact.@accessibility:seriousAuto-mode, fail on critical or serious.@accessibility:moderateAuto-mode, fail on critical / serious / moderate.@accessibility:minorAuto-mode, fail on any impact.@accessibility:anyAuto-mode, fail on any impact (alias).@accessibility:warningAuto-mode, never fail (advisory).@accessibility:strictAlso fail on "incomplete" findings.@behat-steps-skip:AccessibilityTraitOpt the scenario or feature out entirely.Tool-agnostic. Any engine that runs inside the existing Mink session can be plugged in by overriding
accessibilityRunEngine()andaccessibilityNormalizeResults(). The first performs the assessment and returns raw results; the second remaps raw output into the canonical shape the rest of the trait reads.
Reporting. Each scenario writes its own HTML and JUnit report. After the whole suite, a single cross-pageaccessibility_report_<timestamp>.html(timestampYYYYMMDD_HHMMSS) is written to the same directory, de-duplicating every assessed page and rolling violations up by rule.
1 file is written per run, so a run never overwrites a previous one. The aggregate accumulates in process-global state, so under parallel Behat each process writes its own report.
Console output. A 1-line per-page summary can be printed to the console as pages are assessed. Printing is off by default; set theBEHAT_ACCESSIBILITY_PRINTenvironment variable to a non-empty value other than0, or overrideaccessibilityGetPrintCli(), to enable it.
Options
| Option | Type | Default | Tag | Description |
|---|---|---|---|---|
accessibility.enabled | boolean | TRUE | @behat-steps-skip:AccessibilityTrait | If TRUE, assesses every page an @accessibility scenario visits and writes its reports. If FALSE, no page is assessed automatically and no report is written, while the accessibility steps still assess the page they run on. |
accessibility.auto_tag | string | 'accessibility' | - | The name, without the @, of the tag that switches on automatic assessment for a scenario and carries its threshold, as in @accessibility:serious. |
accessibility.default_rules | string | 'wcag2a,wcag2aa' | - | The comma-separated axe-core tags that select the rules to check, in automatic mode and in the step that names no tags. |
accessibility.failure_threshold | string | 'any' | - | The impact at which a violation fails the scenario: critical, serious, moderate or minor fails on that impact or a worse one, any on every violation and never on none. Any other value fails on every violation, like any. An @accessibility:VALUE tag overrides it for 1 scenario. |
accessibility.fail_on_incomplete | boolean | FALSE | - | If TRUE, a finding axe-core can't decide fails the scenario, whatever the threshold. If FALSE, it doesn't. @accessibility:strict sets it to TRUE for 1 scenario. |
accessibility.cdn_url | string | 'https://cdn.jsdelivr.net/npm/axe-core@4.11.4/axe.min.js' | - | The URL of the axe-core script the trait loads into each page it assesses, or the absolute path of a local copy. The script is read once per run. |
accessibility.fetch_timeout | integer | 10 | - | The time, in seconds, an attempt to fetch the axe-core script over HTTP can go without receiving data before it fails. |
accessibility.fetch_attempts | integer | 3 | - | The number of attempts to fetch the axe-core script before the step fails, with a pause after each failed attempt that grows by half a second. A value below 1 counts as 1. |
accessibility.report_dir | string | '.logs/test_results/accessibility' | - | The directory each scenario's HTML and JUnit reports and the run's summary report are written to. A relative path resolves against the directory the run was launched from. |
Steps
@Then the page should pass accessibility checks
Assert that the current page passes accessibility checks
Then the page should pass accessibility checks
@Then the page should pass accessibility checks for the tags :tags
Assert that the current page passes accessibility checks for given tags
Then the page should pass accessibility checks for the tags "wcag2a"