Review visual regressions and accessibility
Visual checks answer a different question
A visual regression test compares a rendered image with an approved reference image. It can catch layout shifts, clipped labels or unexpected style changes that text assertions miss. A screenshot cannot prove a form submits or that keyboard users can reach a control. Choose a stable browser, OS, font set, viewport, device scale, locale, motion setting and synthetic dataset before approving a baseline. Do not copy snapshots from a different environment and silently increase tolerance until they pass.
import { test, expect } from '@playwright/test';for (const width of [320, 1024]) { test(`repair form at ${width}px`, async ({page}) => { await page.setViewportSize({width,height:800}); await page.goto('/tickets/new'); await expect(page.getByRole('heading',{name:'Repair desk'})).toBeVisible(); await page.evaluate(() => document.fonts.ready.then(() => undefined)); expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true); await expect(page.getByRole('main')).toHaveScreenshot(`repair-${width}.png`, { animations:'disabled', maxDiffPixels:0 }); });}These exact pixel comparisons are an intentionally strict starting point for a fixed lab environment; approve first-run baselines after human inspection and choose a documented tolerance for the actual product if needed. The example uses a narrow and a wide viewport; device emulation is not a physical phone. Disable unrelated animations and wait for fonts rather than sleeping. Compare screenshots only after checking the relevant view is ready. This runner-specific screenshot assertion is staged; local Python checks compare repeated native fixture screenshots separately.
Test keyboard access and right-to-left layout
import { test, expect } from '@playwright/test';test('keyboard can reach and submit the form', async ({page}) => { await page.route('**/api/tickets', route => route.fulfill({status:201,json:{id:'demo-3'}})); await page.goto('/tickets/new'); await page.keyboard.press('Tab'); await expect(page.getByRole('link',{name:'New ticket'})).toBeFocused(); await page.keyboard.press('Tab'); const input = page.getByLabel('Description'); await expect(input).toBeFocused(); await page.keyboard.type('Loose wheel'); await page.keyboard.press('Tab'); await expect(page.getByRole('button',{name:'Send ticket'})).toBeFocused(); await page.keyboard.press('Enter'); await expect(page.getByRole('status')).toHaveText('Ticket received');});test('narrow RTL layout does not overflow', async ({page}) => { await page.setViewportSize({width:320,height:800}); await page.goto('/tickets/new'); await page.evaluate(() => {document.documentElement.dir='rtl';}); expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);});The focus order is a contract for this small fixture, not a universal tab sequence. Test actual keyboard actions, not simply programmatically focusing each element. Setting dir checks layout direction only; it does not verify translation or bidirectional content. This English-only course still teaches how to test RTL. Add manual checks for focus visibility, zoom, accessible names and assistive-technology announcements.
Use automated accessibility checks as one layer
import { test, expect } from '@playwright/test';import AxeBuilder from '@axe-core/playwright';test('form has no detected WCAG A/AA violations in selected rules', async ({page}) => { await page.goto('/tickets/new'); const results = await new AxeBuilder({page}) .withTags(['wcag2a','wcag2aa','wcag21a','wcag21aa','wcag22aa']) .analyze(); expect(results.violations).toEqual([]);});The selected rule tags depend on the installed axe version; verify their coverage. A clean report means the selected automated rules detected no violations in that state, not that every WCAG criterion is satisfied. Scan error, pending and success states too. Do not hide violations with broad exclusions. Review false positives individually and record reasons. Practice: modify a local copy to remove the input label and verify that an accessible-name check detects the regression before restoring it.