Skip to content

Commit eae75ce

Browse files
feat: added accessibility example
1 parent 58bddc4 commit eae75ce

File tree

3 files changed

+119
-22
lines changed

3 files changed

+119
-22
lines changed

basic/7-accessibility.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { test, expect } from "@playwright/test";
2+
import AxeBuilder from "@axe-core/playwright"; // 1
3+
4+
test.describe("homepage", () => {
5+
// 2
6+
test("should not have any automatically detectable accessibility issues", async ({
7+
page,
8+
}) => {
9+
await page.goto("https://currents.dev/"); // 3
10+
11+
const accessibilityScanResults = await new AxeBuilder({ page }).analyze(); // 4
12+
13+
expect(accessibilityScanResults.violations).toEqual([]); // 5
14+
});
15+
});
16+
17+
test("navigation menu should not have automatically detectable accessibility violations", async ({
18+
page,
19+
}) => {
20+
await page.goto("https://currents.dev/");
21+
22+
await page.getByRole("button", { name: "Navigation Menu" }).click();
23+
24+
// It is important to waitFor() the page to be in the desired
25+
// state *before* running analyze(). Otherwise, axe might not
26+
// find all the elements your test expects it to scan.
27+
await page.locator("#navigation-menu-flyout").waitFor();
28+
29+
const accessibilityScanResults = await new AxeBuilder({ page })
30+
.include("#navigation-menu-flyout")
31+
.analyze();
32+
33+
expect(accessibilityScanResults.violations).toEqual([]);
34+
});
35+
36+
37+
test('should not have any automatically detectable WCAG A or AA violations', async ({ page }) => {
38+
await page.goto("https://currents.dev/");
39+
40+
const accessibilityScanResults = await new AxeBuilder({ page })
41+
.withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'])
42+
.analyze();
43+
44+
expect(accessibilityScanResults.violations).toEqual([]);
45+
});

package-lock.json

Lines changed: 73 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"dependencies": {
2121
"@axe-core/playwright": "^4.4.4",
22-
"@currents/playwright": "^1.5.6",
22+
"@currents/playwright": "^1.5.11",
2323
"express": "^4.17.2",
2424
"lighthouse": "^9.5.0",
2525
"node-fetch": "^3.1.0",

0 commit comments

Comments
 (0)