From bb7da0de269ff8ab81df0abb3223877c57c66443 Mon Sep 17 00:00:00 2001 From: Dave Harding <35965578+davethepunkyone@users.noreply.github.com> Date: Sun, 10 Nov 2024 16:52:49 +0000 Subject: [PATCH] WCAG 2.2 Implementation in Axe Util (#31) ## Description WCAG 2.2 AA Implementation in Axe Utility - was previously only scanning up to 2.1 AA. ## Context Matches the correct standard. ## Type of changes - [ ] Refactoring (non-breaking change) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would change existing functionality) - [x] Bug fix (non-breaking change which fixes an issue) ## Checklist - [ ] I am familiar with the [contributing guidelines](../docs/CONTRIBUTING.md) - [x] I have followed the code style of the project - [ ] I have added tests to cover my changes - [x] I have updated the documentation accordingly - [ ] This PR is a result of pair or mob programming --- ## Sensitive Information Declaration To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including [PII (Personal Identifiable Information) / PID (Personal Identifiable Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter. - [x] I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes. --- docs/utility-guides/Axe.md | 2 +- tests/test_example.py | 2 +- utils/axe.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/utility-guides/Axe.md b/docs/utility-guides/Axe.md index 1417307..0c46a54 100644 --- a/docs/utility-guides/Axe.md +++ b/docs/utility-guides/Axe.md @@ -39,7 +39,7 @@ The `Axe.run(page)` has the following optional arguments that can be passed in: |Argument|Format|Supported Values|Default Value|Description| |--------|------|----------------|-------------|-----------| -|`ruleset` |`list[str]`|Any provided by [axe-core](https://www.deque.com/axe/core-documentation/api-documentation/)|`['wcag2a', 'wcag21a', 'wcag2aa', 'wcag21aa', 'best-practice']`|The tags that axe-core uses to filter specific checks. Defaulted to rules used for the WCAG 2.2 AA standard.| +|`ruleset` |`list[str]`|Any provided by [axe-core](https://www.deque.com/axe/core-documentation/api-documentation/)|`['wcag2a', 'wcag21a', 'wcag2aa', 'wcag21aa', 'wcag22a', 'wcag22aa', 'best-practice']`|The tags that axe-core uses to filter specific checks. Defaulted to rules used for the WCAG 2.2 AA standard.| |`filename`|`str`|A string valid for a filename (e.g. `test_report`)||If provided, HTML and JSON reports will save with the filename provided. If not provided (default), the URL of the page under test will be used as the filename.| |`report_on_violation_only`|`bool`|`True`, `False`|`False`|If True, HTML and JSON reports will only be generated if at least one violation is found.| |`strict_mode`|`bool`|`True`, `False`|`False`|If True, when a violation is found an AxeAccessibilityException is raised, causing a test failure.| diff --git a/tests/test_example.py b/tests/test_example.py index f4e1a79..faa5167 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -35,7 +35,7 @@ def test_basic_example(page: Page) -> None: # Assert repo text is present expect(page.get_by_role("article")).to_contain_text("Playwright Python Blueprint") - # Assert the page loaded is the playwright-python topic page + # Assert the page loaded contains a reference to the playwright-python topic page expect(page.get_by_role("main")).to_contain_text("playwright-python") diff --git a/utils/axe.py b/utils/axe.py index 4489ed1..e3c9de4 100644 --- a/utils/axe.py +++ b/utils/axe.py @@ -19,7 +19,7 @@ class Axe: @staticmethod def run(page: Page, filename: str = "", - ruleset: list = ['wcag2a', 'wcag21a', 'wcag2aa', 'wcag21aa', 'best-practice'], + ruleset: list = ['wcag2a', 'wcag21a', 'wcag2aa', 'wcag21aa', 'wcag22a', 'wcag22aa', 'best-practice'], report_on_violation_only: bool = False, strict_mode: bool = False, html_report_generated: bool = True, @@ -30,7 +30,7 @@ def run(page: Page, Args: page (playwright.sync_api.Page): The page object to execute axe-core against. filename (str): The filename to use for the outputted reports. If not provided, defaults to the URL under test. - ruleset (list[str]): [Optional] If provided, a list of strings to denote the ruleset tags axe-core should use. If not provided, defaults to the WCAG 2.2 AA standard (uses tags: 'wcag2a', 'wcag21a', 'wcag2aa', 'wcag21aa', 'best-practice'). + ruleset (list[str]): [Optional] If provided, a list of strings to denote the ruleset tags axe-core should use. If not provided, defaults to the WCAG 2.2 AA standard (uses tags: 'wcag2a', 'wcag21a', 'wcag2aa', 'wcag21aa', 'wcag22a', 'wcag22aa', 'best-practice'). report_on_violation_only (bool): [Optional] If true, only generates an Axe report if a violation is detected. If false (default), always generate a report. strict_mode (bool): [Optional] If true, raise an exception if a violation is detected. If false (default), proceed with test execution. html_report_generated (bool): [Optional] If true (default), generates a html report for the page scanned. If false, no html report is generated.