Skip to content

Accessibility

The toBeAccessible() matcher tests the page for common accessibility issues based on WCAG 2.1 guidelines. Pass a Playwright Page. The checker evaluates the live DOM, so it catches issues that static analysis tools miss — dynamically rendered content, SPA state, and computed styles.

import { test, expect } from "@orlalabs/kovar";
test("dashboard is accessible", async ({ page }) => {
await page.goto("/dashboard");
await expect(page).toBeAccessible();
});

10 rules are evaluated:

RuleIDSeverityWCAG
Images missing alt texta11y-img-altmedium1.1.1 Non-text Content
Form inputs without labelsa11y-input-labelhigh1.3.1 Info and Relationships
Buttons without accessible namea11y-button-namehigh4.1.2 Name, Role, Value
Missing lang attribute on <html>a11y-document-langmedium3.1.1 Language of Page
Missing <title> elementa11y-page-titlemedium2.4.2 Page Titled
Links with no accessible texta11y-empty-linksmedium2.4.4 Link Purpose
Missing <main> landmarka11y-landmark-mainlow1.3.1 Info and Relationships
Insufficient color contrasta11y-color-contrastinfo1.4.3 Contrast (Minimum)
Heading hierarchy issuesa11y-heading-ordermedium1.3.1 Info and Relationships
Autoplay media without muteda11y-autoplay-mediamedium1.4.2 Audio Control

By default, info-level findings (like color contrast warnings) are excluded. Pass includeWarnings: true to include them.

await expect(page).toBeAccessible({
skip: ["a11y-color-contrast"], // skip specific rules by ID
only: ["a11y-img-alt"], // check only these rules
includeWarnings: true, // include info-level findings (default: false)
});
OptionTypeDescription
skipstring[]Rule IDs to skip
onlystring[]Check only these rule IDs
includeWarningsbooleanInclude info-level findings (default: false)
import { test, expect } from "@orlalabs/kovar";
test("accessibility with warnings", async ({ page, security }) => {
await page.goto("/dashboard");
const findings = await security.accessibility.check({ includeWarnings: true });
// Filter by specific rules
const labelIssues = findings.filter((f) => f.id === "a11y-input-label");
expect(labelIssues).toHaveLength(0);
});
  • Full Audit — include accessibility in a comprehensive audit with checks: ["accessibility"].
  • Standalone API — use checkAccessibility() outside Playwright.
  • OWASP ASVS — accessibility findings can be mapped to compliance requirements.