-
Notifications
You must be signed in to change notification settings - Fork 63
added accessibility testing to GitHub actions #651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TimOsahenru
merged 6 commits into
BlackPythonDevs:gh-pages
from
TimOsahenru:accessibility_testing
Apr 3, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cf9e8a0
axe-playwright installed
TimOsahenru 4f75241
axe-core-python installed
TimOsahenru 0469f1c
feat: add accessibility testing using axe-core-python
TimOsahenru fd96163
feat: github actions workflow to test feature branches ensure accessiβ¦
TimOsahenru 9933195
Linting test
TimOsahenru d9c6766
Removed unwanted dependencies from requirement files
TimOsahenru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Accessibility Tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- gh-pages | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Install dependencies | ||
run: | | ||
python3 -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install axe-core-python pytest playwright axe-playwright-python | ||
|
||
- name: Install Playwright browsers | ||
run: | | ||
playwright install | ||
|
||
- name: Run accessibility tests | ||
run: | | ||
python3 -m pytest tests/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
from playwright.sync_api import Page, expect, sync_playwright | ||
|
||
|
||
from axe_core_python.sync_playwright import Axe | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def page_url(xprocess, url_port): | ||
"""Returns the url of the live server""" | ||
|
@@ -43,6 +46,19 @@ class Starter(ProcessStarter): | |
xprocess.getinfo("page_url").terminate() | ||
|
||
|
||
def test_accessibility(page_url: tuple[Page, str]): | ||
"""Run accessibility tests on the homepage""" | ||
page, live_server_url = page_url | ||
page.goto(f"{live_server_url}/") | ||
|
||
axe = Axe() | ||
results = axe.run(page) | ||
|
||
assert ( | ||
len(results["violations"]) == 0 | ||
), f"Accessibility violations found: {results['violations']}" | ||
|
||
|
||
def test_destination( | ||
loaded_route: str, | ||
page_url: tuple[Page, str], | ||
|
@@ -79,6 +95,13 @@ def test_headers_in_language(page_url: tuple[Page, str], route: str) -> None: | |
] # urls start with the language if not en | ||
assert doc_lang == lang | ||
|
||
axe = Axe() | ||
results = axe.run(page) | ||
|
||
assert ( | ||
len(results["violations"]) == 0 | ||
), f"Accessibility violations found: {results['violations']}" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"title, url", | ||
|
@@ -96,13 +119,27 @@ def test_bpdevs_title_en(page_url: tuple[Page, str], title: str, url: str) -> No | |
page.goto(f"{live_server_url}{url}") | ||
expect(page).to_have_title(f"Black Python Devs | {title}") | ||
|
||
axe = Axe() | ||
results = axe.run(page) | ||
|
||
assert ( | ||
len(results["violations"]) == 0 | ||
), f"Accessibility violations found: {results['violations']}" | ||
|
||
|
||
def test_mailto_bpdevs(page_url: tuple[Page, str]) -> None: | ||
page, live_server_url = page_url | ||
page.goto(live_server_url) | ||
mailto = page.get_by_role("link", name="email") | ||
expect(mailto).to_have_attribute("href", "mailto:[email protected]") | ||
|
||
axe = Axe() | ||
results = axe.run(page) | ||
|
||
assert ( | ||
len(results["violations"]) == 0 | ||
), f"Accessibility violations found: {results['violations']}" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"url", | ||
|
@@ -115,6 +152,13 @@ def test_page_description_in_index_and_blog(page_url: tuple[Page, str], url: str | |
expect(page.locator("p.post-description").first).to_be_visible() | ||
expect(page.locator("p.post-description").first).not_to_be_empty() | ||
|
||
axe = Axe() | ||
results = axe.run(page) | ||
|
||
assert ( | ||
len(results["violations"]) == 0 | ||
), f"Accessibility violations found: {results['violations']}" | ||
|
||
|
||
def stem_description( | ||
path: pathlib.Path, | ||
|
@@ -146,3 +190,10 @@ def test_page_blog_posts( | |
page.locator('meta[name="description"]').get_attribute("content") | ||
== frontmatter["description"] | ||
) | ||
|
||
axe = Axe() | ||
results = axe.run(page) | ||
|
||
assert ( | ||
len(results["violations"]) == 0 | ||
), f"Accessibility violations found: {results['violations']}" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.