Skip to content

Commit 9ff69dd

Browse files
committed
simplify axe tests
axe_playwright_python previously had a bug that meant passing in options didn't work. This is now fixed, and the bundled version of axe-copy has been updated, so we don't need to manage our own version anymore.
1 parent b6f5b32 commit 9ff69dd

File tree

3 files changed

+11
-35
lines changed

3 files changed

+11
-35
lines changed
Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,20 @@
1-
import json
2-
31
from axe_playwright_python.base import AxeResults
4-
from django.conf import settings
5-
from playwright.sync_api import Page
2+
from axe_playwright_python.sync_playwright import Axe
63

74
AXE_VIOLATIONS_EXCLUDE_LIST = [
85
"region", # 'Some page content is not contained by landmarks' https://github.com/alphagov/govuk-frontend/issues/1604
96
"aria-allowed-attr", # 'ARIA attribute is not allowed: aria-expanded="false"' https://github.com/alphagov/govuk-frontend/issues/979
107
]
118

129

13-
class AxeAdapter:
14-
def __init__(
15-
self,
16-
page: Page,
17-
script_path=settings.BASE_DIR.parent
18-
/ "node_modules"
19-
/ "axe-core"
20-
/ "axe.min.js",
21-
options=None,
22-
):
23-
self.script_path = script_path
24-
self.options = options or {
10+
class AxeAdapter(Axe):
11+
def __init__(self):
12+
self.default_options = {
2513
"rules": {id: {"enabled": False} for id in AXE_VIOLATIONS_EXCLUDE_LIST}
2614
}
27-
self.page = page
28-
self._install(page)
29-
30-
def _install(self, page: Page):
31-
"""
32-
Add the axe script to a playwright Page.
33-
The script will be re-executed any time the page or it's frames are navigated.
34-
"""
35-
page.add_init_script(path=self.script_path)
15+
super().__init__()
3616

37-
def run(self) -> AxeResults:
38-
"""
39-
Run axe on the whole document
40-
"""
41-
options = json.dumps(self.options)
42-
response = self.page.evaluate(rf"axe.run({options})")
43-
return AxeResults(response)
17+
def run(self, page, context=None, options=None) -> AxeResults:
18+
return super().run(
19+
page=page, context=context, options=options or self.default_options
20+
)

manage_breast_screening/tests/system/system_test_setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def setUp(self):
3535
self.context = self.browser.new_context()
3636
self.page = self.context.new_page()
3737
self.page.set_default_timeout(5000)
38-
self.axe = AxeAdapter(self.page)
38+
self.axe = AxeAdapter()
3939
settings.BASE_URL = self.live_server_url
4040

4141
def tearDown(self):
@@ -138,7 +138,7 @@ def then_the_accessibility_baseline_is_met(self, require_unique_link_text=True):
138138
any interactive elements that appear close together, and avoiding any non-specific
139139
links like "click here".
140140
"""
141-
results = self.axe.run()
141+
results = self.axe.run(page=self.page)
142142
self.assertEqual(results.violations_count, 0, results.generate_report())
143143

144144
if require_unique_link_text:

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"@types/eslint": "^9.6.1",
3939
"@types/jest": "^30.0.0",
4040
"@types/node": "^24.10.1",
41-
"axe-core": "^4.11.0",
4241
"babel-jest": "^30.2.0",
4342
"concurrently": "^9.2.1",
4443
"eslint": "^9.37.0",

0 commit comments

Comments
 (0)