Version 2.0
New features
Data grid, aria snapshots and a fake clock.
Version 1.9
Bug fixes
Timers no longer fire after leaving a page.
A page with a few deliberate problems. Write checks that find every one of them, as you would for a real release.
await expect(page).toHaveTitle('Page Audit · QA Playground');
await expect(page.locator('meta[name="description"]')).toHaveAttribute('content', /audit/i);
await expect(page.locator('html')).toHaveAttribute('lang', 'en');Every image needs an alt attribute. An empty alt="" is correct for decorative images; a missing one is a bug:
await expect(page.locator('main img:not([alt])')).toHaveCount(1);A broken image is still an element on the page, so toBeVisible() will not catch it. Wait until every image has finished loading, then check its naturalWidth: it is 0 when the file could not be shown.
const images = page.locator('main img');
await expect
.poll(() => images.evaluateAll((imgs) => imgs.every((img) => (img as HTMLImageElement).complete)))
.toBe(true);
const broken = await images.evaluateAll((imgs) =>
(imgs as HTMLImageElement[])
.filter((img) => img.naturalWidth === 0)
.map((img) => img.getAttribute('src'))
);
expect(broken).toEqual(['/images/team-photo.png']);Collect every same-site link and request it with the request fixture, without a browser. Use expect.soft() so one broken link does not hide the others: the test continues and reports all failures at the end.
test('links work', async ({ page, request }) => {
await page.goto('/content/page-audit');
const hrefs = await page
.locator('main a[href^="/"]')
.evaluateAll((links) => links.map((a) => a.getAttribute('href')!));
for (const href of hrefs) {
const response = await request.get(href);
expect.soft(response.status(), href).toBeLessThan(400);
}
});Leave external links out of automated checks: other sites are slow, rate-limited and outside your control.
Links that open a new tab should have rel="noopener", or the new page can control the old one:
await expect(page.locator('main a[target="_blank"]:not([rel~="noopener"])')).toHaveCount(1);Headings should go down one level at a time; screen-reader users navigate by them. Read the levels and look for jumps:
const levels = await page
.getByTestId('release-notes')
.getByRole('heading')
.evaluateAll((headings) => headings.map((h) => Number(h.tagName[1])));
const skips = levels.filter((level, i) => i > 0 && level - levels[i - 1] > 1);
expect(skips).toEqual([5]);Data grid, aria snapshots and a fake clock.
Timers no longer fire after leaving a page.
Read the guide: Playwright cheat sheet: locators, actions and assertions
