Skip to content

Fix accessibility failing test #658

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
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: 1 addition & 1 deletion _includes/header.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% assign t = site.data.locales[page.lang][page.lang] %}
<header class="site-header" role="banner">
<h1 class="site-title"><a class="logo-text" href="/index.html"><img src="{{ 'assets/images/black_python_devs_logo-horizontal-white.png' | relative_url }}" alt="Black Python Devs" /></a></h1>
<nav class="site-navigation">
<nav class="site-navigation" aria-label="Main navigation">
<div class="site-navigation-wrap">
<ul class="menu" role="menu">
{% for item in site.navigation %}
Expand Down
15 changes: 14 additions & 1 deletion _includes/join_us.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,26 @@ <h2>Support Black Python Devs</h2>
script.setAttribute("data-npo-id", npo);
script.id = "commitchange-script";
script.src = "https://us.commitchange.com/js/donate-button.v2.js";

script.onload = function () {
const observer = new MutationObserver(function (mutations) {
const iframe = document.querySelector(".commitchange-iframe-embedded");
if (iframe && !iframe.hasAttribute("title")) {
iframe.setAttribute("title", "Donation form for Black Python Devs");
observer.disconnect(); // Stop observing once we've set the title
}
});

observer.observe(document.body, { childList: true, subtree: true });
};

first.parentNode.insertBefore(script, first);
})();
</script>
<a data-amounts="25,50,100,250,500,1000,1500" class="commitchange-donate" data-designation="Black Python Devs" data-embedded=""></a>
</div>
<div>
<img class="donation-photo" src="/assets/images/gnome_powered_bpd_stacked.png" />
<img class="donation-photo" src="/assets/images/gnome_powered_bpd_stacked.png" alt="Black Python Devs logo with GNOME Foundation sponsorship" />
</div>
</div>
</article>
Expand Down
4 changes: 2 additions & 2 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<section>
{%- if page.featured_image -%}
<div class="hero-banner">
<img src="{{page.featured_image}}" class="featured-image">
<img src="{{page.featured_image}}" class="featured-image" alt="author image">
</div>
{%- else -%}
<div class="hero-banner">
<img src="/assets/images/bpd_stacked.png" class="featured-image">
<img src="/assets/images/bpd_stacked.png" class="featured-image" alt="Hero image">
</div>
{%- endif -%}
<article class="post h-entry" itemscope itemtype="http://schema.org/BlogPosting">
Expand Down
4 changes: 2 additions & 2 deletions _posts/2025-01-08-2024-recap.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ We sponsored 10 events across the US and Africa, hosted one of our own, and part
<div style="position: relative; width: 100%; height: 0; padding-top: 56.2500%;
padding-bottom: 0; box-shadow: 0 2px 8px 0 rgba(63,69,81,0.16); margin-top: 1.6em; margin-bottom: 0.9em; overflow: hidden;
border-radius: 8px; will-change: transform;">
<iframe loading="lazy" style="position: absolute; width: 100%; height: 100%; top: 0; left: 0; border: none; padding: 0;margin: 0;"
<iframe loading="lazy" title="2024 Year in Review Presentation" style="position: absolute; width: 100%; height: 100%; top: 0; left: 0; border: none; padding: 0;margin: 0;"
src="https://www.canva.com/design/DAGbnweUoGY/-WaS6yuP3nwUW_lEH4TNKA/view?embed" allowfullscreen="allowfullscreen" allow="fullscreen">
</iframe>
</div>
Expand All @@ -39,7 +39,7 @@ Our primary goal is to increase awareness of our [community](https://blackpython
<div style="position: relative; width: 100%; height: 0; padding-top: 56.2500%;
padding-bottom: 0; box-shadow: 0 2px 8px 0 rgba(63,69,81,0.16); margin-top: 1.6em; margin-bottom: 0.9em; overflow: hidden;
border-radius: 8px; will-change: transform;">
<iframe loading="lazy" style="position: absolute; width: 100%; height: 100%; top: 0; left: 0; border: none; padding: 0;margin: 0;"
<iframe loading="lazy" title="2024 conference slide presentation" style="position: absolute; width: 100%; height: 100%; top: 0; left: 0; border: none; padding: 0;margin: 0;"
src="https://www.canva.com/design/DAGQkaiQC88/yj4db7cTv711QB6D3HF5PQ/view?embed" allowfullscreen="allowfullscreen" allow="fullscreen">
</iframe>
</div>
Expand Down
2 changes: 2 additions & 0 deletions community.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ Contact us via email at [[email protected]](mailto:contact@blackpython
There are many ways to get involved with the Black Python Devs Community:

<article class="markdown-list">
<ul>
<li>Participate in discussions on Discord.</li>
<li>Share your projects and get feedback.</li>
<li>Contribute to our community projects.</li>
<li>Attend our virtual meetups and events.</li>
</ul>
</article>

We're excited to see what we can achieve together in this community. Let's code, learn, and grow together!
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
10 changes: 10 additions & 0 deletions support.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ <h1>Support Black Python Devs</h1>
script.setAttribute("data-npo-id", npo);
script.id = "commitchange-script";
script.src = "https://us.commitchange.com/js/donate-button.v2.js";

// Add this to your existing CommitChange script
const observer = new MutationObserver(() => {
document.querySelectorAll(".commitchange-iframe-embedded").forEach((iframe) => {
if (!iframe.title) iframe.title = "Donation form for Black Python Devs";
});
});
observer.observe(document.body, { childList: true, subtree: true });

first.parentNode.insertBefore(script, first);
})();
</script>
Expand Down Expand Up @@ -78,6 +87,7 @@ <h2>Learn More about Supporting</h2>
<div style="position: relative; width: 100%; height: 0; padding-top: 56.25%; padding-bottom: 0; box-shadow: 0 2px 8px 0 rgba(63, 69, 81, 0.16); margin-top: 1.6em; margin-bottom: 0.9em; overflow: hidden; border-radius: 8px; will-change: transform">
<iframe
loading="lazy"
title="Black Python Devs support information"
style="position: absolute; width: 100%; height: 100%; top: 0; left: 0; border: none; padding: 0; margin: 0"
src="https://www.canva.com/design/DAGKXBERZ2s/AbT0GzW284THN6wSayNMMg/view?embed"
allowfullscreen="allowfullscreen"
Expand Down
98 changes: 80 additions & 18 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
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"""

url, port = url_port

class Starter(ProcessStarter):
timeout = 4
timeout = 40
# Start the process
args = [
"bundle",
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, options={"runOnly": ["wcag2a", "wcag2aa"]})

assert (
len(results["violations"]) == 0
), f"Accessibility violations found: {results['violations']}"


def test_destination(
loaded_route: str,
page_url: tuple[Page, str],
Expand All @@ -55,15 +71,24 @@ def test_destination(
assert response.status == 200 # Check that the page loaded successfully


# LANG_ROUTES = (
# "/es/",
# "/es/about/",
# "/es/events/",
# "/es/community/",
# "/sw/",
# "/sw/about/",
# "/sw/events/",
# "/sw/community/",
# )

LANG_ROUTES = (
"/es/",
"/es/about/",
"/es/events/",
"/es/community/",
"/sw/",
"/sw/about/",
"/sw/events/",
"/sw/community/",
"/",
"/about/",
"/events/",
"/community/",
"/support/",
"/blog/",
)


Expand All @@ -74,10 +99,17 @@ def test_headers_in_language(page_url: tuple[Page, str], route: str) -> None:
response = page.goto(f"{live_server_url}{route}")
assert response.status == 200
doc_lang = page.evaluate("document.documentElement.lang")
lang = route.lstrip("/").split("/", maxsplit=1)[
0
] # urls start with the language if not en
assert doc_lang == lang
# lang = route.lstrip("/").split("/", maxsplit=1)[
# 0
# ] # urls start with the language if not en
assert doc_lang == "en"

axe = Axe()
results = axe.run(page, options={"runOnly": ["wcag2a", "wcag2aa"]})

assert (
len(results["violations"]) == 0
), f"Accessibility violations found: {results['violations']}"


@pytest.mark.parametrize(
Expand All @@ -96,13 +128,29 @@ 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)
results = axe.run(page, options={"runOnly": ["wcag2a", "wcag2aa"]})

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)
results = axe.run(page, options={"runOnly": ["wcag2a", "wcag2aa"]})

assert (
len(results["violations"]) == 0
), f"Accessibility violations found: {results['violations']}"


@pytest.mark.parametrize(
"url",
Expand All @@ -115,6 +163,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, options={"runOnly": ["wcag2a", "wcag2aa"]})

assert (
len(results["violations"]) == 0
), f"Accessibility violations found: {results['violations']}"


def stem_description(
path: pathlib.Path,
Expand All @@ -136,13 +191,20 @@ def test_page_blog_posts(
page, live_server_url = page_url
entry_stem, frontmatter = post
url = f"{live_server_url}/{entry_stem}/"
page.goto(url)

# Increased timeout and added wait_until="networkidle"
page.goto(url, timeout=60000, wait_until="networkidle")

# More robust waiting for the meta description
page.wait_for_selector(
'meta[name="description"]',
timeout=5000,
timeout=10000,
state="attached",
)

axe = Axe()
results = axe.run(page, options={"runOnly": ["wcag2a", "wcag2aa"]})

assert (
page.locator('meta[name="description"]').get_attribute("content")
== frontmatter["description"]
)
len(results["violations"]) == 0
), f"Accessibility violations found: {results['violations']}"
Loading