A11y: add fixture and matcher for a11y tests with Axe#2462
Conversation
| expect(report).toHaveNoA11yViolations({ | ||
| // this is the complete list of a11y violations on this page today. maybe we want to do something more flake-proof here, | ||
| // but I do like that this test confirms that some violations are actually being detected | ||
| ignoredRules: ['label', 'list', 'listitem', 'page-has-heading-one'], |
There was a problem hiding this comment.
to see how the custom matcher outputs violations, comment out this line and run the e2es (npm run playwright:test -- --grep accessibility)
There was a problem hiding this comment.
2) [admin-wide-screen] › tests/as-admin-user/a11y/accessibility.spec.ts:4:7 › scanForA11yViolations › runs a11y audit against a basic page
Error: 3 Axe violations found (Threshold: 0)
Axe Violations:
- Rule: Ensure every form element has a label
ID: label (https://dequeuniversity.com/rules/axe/4.11/label?application=playwright)
Impact: critical
Affected nodes:
- <input class="" autocapitalize="none" autocomplete="off" autocorrect="off" id="react-select-2-input" spellcheck="false" tabindex="0" type="text" aria-autocomplete="list" aria-expanded="false" aria-haspopup="true" role="combobox" aria-activedescendan...="" data-testid="data-testid Dashboar..." value= ...>
- Rule: Ensure that lists are structured correctly
ID: list (https://dequeuniversity.com/rules/axe/4.11/list?application=playwright)
Impact: serious
Affected nodes:
- <ul class="css-7vg4ns" aria-label="Navigation">
- Rule: Ensure <li> elements are used semantically
ID: listitem (https://dequeuniversity.com/rules/axe/4.11/listitem?application=playwright)
Impact: serious
Affected nodes:
- <li class="css-njbp03">
- <li class="css-njbp03">
- <li class="css-njbp03">
- <li class="css-njbp03">
- <li class="css-njbp03">
- <li class="css-njbp03">
- <li class="css-njbp03">
- <li class="css-njbp03">
- <li class="css-njbp03">
There was a problem hiding this comment.
Pull request overview
Adds first-class accessibility (a11y) testing support to @grafana/plugin-e2e by integrating Axe with Playwright and providing an ergonomic assertion matcher for test authors.
Changes:
- Introduces a
scanForA11yViolationsfixture that runs Axe scans on the current Playwright page. - Adds a
toHaveNoA11yViolationscustom matcher to produce readable assertions and output. - Adds an E2E spec covering the fixture + matcher behavior and wires in Axe dependencies.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/plugin-e2e/tests/as-admin-user/a11y/accessibility.spec.ts | Adds E2E coverage for the new fixture/matcher (and demonstrates usage). |
| packages/plugin-e2e/src/types.ts | Exposes the new fixture type in the public PluginFixture API. |
| packages/plugin-e2e/src/matchers/toHaveNoA11yViolations.ts | Implements the custom matcher for Axe results. |
| packages/plugin-e2e/src/index.ts | Wires the new fixture and matcher into the exported test/expect. |
| packages/plugin-e2e/src/fixtures/scanForA11yViolations.ts | Implements the Axe-backed fixture. |
| packages/plugin-e2e/package.json | Adds Axe-related dependencies. |
| package-lock.json | Lockfile updates for new dependencies. |
packages/plugin-e2e/tests/as-admin-user/a11y/accessibility.spec.ts
Outdated
Show resolved
Hide resolved
packages/plugin-e2e/tests/as-admin-user/a11y/accessibility.spec.ts
Outdated
Show resolved
Hide resolved
| (options?: AxeRunOptions) => Promise<AxeResults>, | ||
| PlaywrightArgs | ||
| > = async ({ page }, use, testInfo) => { | ||
| const builder = new AxeBuilder({ page }).withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa' /*'best-practice'*/]); |
There was a problem hiding this comment.
this set of default tags can be overridden by passing options in, which is kind of demonstrated in the test. More on how to do that here: https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#options-parameter-examples
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…c.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…c.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
sunker
left a comment
There was a problem hiding this comment.
This looks like a great start @fastfrwrd. Added a few comments.
…given test if the fixture is run more than once
ashharrison90
left a comment
There was a problem hiding this comment.
lgtm 👍
let's go! 🚀
sunker
left a comment
There was a problem hiding this comment.
Just a few minor comments. I think it's fine to mark these APIs as alpha and iterate on them. We should probably avoid announcing this feature internally until it's completed though.
packages/plugin-e2e/tests/as-admin-user/a11y/accessibility.spec.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Playwright test results
Troubleshooting404 when clicking on
|
|
🚀 PR was released in |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Implements #2457
📦 Published PR as canary version:
Canary Versions✨ Test out this PR locally via:
npm install @grafana/plugin-e2e@3.4.0-canary.2462.22402131260.0 # or yarn add @grafana/plugin-e2e@3.4.0-canary.2462.22402131260.0