QA AND TEST AUTOMATION · PART 5 · UI WEB AUTOMATION · TECHNIQUE · 59 OF 112

Accessibility Testing: ARIA Snapshots and axe

Testing that everyone can use the product: WCAG and its principles, automated axe scans in Playwright, run for real on ShopRung (login and product pages clean; the home page flagged 12 serious "label-content-name-mismatch" issues on its Add to cart buttons), ARIA snapshots of the header, keyboard checks, what automation cannot find, and manual screen reader testing.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 67
  63. 68
  64. 69
  65. 70
  66. 71
  67. 72
  68. 73
  69. 74
  70. 75
  71. 76
  72. 77
  73. 78
  74. 79
  75. 80
  76. 81
  77. 82
  78. 83
  79. 84
  80. 85
  81. 86
  82. 87
  83. 88
  84. 89
  85. 90
  86. 91
  87. 92
  88. 93
  89. 94
  90. 95
  91. 96
  92. 97
  93. 98
  94. 99
  95. 100
  96. 101
  97. 102
  98. 103
  99. 104
  100. 105
  101. 106
  102. 107
  103. 108
  104. 109
  105. 110
  106. 111
  107. 112
1 / 12

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • WCAG 2.2 AA and POUR
  • axe in tests
  • label in name
  • ARIA snapshots
  • keyboard
  • manual screen reader checks

Notes

WCAG

The main standard is WCAG, the Web Content Accessibility Guidelines from the W3C, currently version two point two. Its four principles spell POUR. Perceivable: text alternatives, contrast, captions. Operable: everything works by keyboard, users have enough time, nothing flashes dangerously. Understandable: clear labels and error messages, predictable behaviour. Robust: works with assistive technology. Success criteria have levels A, AA and AAA; most laws and policies target AA.

WCAG in one screen
  • Web Content Accessibility Guidelines (W3C), now 2.2
  • Perceivable: alt text, contrast, captions
  • Operable: keyboard, time, no seizures, navigation
  • Understandable: labels, errors, predictable
  • Robust: works with assistive tech (valid roles, names)
  • most laws target level AA

Automated scans

Axe core is the most widely used accessibility rules engine, and the axe Playwright package runs it inside a test. Open the page and wait until it has rendered, because ShopRung builds pages with JavaScript. Then build an axe scan limited to WCAG A and AA rules, analyse, and expect no violations. Each violation lists the rule, its impact, the elements involved and how to fix them.

tests/a11y.spec.ts
import AxeBuilder from
  "@axe-core/playwright";

await page.goto("/#/login");
await page.locator("main h1")
  .waitFor();
const r = await new AxeBuilder(
  { page }).withTags(["wcag2a",
  "wcag2aa", "wcag21a", "wcag21aa"])
  .analyze();
expect(r.violations).toEqual([]);

A real finding

We scanned three ShopRung pages. Login: no violations. Product: no violations. Home: twelve serious violations of one rule, label content name mismatch, one for each add to cart button. The visible text says add to cart, but the accessible name, from the aria label, is add clean code notebook to cart, and the visible words are not contained in it. This is the same button that surprised us in the locators episode.

Real results
login    violations: none
product  violations: none
home     label-content-name-
         mismatch (serious) x12

button[data-add="1"]
  visible text: "Add to cart"
  accessible name: "Add Clean
    Code Notebook to cart"
"Text inside the element is not
 included in the accessible name"

Why it matters

Why does it matter? It breaks WCAG's label in name rule. A person using voice control looks at the screen and says click add to cart. Their software matches the spoken words against accessible names, and add clean code notebook to cart does not contain the phrase. A fix keeps the visible words inside the name, for example add to cart, clean code notebook, or keeps the visible text and adds a visually hidden product name after it.

WCAG 2.5.3 Label in Name
  • a voice control user says: "click Add to cart"
  • the name must CONTAIN the visible words to match
  • fix options: name "Add to cart: Clean Code Notebook" or visible text + visually hidden product name

ARIA snapshots

Playwright's ARIA snapshots capture the accessibility tree as readable YAML. This is ShopRung's real header: a navigation named main with links for products, cart zero, orders and log in, and a search landmark with a labelled search box and a search button. To match aria snapshot asserts this structure, so if someone removes a label or turns a link into an unlabelled icon, the test fails with a clear diff.

The header, as a screen reader
- navigation "Main":
  - link "Products"
  - link "Cart 0"
  - link "Orders"
  - link "Log in"
- search:
  - searchbox "Search products"
  - button "Search"

expect(nav).toMatchAriaSnapshot(
  `...`)

Keyboard

Keyboard users move with tab and activate with enter or space. Tests can press tab and check which element has focus. On ShopRung, tabbing from the page went to the category filter, then each product's link and its add button in reading order, which is logical. Also check that focus is always visible, nothing traps focus, enter and space activate controls, and escape closes dialogs.

Keyboard checks
await page.keyboard.press("Tab");
expect(page.locator(":focus"))

ShopRung tab order (real):
  category → product link →
  its Add button → next
  product ... (logical)

check: visible focus, no traps,
  Enter/Space activate,
  Esc closes dialogs

Limits of automation

Automated scanners catch a useful share of issues, such as missing labels, low contrast and invalid ARIA, but many problems need judgment. Is the alt text meaningful, or just image? Is the reading order sensible? Do error messages help? Does the page work at two hundred or four hundred percent zoom? Can someone complete checkout with a screen reader? Treat automated results as a floor, not a certificate.

Needs a human
  • is the alt text MEANINGFUL?
  • is the reading order sensible?
  • do error messages help?
  • does it work at 200-400% zoom?
  • is the flow usable with a screen reader?
  • do custom widgets behave like their role?
  • automated = a floor, not a certificate

Manual testing

A practical manual routine. Complete the main journey with the keyboard only. Repeat it with a screen reader: NVDA on Windows, VoiceOver on Mac and iPhone, TalkBack on Android. Zoom to two hundred and four hundred percent. Check that colour is never the only way meaning is shown, like red for errors without text. Best of all, include people with disabilities in usability sessions.

A practical routine
  • keyboard only: full journey
  • screen reader: NVDA (Windows), VoiceOver (macOS, iOS), TalkBack (Android)
  • zoom 200% and 400%, and text spacing
  • colour: contrast, not colour alone for meaning
  • best: sessions with disabled users

Common mistakes

Mistakes. Believing a clean axe scan means the product is accessible. Scanning before a JavaScript page has rendered, which reports nothing. Disabling rules to get a green build. Adding aria labels everywhere: as ShopRung showed, an aria label can create a problem, and the common advice is that no ARIA is better than bad ARIA. And leaving accessibility to the end, when fixes are most expensive.

Avoid these
  • "axe passed, so we are accessible"
  • scanning before the page has rendered
  • disabling rules to go green
  • aria-label everywhere (no ARIA is better than bad ARIA)
  • testing only at the end

Say it like this

In the interview: I test against WCAG two point two AA. In CI, axe scans key pages after they render, ARIA snapshots protect key components, and tests cover keyboard navigation. Manually, I run keyboard only and screen reader journeys and check zoom and contrast. Automation is a floor, not a certificate; for example, axe flagged our add to cart buttons for a label in name problem that affects voice control users.

In the interview
  • "Against WCAG 2.2 AA. In CI: axe scans of key pages after render, ARIA snapshots of key
  • components, keyboard tests.
  • Manually: keyboard-only and screen reader journeys, zoom, contrast. Automation is a floor; e.g. axe flagged our Add to cart buttons for label-in-name."

Interview questions

Q1What is WCAG?

The Web Content Accessibility Guidelines from the W3C (currently 2.2), organised under perceivable, operable, understandable and robust, with levels A, AA and AAA.

Q2What is axe-core?

An open-source accessibility rules engine that scans the DOM for issues such as missing labels, low contrast and invalid ARIA; it integrates with Playwright, Selenium and Cypress.

Q3Can automated tools guarantee accessibility?

No. They catch a portion of issues; meaningful alt text, reading order, usability with screen readers and many others need manual testing.

Q4What is an accessible name?

The name assistive technology announces for an element, from aria-labelledby, aria-label, an associated label or the element's content.

Q5What does WCAG 2.5.3 Label in Name require?

When a control has visible text, its accessible name must contain that text, so voice control users can activate it by saying what they see.

Q6What is an ARIA snapshot in Playwright?

A YAML representation of an element's accessibility tree that can be asserted with toMatchAriaSnapshot to catch structural or labelling regressions.

Q7How do you test keyboard accessibility?

Navigate with Tab/Shift+Tab, activate with Enter/Space, close with Esc, and check focus order, visible focus and no keyboard traps.

Q8Which screen readers should testers know?

NVDA and JAWS on Windows, VoiceOver on macOS and iOS, and TalkBack on Android.