8
8
9
9
ACCESSIBILITY_STANDARDS = ["wcag2a" , "wcag2aa" ]
10
10
11
+
11
12
def check_accessibility (page : Page ):
12
- '''
13
+ """
13
14
Inserts axe core python into a page at the yield step
14
15
to run accessibility based testing. Axe will run on
15
16
the page defined in the function.
16
- '''
17
+ """
17
18
if page .title () != "localhost" :
18
19
directory = "tests/functional_tests/accessibility_output"
19
20
if not os .path .exists (directory ):
@@ -24,16 +25,16 @@ def check_accessibility(page: Page):
24
25
25
26
wcag_violations = []
26
27
27
- for violation in results [' violations' ]:
28
+ for violation in results [" violations" ]:
28
29
if set (violation ["tags" ]) & set (ACCESSIBILITY_STANDARDS ):
29
30
wcag_violations .append (violation )
30
-
31
+
31
32
if len (wcag_violations ) == 0 :
32
33
assert "No WCAG accessibility issues found"
33
34
else :
34
35
# Cleans the URL to remove any invalid characters and replace with _
35
36
invalid_filename_chars = r'[\/:*?"<>|]'
36
- sanitized_title = re .sub (invalid_filename_chars , '_' , page .title ())
37
+ sanitized_title = re .sub (invalid_filename_chars , "_" , page .title ())
37
38
38
39
max_title_len = 30
39
40
file_name = f"axe_results_{ sanitized_title [:max_title_len ]} .json"
@@ -44,17 +45,18 @@ def check_accessibility(page: Page):
44
45
45
46
@pytest .mark .usefixtures ("live_server" )
46
47
def test_all_page_accessibility (app , page : Page ):
47
- ignored_routes = [' static' , '/' ]
48
+ ignored_routes = [" static" , "/" ]
48
49
routes = app .view_functions
49
50
for route in routes :
50
51
if route not in ignored_routes :
51
52
full_url = url_for (route , _external = True )
52
53
page .goto (full_url )
53
54
check_accessibility (page )
54
55
56
+
55
57
def test_accessibility_folder ():
56
- path = ' tests/functional_tests/accessibility_output'
58
+ path = " tests/functional_tests/accessibility_output"
57
59
if not any (os .scandir (path )):
58
60
assert True
59
61
else :
60
- assert not ' WCAG accessibility issues found'
62
+ assert not " WCAG accessibility issues found"
0 commit comments