Files
notifications-admin/tests/end_to_end/conftest.py

49 lines
1.3 KiB
Python
Raw Normal View History

import os
import pytest
2024-09-11 12:36:58 -07:00
from axe_core_python.sync_playwright import Axe
E2E_TEST_URI = os.getenv("NOTIFY_E2E_TEST_URI")
2024-07-15 08:07:18 -07:00
@pytest.fixture
def end_to_end_context(browser):
context = browser.new_context()
return context
2024-07-15 08:07:18 -07:00
@pytest.fixture
def authenticated_page(end_to_end_context):
# Open a new page and go to the site.
page = end_to_end_context.new_page()
2024-08-28 11:17:52 -07:00
page.goto(f"{E2E_TEST_URI}/sign-in")
# Wait for the next page to fully load.
page.wait_for_load_state("domcontentloaded")
return page
2024-09-11 12:36:58 -07:00
def check_axe_report(page):
axe = Axe()
results = axe.run(page)
2025-05-02 10:43:07 -04:00
filtered_violations = []
2024-09-11 12:57:10 -07:00
for violation in results["violations"]:
2025-05-02 10:43:07 -04:00
keep = True
for node in violation["nodes"]:
for target in node.get("target", []):
# Skip known Flask debug elements like werkzeug or debugger footer
if (
"werkzeug" in target
or ".debugger" in target
or ".footer" in target
or "DON'T PANIC" in node.get("html", "")
):
keep = False
if keep:
filtered_violations.append(violation)
for violation in filtered_violations:
assert violation["impact"] in ["minor", "moderate"], f"Accessibility violation: {violation}"