77from playwright .sync_api import Page , expect , sync_playwright
88
99
10+ from axe_core_python .sync_playwright import Axe
11+
12+
1013@pytest .fixture (scope = "module" )
1114def page_url (xprocess , url_port ):
1215 """Returns the url of the live server"""
@@ -42,6 +45,15 @@ class Starter(ProcessStarter):
4245 # Clean up the process
4346 xprocess .getinfo ("page_url" ).terminate ()
4447
48+ def test_accessibility (page_url : tuple [Page , str ]):
49+ """Run accessibility tests on the homepage"""
50+ page , live_server_url = page_url
51+ page .goto (f"{ live_server_url } /" )
52+
53+ axe = Axe ()
54+ results = axe .run (page )
55+
56+ assert len (results ["violations" ]) == 0 , f"Accessibility violations found: { results ['violations' ]} "
4557
4658def test_destination (
4759 loaded_route : str ,
@@ -79,6 +91,12 @@ def test_headers_in_language(page_url: tuple[Page, str], route: str) -> None:
7991 ] # urls start with the language if not en
8092 assert doc_lang == lang
8193
94+ axe = Axe ()
95+ results = axe .run (page )
96+
97+ assert len (results ["violations" ]) == 0 , f"Accessibility violations found: { results ['violations' ]} "
98+
99+
82100
83101@pytest .mark .parametrize (
84102 "title, url" ,
@@ -96,13 +114,25 @@ def test_bpdevs_title_en(page_url: tuple[Page, str], title: str, url: str) -> No
96114 page .goto (f"{ live_server_url } { url } " )
97115 expect (page ).to_have_title (f"Black Python Devs | { title } " )
98116
117+ axe = Axe ()
118+ results = axe .run (page )
119+
120+ assert len (results ["violations" ]) == 0 , f"Accessibility violations found: { results ['violations' ]} "
121+
122+
99123
100124def test_mailto_bpdevs (page_url : tuple [Page , str ]) -> None :
101125 page , live_server_url = page_url
102126 page .goto (live_server_url )
103127 mailto = page .get_by_role ("link" , name = "email" )
104128 expect (
mailto ).
to_have_attribute (
"href" ,
"mailto:[email protected] " )
105129
130+ axe = Axe ()
131+ results = axe .run (page )
132+
133+ assert len (results ["violations" ]) == 0 , f"Accessibility violations found: { results ['violations' ]} "
134+
135+
106136
107137@pytest .mark .parametrize (
108138 "url" ,
@@ -115,6 +145,12 @@ def test_page_description_in_index_and_blog(page_url: tuple[Page, str], url: str
115145 expect (page .locator ("p.post-description" ).first ).to_be_visible ()
116146 expect (page .locator ("p.post-description" ).first ).not_to_be_empty ()
117147
148+ axe = Axe ()
149+ results = axe .run (page )
150+
151+ assert len (results ["violations" ]) == 0 , f"Accessibility violations found: { results ['violations' ]} "
152+
153+
118154
119155def stem_description (
120156 path : pathlib .Path ,
@@ -146,3 +182,9 @@ def test_page_blog_posts(
146182 page .locator ('meta[name="description"]' ).get_attribute ("content" )
147183 == frontmatter ["description" ]
148184 )
185+
186+ axe = Axe ()
187+ results = axe .run (page )
188+
189+ assert len (results ["violations" ]) == 0 , f"Accessibility violations found: { results ['violations' ]} "
190+
0 commit comments