8
8
9
9
import pytest
10
10
11
- from .utils .pretty_axe_results import pretty_axe_results
12
-
13
11
# Using importorskip to ensure these tests are only loaded if Playwright is installed.
14
12
playwright = pytest .importorskip ("playwright" )
15
13
from playwright .sync_api import Page , expect # noqa: E402
@@ -72,34 +70,88 @@ def url_base():
72
70
process .wait ()
73
71
74
72
73
+ def fingerprint_violations (accessibility_page_scan_violations ):
74
+ """Create a fingerprint of the Axe violations array.
75
+
76
+ https://playwright.dev/docs/accessibility-testing#using-snapshots-to-allow-specific-known-issues
77
+ """
78
+ return [
79
+ {
80
+ "id" : violation ["id" ],
81
+ "help" : violation ["help" ],
82
+ "helpUrl" : violation ["helpUrl" ],
83
+ "targets" : [node ["target" ] for node in violation ["nodes" ]],
84
+ }
85
+ for violation in accessibility_page_scan_violations
86
+ ]
87
+
88
+
75
89
@pytest .mark .a11y
76
90
@pytest .mark .parametrize ("theme" , ["light" , "dark" ])
77
91
@pytest .mark .parametrize (
78
92
"url_pathname,selector" ,
79
93
[
80
- ("/examples/kitchen-sink/admonitions.html" , "#admonitions" ),
81
- ("/examples/kitchen-sink/api.html" , "#api-documentation" ),
94
+ (
95
+ "/examples/kitchen-sink/admonitions.html" ,
96
+ "#admonitions" ,
97
+ ),
98
+ (
99
+ "/examples/kitchen-sink/api.html" ,
100
+ "#api-documentation" ,
101
+ ),
82
102
("/examples/kitchen-sink/blocks.html" , "#blocks" ),
83
- ("/examples/kitchen-sink/generic.html" , "#generic-items" ),
84
- ("/examples/kitchen-sink/images.html" , "#images-figures" ),
103
+ (
104
+ "/examples/kitchen-sink/generic.html" ,
105
+ "#generic-items" ,
106
+ ),
107
+ (
108
+ "/examples/kitchen-sink/images.html" ,
109
+ "#images-figures" ,
110
+ ),
85
111
("/examples/kitchen-sink/lists.html" , "#lists" ),
86
- ("/examples/kitchen-sink/structure.html" , "#structural-elements" ),
87
- ("/examples/kitchen-sink/structure.html" , "#structural-elements-2" ),
112
+ (
113
+ "/examples/kitchen-sink/structure.html" ,
114
+ "#structural-elements" ,
115
+ ),
116
+ (
117
+ "/examples/kitchen-sink/structure.html" ,
118
+ "#structural-elements-2" ,
119
+ ),
88
120
("/examples/kitchen-sink/tables.html" , "#tables" ),
89
- ("/examples/kitchen-sink/typography.html" , "#typography" ),
121
+ (
122
+ "/examples/kitchen-sink/typography.html" ,
123
+ "#typography" ,
124
+ ),
90
125
("/examples/pydata.html" , "#pydata-library-styles" ),
91
- ("/user_guide/theme-elements.html" , "#theme-specific-elements" ),
92
- ("/user_guide/web-components.html" , "#sphinx-design-components" ),
93
- ("/user_guide/extending.html" , "#extending-the-theme" ),
94
- ("/user_guide/styling.html" , "#theme-variables-and-css" ),
126
+ (
127
+ "/user_guide/theme-elements.html" ,
128
+ "#theme-specific-elements" ,
129
+ ),
130
+ (
131
+ "/user_guide/web-components.html" ,
132
+ "#sphinx-design-components" ,
133
+ ),
134
+ (
135
+ "/user_guide/extending.html" ,
136
+ "#extending-the-theme" ,
137
+ ),
138
+ (
139
+ "/user_guide/styling.html" ,
140
+ "#theme-variables-and-css" ,
141
+ ),
95
142
# Using one of the simplest pages on the site, select the whole page for
96
143
# testing in order to effectively test repeated website elements like
97
144
# nav, sidebars, breadcrumbs, footer
98
145
("/user_guide/page-toc.html" , "" ),
99
146
],
100
147
)
101
148
def test_axe_core (
102
- theme : str , url_base : str , url_pathname : str , selector : str , page : Page
149
+ data_regression ,
150
+ theme : str ,
151
+ url_base : str ,
152
+ url_pathname : str ,
153
+ selector : str ,
154
+ page : Page ,
103
155
):
104
156
"""Should have no Axe-core violations at the provided theme and page section."""
105
157
# Load the page at the provided path
@@ -118,8 +170,8 @@ def test_axe_core(
118
170
# the PyData Sphinx Theme documentation website.)
119
171
results = page .evaluate ("axe.run()" if selector == "" else f"axe.run('{ selector } ')" )
120
172
121
- # Expect Axe-core to have found 0 accessibility violations
122
- assert len ( results ["violations" ]) == 0 , pretty_axe_results ( results , selector )
173
+ # Check found violations against known violations that we do not plan to fix
174
+ data_regression . check ( fingerprint_violations ( results ["violations" ]))
123
175
124
176
125
177
def test_version_switcher_highlighting (page : Page , url_base : str ) -> None :
0 commit comments