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"""
@@ -43,6 +46,19 @@ class Starter(ProcessStarter):
4346 xprocess .getinfo ("page_url" ).terminate ()
4447
4548
49+ def test_accessibility (page_url : tuple [Page , str ]):
50+ """Run accessibility tests on the homepage"""
51+ page , live_server_url = page_url
52+ page .goto (f"{ live_server_url } /" )
53+
54+ axe = Axe ()
55+ results = axe .run (page )
56+
57+ assert (
58+ len (results ["violations" ]) == 0
59+ ), f"Accessibility violations found: { results ['violations' ]} "
60+
61+
4662def test_destination (
4763 loaded_route : str ,
4864 page_url : tuple [Page , str ],
@@ -79,6 +95,13 @@ def test_headers_in_language(page_url: tuple[Page, str], route: str) -> None:
7995 ] # urls start with the language if not en
8096 assert doc_lang == lang
8197
98+ axe = Axe ()
99+ results = axe .run (page )
100+
101+ assert (
102+ len (results ["violations" ]) == 0
103+ ), f"Accessibility violations found: { results ['violations' ]} "
104+
82105
83106@pytest .mark .parametrize (
84107 "title, url" ,
@@ -96,13 +119,27 @@ def test_bpdevs_title_en(page_url: tuple[Page, str], title: str, url: str) -> No
96119 page .goto (f"{ live_server_url } { url } " )
97120 expect (page ).to_have_title (f"Black Python Devs | { title } " )
98121
122+ axe = Axe ()
123+ results = axe .run (page )
124+
125+ assert (
126+ len (results ["violations" ]) == 0
127+ ), f"Accessibility violations found: { results ['violations' ]} "
128+
99129
100130def test_mailto_bpdevs (page_url : tuple [Page , str ]) -> None :
101131 page , live_server_url = page_url
102132 page .goto (live_server_url )
103133 mailto = page .get_by_role ("link" , name = "email" )
104134 expect (
mailto ).
to_have_attribute (
"href" ,
"mailto:[email protected] " )
105135
136+ axe = Axe ()
137+ results = axe .run (page )
138+
139+ assert (
140+ len (results ["violations" ]) == 0
141+ ), f"Accessibility violations found: { results ['violations' ]} "
142+
106143
107144@pytest .mark .parametrize (
108145 "url" ,
@@ -115,6 +152,13 @@ def test_page_description_in_index_and_blog(page_url: tuple[Page, str], url: str
115152 expect (page .locator ("p.post-description" ).first ).to_be_visible ()
116153 expect (page .locator ("p.post-description" ).first ).not_to_be_empty ()
117154
155+ axe = Axe ()
156+ results = axe .run (page )
157+
158+ assert (
159+ len (results ["violations" ]) == 0
160+ ), f"Accessibility violations found: { results ['violations' ]} "
161+
118162
119163def stem_description (
120164 path : pathlib .Path ,
@@ -146,3 +190,10 @@ def test_page_blog_posts(
146190 page .locator ('meta[name="description"]' ).get_attribute ("content" )
147191 == frontmatter ["description" ]
148192 )
193+
194+ axe = Axe ()
195+ results = axe .run (page )
196+
197+ assert (
198+ len (results ["violations" ]) == 0
199+ ), f"Accessibility violations found: { results ['violations' ]} "
0 commit comments