LESSON VIEW
LAB-7 · AUTOMATION PRACTICE LAB · PRACTICAL QA

Visual & Accessibility Checks

Objective: Add visual checks (approved baselines, tuned thresholds, masked dynamism) and accessibility checks (axe-style scans at meaningful states, gated on new violations) to the suite — and schedule the human audits neither can replace.

⏱ ≈2.5 h practice unit · Code: copy, paste, practise · English edition — Español · العربية · বাংলা in translation

🧽 The practice business: FreshNest Home Cleaning — a fictional local cleaning company (owner: Maya Torres) invented for this course. Every example and exercise uses FreshNest, so you learn on a complete, realistic business without ever touching a real one.

⚡ Key Points

  • A page can pass every DOM check and still be visually broken — existence is not appearance.
  • A visual check = baseline + candidate + diff + a human decision. Auto-approval hides change.
  • Tolerance forgives rendering noise; max-diff percentage forgives a small amount of real change. Tune separately.
  • Baselines are captured in CI, one set per project — laptop baselines manufacture false diffs.
  • Scanners catch the mechanical layer, humans judge meaning — so scan states, not loads, and baseline legacy violations only as a repayment plan gated on new ones.

📖 Read

Every functional check so far asked the DOM questions: is the heading there, does the link work? But a page can pass all of those while being visually broken — the heading overlaps the button, the logo is stretched, the text runs off the card. The elements all exist; the user's eyes say disaster. A visual check is three artifacts and a decision: a baseline (the approved appearance, captured in a controlled environment), a candidate (this run's screenshot, same conditions), a diff (the pixels that changed beyond the threshold), and a decision — a human accepts the change as the new baseline, or rejects it as a bug. The machine flags; the human judges. Any tool that auto-approves is a change-hider, not a change-detector. The pairing rule runs through the whole unit: visual diffs prove appearance changed; functional assertions prove behaviour works. A page can be pixel-perfect and dead — buttons inert, beautifully — so neither layer substitutes for the other.

Thresholds are two different knobs, tuned separately and with the reasons written down. Per-pixel tolerance forgives rendering differences — anti-aliasing and font rasterisation noise. Max-diff percentage forgives a small amount of genuinely changed pixels. Baselines must be captured in the CI environment itself, one baseline set per project (browser × viewport), because a laptop baseline manufactures false diffs against CI candidates for font-rendering reasons alone. The rest is flake control for pixels: mask or freeze dynamic regions (dates, prices, adverts, rotating heroes), capture settled states only rather than animations mid-flight, and assert lazy images have loaded before capture. The meta-rule: capture determinism is engineered, like any other feature. Visual checks earn their keep on high-value, layout-dense, change-frequent surfaces — marketing pages, pricing, checkout, dashboards — and not on volatile data tables or third-party embeds. Scope discipline is what keeps the approval queue small enough that humans still read it. In Playwright, the built-in route is the screenshot assertion (toHaveScreenshot) in a suite you extend yourself, standing on the evidence capture your config already does on every run.

Accessibility splits the same way, into a mechanical layer and a judgment layer. Automated scanners (the best-known engine is axe) reliably catch the mechanical layer: missing labels, missing alt text, empty buttons, insufficient colour contrast, broken heading order, missing page language. What no scanner can judge is whether alt text is meaningful ("image123.jpg" passes existence checks and helps nobody), whether tab order makes sense, or whether an error message is understandable — those need a human with assistive technology in hand. Your locators have been doing accessibility work all along: role plus accessible name is exactly what a screen reader announces, so when getByRole cannot find an element, a screen reader probably cannot either. Engineering the scan layer means: scan states, not just page loads (a form's error state, an open modal — violations live in states, and a load-only scan certifies the one state users leave immediately); scope deliberately (key templates once per run, components where they are composed, full pages on a schedule, each scan attached to a case ID); and baseline legacy violations only as a repayment plan — an owner, a burn-down, and gating on new violations, asserting zero critical or serious new violations on gated pages. Scanners find; targeted assertions keep — a found violation is fixed, then guarded by a cheap permanent check at the cheapest layer, often a label assertion inside the Page Object. The judgment layer goes on the calendar: quarterly, and at every major redesign — keyboard-only journey completion, a screen-reader pass on the money flows, zoom and reflow, reduced-motion behaviour — with findings joining the same backlog as scanner findings.

💻 Code for this unit — copy, paste, practise

The original worked code for this unit, verbatim, with its line-by-line explanations. Run it against the course practice project (download on the course page).

B-12 · Example 1 — Visual testing

use: { baseURL, trace: "on", video: "on", screenshot: "only-on-failure" }

From the module's full text.

B-13 · Example 1 — Accessibility testing

page.getByRole("button", { name: "Send" })

Role + name is exactly what a screen reader announces (“button, Send”). When your test finds elements the way assistive tech experiences them, passing tests quietly PROVE those names exist. If getByRole can't find it — a screen reader probably can't either.