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"""
@@ -43,6 +46,19 @@ class Starter(ProcessStarter):
43
46
xprocess .getinfo ("page_url" ).terminate ()
44
47
45
48
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
+
46
62
def test_destination (
47
63
loaded_route : str ,
48
64
page_url : tuple [Page , str ],
@@ -79,6 +95,13 @@ def test_headers_in_language(page_url: tuple[Page, str], route: str) -> None:
79
95
] # urls start with the language if not en
80
96
assert doc_lang == lang
81
97
98
+ axe = Axe ()
99
+ results = axe .run (page )
100
+
101
+ assert (
102
+ len (results ["violations" ]) == 0
103
+ ), f"Accessibility violations found: { results ['violations' ]} "
104
+
82
105
83
106
@pytest .mark .parametrize (
84
107
"title, url" ,
@@ -96,13 +119,27 @@ def test_bpdevs_title_en(page_url: tuple[Page, str], title: str, url: str) -> No
96
119
page .goto (f"{ live_server_url } { url } " )
97
120
expect (page ).to_have_title (f"Black Python Devs | { title } " )
98
121
122
+ axe = Axe ()
123
+ results = axe .run (page )
124
+
125
+ assert (
126
+ len (results ["violations" ]) == 0
127
+ ), f"Accessibility violations found: { results ['violations' ]} "
128
+
99
129
100
130
def test_mailto_bpdevs (page_url : tuple [Page , str ]) -> None :
101
131
page , live_server_url = page_url
102
132
page .goto (live_server_url )
103
133
mailto = page .get_by_role ("link" , name = "email" )
104
134
expect (mailto ).to_have_attribute ("href" , "mailto:contact@blackpythondevs.com" )
105
135
136
+ axe = Axe ()
137
+ results = axe .run (page )
138
+
139
+ assert (
140
+ len (results ["violations" ]) == 0
141
+ ), f"Accessibility violations found: { results ['violations' ]} "
142
+
106
143
107
144
@pytest .mark .parametrize (
108
145
"url" ,
@@ -115,6 +152,13 @@ def test_page_description_in_index_and_blog(page_url: tuple[Page, str], url: str
115
152
expect (page .locator ("p.post-description" ).first ).to_be_visible ()
116
153
expect (page .locator ("p.post-description" ).first ).not_to_be_empty ()
117
154
155
+ axe = Axe ()
156
+ results = axe .run (page )
157
+
158
+ assert (
159
+ len (results ["violations" ]) == 0
160
+ ), f"Accessibility violations found: { results ['violations' ]} "
161
+
118
162
119
163
def stem_description (
120
164
path : pathlib .Path ,
@@ -146,3 +190,10 @@ def test_page_blog_posts(
146
190
page .locator ('meta[name="description"]' ).get_attribute ("content" )
147
191
== frontmatter ["description" ]
148
192
)
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