Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e68d620

Browse files
authoredApr 3, 2025··
Merge pull request #651 from TimOsahenru/accessibility_testing
added accessibility testing to GitHub actions
2 parents 1117925 + d9c6766 commit e68d620

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
 
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Accessibility Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- gh-pages
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v3
15+
with:
16+
ref: ${{ github.head_ref }}
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: "3.10"
22+
23+
- name: Install dependencies
24+
run: |
25+
python3 -m pip install --upgrade pip
26+
pip install -r requirements.txt
27+
pip install axe-core-python pytest playwright axe-playwright-python
28+
29+
- name: Install Playwright browsers
30+
run: |
31+
playwright install
32+
33+
- name: Run accessibility tests
34+
run: |
35+
python3 -m pytest tests/

‎requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ python-frontmatter
1313
ephemeral_port_reserve
1414
pytest-playwright
1515
pytest-xprocess
16+
axe-core-python==0.1.0
17+
axe-playwright-python==0.1.4

‎tests/test.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
from playwright.sync_api import Page, expect, sync_playwright
88

99

10+
from axe_core_python.sync_playwright import Axe
11+
12+
1013
@pytest.fixture(scope="module")
1114
def page_url(xprocess, url_port):
1215
"""Returns the url of the live server"""
@@ -43,6 +46,19 @@ class Starter(ProcessStarter):
4346
xprocess.getinfo("page_url").terminate()
4447

4548

49+
def test_accessibility(page_url: tuple[Page, str]):
50+
"""Run accessibility tests on the homepage"""
51+
page, live_server_url = page_url
52+
page.goto(f"{live_server_url}/")
53+
54+
axe = Axe()
55+
results = axe.run(page)
56+
57+
assert (
58+
len(results["violations"]) == 0
59+
), f"Accessibility violations found: {results['violations']}"
60+
61+
4662
def test_destination(
4763
loaded_route: str,
4864
page_url: tuple[Page, str],
@@ -79,6 +95,13 @@ def test_headers_in_language(page_url: tuple[Page, str], route: str) -> None:
7995
] # urls start with the language if not en
8096
assert doc_lang == lang
8197

98+
axe = Axe()
99+
results = axe.run(page)
100+
101+
assert (
102+
len(results["violations"]) == 0
103+
), f"Accessibility violations found: {results['violations']}"
104+
82105

83106
@pytest.mark.parametrize(
84107
"title, url",
@@ -96,13 +119,27 @@ def test_bpdevs_title_en(page_url: tuple[Page, str], title: str, url: str) -> No
96119
page.goto(f"{live_server_url}{url}")
97120
expect(page).to_have_title(f"Black Python Devs | {title}")
98121

122+
axe = Axe()
123+
results = axe.run(page)
124+
125+
assert (
126+
len(results["violations"]) == 0
127+
), f"Accessibility violations found: {results['violations']}"
128+
99129

100130
def test_mailto_bpdevs(page_url: tuple[Page, str]) -> None:
101131
page, live_server_url = page_url
102132
page.goto(live_server_url)
103133
mailto = page.get_by_role("link", name="email")
104134
expect(mailto).to_have_attribute("href", "mailto:contact@blackpythondevs.com")
105135

136+
axe = Axe()
137+
results = axe.run(page)
138+
139+
assert (
140+
len(results["violations"]) == 0
141+
), f"Accessibility violations found: {results['violations']}"
142+
106143

107144
@pytest.mark.parametrize(
108145
"url",
@@ -115,6 +152,13 @@ def test_page_description_in_index_and_blog(page_url: tuple[Page, str], url: str
115152
expect(page.locator("p.post-description").first).to_be_visible()
116153
expect(page.locator("p.post-description").first).not_to_be_empty()
117154

155+
axe = Axe()
156+
results = axe.run(page)
157+
158+
assert (
159+
len(results["violations"]) == 0
160+
), f"Accessibility violations found: {results['violations']}"
161+
118162

119163
def stem_description(
120164
path: pathlib.Path,
@@ -146,3 +190,10 @@ def test_page_blog_posts(
146190
page.locator('meta[name="description"]').get_attribute("content")
147191
== frontmatter["description"]
148192
)
193+
194+
axe = Axe()
195+
results = axe.run(page)
196+
197+
assert (
198+
len(results["violations"]) == 0
199+
), f"Accessibility violations found: {results['violations']}"

0 commit comments

Comments
 (0)
Please sign in to comment.