7
7
from playwright .sync_api import Page , expect , sync_playwright
8
8
9
9
10
+ from axe_core_python .sync_playwright import Axe
11
+
12
+
10
13
@pytest .fixture (scope = "module" )
11
14
def page_url (xprocess , url_port ):
12
15
"""Returns the url of the live server"""
@@ -42,6 +45,15 @@ class Starter(ProcessStarter):
42
45
# Clean up the process
43
46
xprocess .getinfo ("page_url" ).terminate ()
44
47
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' ]} "
45
57
46
58
def test_destination (
47
59
loaded_route : str ,
@@ -79,6 +91,12 @@ def test_headers_in_language(page_url: tuple[Page, str], route: str) -> None:
79
91
] # urls start with the language if not en
80
92
assert doc_lang == lang
81
93
94
+ axe = Axe ()
95
+ results = axe .run (page )
96
+
97
+ assert len (results ["violations" ]) == 0 , f"Accessibility violations found: { results ['violations' ]} "
98
+
99
+
82
100
83
101
@pytest .mark .parametrize (
84
102
"title, url" ,
@@ -96,13 +114,25 @@ def test_bpdevs_title_en(page_url: tuple[Page, str], title: str, url: str) -> No
96
114
page .goto (f"{ live_server_url } { url } " )
97
115
expect (page ).to_have_title (f"Black Python Devs | { title } " )
98
116
117
+ axe = Axe ()
118
+ results = axe .run (page )
119
+
120
+ assert len (results ["violations" ]) == 0 , f"Accessibility violations found: { results ['violations' ]} "
121
+
122
+
99
123
100
124
def test_mailto_bpdevs (page_url : tuple [Page , str ]) -> None :
101
125
page , live_server_url = page_url
102
126
page .goto (live_server_url )
103
127
mailto = page .get_by_role ("link" , name = "email" )
104
128
expect (
mailto ).
to_have_attribute (
"href" ,
"mailto:[email protected] " )
105
129
130
+ axe = Axe ()
131
+ results = axe .run (page )
132
+
133
+ assert len (results ["violations" ]) == 0 , f"Accessibility violations found: { results ['violations' ]} "
134
+
135
+
106
136
107
137
@pytest .mark .parametrize (
108
138
"url" ,
@@ -115,6 +145,12 @@ def test_page_description_in_index_and_blog(page_url: tuple[Page, str], url: str
115
145
expect (page .locator ("p.post-description" ).first ).to_be_visible ()
116
146
expect (page .locator ("p.post-description" ).first ).not_to_be_empty ()
117
147
148
+ axe = Axe ()
149
+ results = axe .run (page )
150
+
151
+ assert len (results ["violations" ]) == 0 , f"Accessibility violations found: { results ['violations' ]} "
152
+
153
+
118
154
119
155
def stem_description (
120
156
path : pathlib .Path ,
@@ -146,3 +182,9 @@ def test_page_blog_posts(
146
182
page .locator ('meta[name="description"]' ).get_attribute ("content" )
147
183
== frontmatter ["description" ]
148
184
)
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