Skip to content

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/accessibility-tests.yml
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/
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ python-frontmatter
ephemeral_port_reserve
pytest-playwright
pytest-xprocess
axe-core-python==0.1.0
axe-playwright-python==0.1.4
51 changes: 51 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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']}"
Loading