|
1 | 1 | """Using Axe-core, scan the Kitchen Sink pages for accessibility violations.""" |
2 | 2 |
|
3 | 3 | import time |
| 4 | +from dataclasses import dataclass |
4 | 5 | from http.client import HTTPConnection |
5 | 6 | from pathlib import Path |
6 | 7 | from subprocess import PIPE, Popen |
@@ -70,20 +71,30 @@ def url_base(): |
70 | 71 | process.wait() |
71 | 72 |
|
72 | 73 |
|
73 | | -def fingerprint_violations(accessibility_page_scan_violations): |
| 74 | +@dataclass(frozen=True) |
| 75 | +class AxeViolationFingerprint: |
| 76 | + """Fingerprint for single Axe violation.""" |
| 77 | + |
| 78 | + id: str |
| 79 | + help: str |
| 80 | + helpUrl: str |
| 81 | + targets: tuple |
| 82 | + |
| 83 | + |
| 84 | +def fingerprint(accessibility_page_scan_violations): |
74 | 85 | """Create a fingerprint of the Axe violations array. |
75 | 86 |
|
76 | 87 | https://playwright.dev/docs/accessibility-testing#using-snapshots-to-allow-specific-known-issues |
77 | 88 | """ |
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 | | - } |
| 89 | + return tuple( |
| 90 | + AxeViolationFingerprint( |
| 91 | + violation["id"], |
| 92 | + violation["help"], |
| 93 | + violation["helpUrl"], |
| 94 | + tuple(node["target"] for node in violation["nodes"]), |
| 95 | + ) |
85 | 96 | for violation in accessibility_page_scan_violations |
86 | | - ] |
| 97 | + ) |
87 | 98 |
|
88 | 99 |
|
89 | 100 | @pytest.mark.a11y |
@@ -171,7 +182,7 @@ def test_axe_core( |
171 | 182 | results = page.evaluate("axe.run()" if selector == "" else f"axe.run('{selector}')") |
172 | 183 |
|
173 | 184 | # Check found violations against known violations that we do not plan to fix |
174 | | - data_regression.check(fingerprint_violations(results["violations"])) |
| 185 | + data_regression.check(fingerprint(results["violations"])) |
175 | 186 |
|
176 | 187 |
|
177 | 188 | def test_version_switcher_highlighting(page: Page, url_base: str) -> None: |
|
0 commit comments