Trang chủ
QA Learning Hub
Chương 15 · Accessibility Testing
Chương 15 Trung Cấp

Accessibility Testing

WCAG 2.1 AA compliance, keyboard navigation, screen reader testing — bắt buộc với sản phẩm US market (ADA compliance).

WCAG 2.1 — 4 Nguyên Tắc POUR
  • PerceivableThông tin và UI có thể nhận biết bằng mọi sense. Test: alt text cho images, captions cho videos, không dùng chỉ màu sắc để convey information.
  • OperableTất cả functionality dùng được bằng keyboard (không chỉ mouse). Test: keyboard navigation, focus visible, không có time limits không cần thiết, no seizure-triggering content.
  • UnderstandableText readable, behavior predictable, errors được identify và có hướng dẫn fix. Test: clear error messages, consistent navigation, language attribute đúng.
  • RobustContent parse được bởi assistive technologies. Test: valid HTML, ARIA correct, semantic markup, compatible với screen readers.
CriterionLevelWhat to TestPass ExampleFail Example
1.1.1 Non-text ContentAAlt text cho imagesalt="Product photo of red shoes"alt="" on informative image
1.4.3 ContrastAAText contrast ratio ≥ 4.5:1Dark text on white = ~21:1Gray #999 on white = 2.85:1
2.1.1 KeyboardAAll functionality via keyboardTab, Enter, Space navigate entire formCustom dropdown only works with mouse
2.4.7 Focus VisibleAAFocus indicator visibleBlue outline on focused buttonoutline: none with no replacement
3.3.1 Error IDAErrors described in text"Email is required" inline errorField turns red only, no text
4.1.2 Name/Role/ValueAUI components have accessible name<button aria-label="Close dialog">Icon-only button with no label
⌨️ Keyboard Navigation Testing

Chỉ dùng keyboard để test — không chạm mouse:

  1. Tab Order: Nhấn Tab từ đầu trang. Focus phải di chuyển theo thứ tự logic (top-left → bottom-right, theo reading order). Không có jumps bất thường.
  2. Focus Indicator: Tại mỗi focused element, phải nhìn thấy rõ ràng element nào đang focused (outline, highlight, underline). Không bao giờ "lost focus."
  3. Activation: Button → Enter hoặc Space. Link → Enter. Checkbox → Space. Radio → Arrow keys. Dropdown → Space/Arrow/Enter.
  4. Modal/Dialog: Khi modal mở, focus phải trap trong modal (Tab không ra ngoài). Escape đóng modal. Sau khi đóng, focus trả về element đã trigger modal.
  5. Navigation Menu: Arrow keys điều hướng trong menu. Escape collapse menu. Enter/Space select item.
  6. Skip Links: Đầu trang nên có "Skip to main content" link (thường ẩn, chỉ hiện khi focused). Enter → focus nhảy tới main content. Quan trọng cho screen reader users.
  7. Carousels/Sliders: Arrow keys để navigate. Pause button accessible bằng keyboard.
🗣️ Screen Reader Testing

Screen Readers phổ biến:

  • NVDA (Windows)Free, open-source. Phổ biến nhất Windows. Dùng với Chrome hoặc Firefox. Download: nvaccess.org. Keys: Insert+F7 = elements list, Insert+Space = toggle browse/focus mode.
  • VoiceOver (macOS)Built-in, miễn phí. Bật: Cmd+F5 hoặc System Preferences → Accessibility. Dùng với Safari. VO+Arrow = navigate, VO+Space = activate.
  • VoiceOver (iOS)Settings → Accessibility → VoiceOver. Swipe để navigate, double-tap để activate. Critical vì nhiều người khiếm thị dùng iPhone.
  • TalkBack (Android)Built-in Android screen reader. Settings → Accessibility → TalkBack. Swipe navigate, double-tap activate.

Khi test với screen reader, verify:

  • Page title announces correctly khi navigate đến page mới
  • Images: informative images có meaningful alt text; decorative images có alt="" (skip được)
  • Form inputs: label được đọc khi focus vào input
  • Buttons: purpose rõ ràng ("Submit Order" không phải "Click here")
  • Error messages: announced automatically khi form submit fails (aria-live)
  • Modal: "dialog" role được announce, close button accessible
  • Dynamic content updates: aria-live regions announce changes
🎨 Color & Visual Accessibility
  • Contrast Ratio: Normal text: minimum 4.5:1 (AA). Large text (≥18pt or 14pt bold): 3:1. Check tại webaim.org/resources/contrastchecker
  • Không dùng chỉ màu sắc: Error fields phải có icon + text + màu đỏ, không chỉ màu đỏ. Graphs phải có labels/patterns ngoài màu sắc.
  • Zoom 200%: Ctrl+ (Windows) hoặc Cmd+ (Mac) zoom tới 200%. Content phải vẫn readable, không bị cắt, không bị horizontal scroll (trừ tables/maps).
  • Color blindness: Chrome DevTools → Rendering → Emulate vision deficiencies. Test Deuteranopia (phổ biến nhất), Protanopia, Achromatopsia.
  • Focus indicator contrast: Focus outline cũng phải đủ contrast. White outline trên white background = invisible.
💡 Quick Contrast Check
WebAIM Contrast Checker (webaim.org/resources/contrastchecker): nhập foreground và background color → instant pass/fail cho WCAG AA và AAA. Chrome DevTools cũng highlight low-contrast elements trong Accessibility panel.
🏷️ ARIA Attributes Quan Trọng
  • aria-labelĐặt tên cho element khi không có visible text: <button aria-label="Close">×</button>. Screen reader đọc label thay vì "×".
  • aria-describedbyLink input với helper text/error: <input aria-describedby="email-error">. Screen reader đọc description khi focus.
  • aria-expandedTrạng thái mở/đóng: aria-expanded="true/false" trên button điều khiển dropdown/accordion.
  • aria-liveAnnounce dynamic changes: aria-live="polite" (đợi user xong), aria-live="assertive" (interrupt ngay). Dùng cho error messages, status updates.
  • aria-hiddenaria-hidden="true" ẩn element khỏi screen reader. Dùng cho decorative icons bên cạnh text label. Đừng dùng để ẩn important content.
  • roleGán semantic role: role="alert" cho errors, role="dialog" cho modals, role="navigation" cho nav. Dùng HTML semantic elements khi có thể.
🤖 Automated Accessibility Scanning
  • axe DevToolsChrome/Firefox extension (free). Scan page → list violations với severity và fix guidance. Best free tool. axe-core cũng có thể integrate vào Playwright: await checkA11y(page).
  • LighthouseBuilt-in Chrome DevTools → Lighthouse → Accessibility score 0-100. Shows specific violations. Run in CI với lighthouse-ci npm package.
  • WAVEwave.webaim.org — paste URL hoặc dùng extension. Visual overlay hiển thị errors/warnings/features directly trên page.
  • Pa11yCLI tool, Node.js. pa11y https://example.com. Tích hợp vào CI pipeline. Config WCAG level và rules.
⚠️ Automated Tools không đủ
Automated tools chỉ catch ~30-40% accessibility issues. Những gì cần manual test: keyboard navigation flow, screen reader experience, cognitive accessibility, focus management trong complex interactions. Automation = good starting point, not complete coverage.
🏆 Senior Insight: ADA Compliance Risk

Ở US, Americans with Disabilities Act (ADA) áp dụng cho websites. Nhiều companies đã bị kiện vì non-accessible sites (Domino's Pizza, Beyoncé.com). Senior QA nên include accessibility trong Definition of Done và provide metrics (axe violations count) trong sprint report. Không phải "nice to have" — đây là legal requirement.

✏️ Bài Tập
📝 Bài Tập: Accessibility Audit

Chọn một form đăng ký (registration form) bất kỳ. Audit và tìm accessibility issues:

  1. Dùng chỉ keyboard để hoàn thành form — ghi lại tất cả issues với keyboard navigation
  2. Chạy axe DevTools extension — screenshot kết quả và phân loại issues theo severity
  3. Check contrast ratio của ít nhất 3 text elements bằng WebAIM Contrast Checker
  4. Tắt CSS styles (Chrome DevTools → Sources → Snippets: document.body.style.display='block' sau khi clear) — content có vẫn readable theo đúng order không?
  5. Viết bug reports cho 3 issues nghiêm trọng nhất tìm được, với WCAG criterion reference