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+ } ) ;
0 commit comments