@@ -38,8 +38,9 @@ def filter_ignored_violations(violations, url_pathname):
38
38
]:
39
39
filtered = []
40
40
for violation in violations :
41
- # TODO: eventually fix this rule violation. See
42
- # https://github.com/pydata/pydata-sphinx-theme/issues/1479.
41
+ # TODO: remove this exclusion once the following update to Axe is
42
+ # released and we upgrade:
43
+ # https://github.com/dequelabs/axe-core/pull/4469
43
44
if violation ["id" ] == "landmark-unique" :
44
45
# Ignore landmark-unique only for .sidebar targets. Don't ignore
45
46
# it for other targets because then the test might fail to catch
@@ -167,6 +168,11 @@ def test_axe_core(
167
168
# Wait for CSS transitions (Bootstrap's transitions are 300 ms)
168
169
page .wait_for_timeout (301 )
169
170
171
+ # Wait for JavaScript to add tabindex=0 to scrollable regions (code blocks,
172
+ # tables, etc.), otherwise the page will fail
173
+ # [scrollable-region-focusable](https://dequeuniversity.com/rules/axe/4.9/scrollable-region-focusable)
174
+ page .wait_for_function ("() => document.body.dataset.pstTestTabStops === 'added'" )
175
+
170
176
# Inject the Axe-core JavaScript library into the page
171
177
page .add_script_tag (path = "node_modules/axe-core/axe.min.js" )
172
178
@@ -176,6 +182,35 @@ def test_axe_core(
176
182
177
183
# Check found violations against known violations that we do not plan to fix
178
184
filtered_violations = filter_ignored_violations (results ["violations" ], url_pathname )
185
+
186
+ # We expect notebook outputs on the PyData Library Styles page to have color
187
+ # contrast failures.
188
+ if url_pathname == "/examples/pydata.html" :
189
+ # All violations should be color contrast violations
190
+ for violation in filtered_violations :
191
+ assert (
192
+ violation ["id" ] == "color-contrast"
193
+ ), f"Found { violation ['id' ]} violation (expected color-contrast): { format_violations ([violation ])} "
194
+
195
+ # Now check that when we exclude notebook outputs, the page has no violations
196
+
197
+ results_sans_nbout = page .evaluate (
198
+ f"axe.run({{ include: '{ selector } ', exclude: '.nboutput > .output_area' }})"
199
+ )
200
+ violations_sans_nbout = filter_ignored_violations (
201
+ results_sans_nbout ["violations" ], url_pathname
202
+ )
203
+
204
+ # No violations on page when excluding notebook outputs
205
+ assert len (violations_sans_nbout ) == 0 , format_violations (violations_sans_nbout )
206
+
207
+ # TODO: for color contrast issues with common notebook outputs
208
+ # (ipywidget tabbed panels, Xarray, etc.), should we override
209
+ # third-party CSS with our own CSS or/and work with NbSphinx, MyST-NB,
210
+ # ipywidgets, and other third parties to use higher contrast colors in
211
+ # their CSS?
212
+ pytest .xfail ("notebook outputs have color contrast violations" )
213
+
179
214
assert len (filtered_violations ) == 0 , format_violations (filtered_violations )
180
215
181
216
0 commit comments