Skip to content

Commit 5cdcd6c

Browse files
Change to Axe class to use pytest-playwright-axe instead (#45)
<!-- markdownlint-disable-next-line first-line-heading --> ## Description <!-- Describe your changes in detail. --> This changes the logic of the Axe utility to use the dedicated pytest-playwright-axe package instead. ## Context <!-- Why is this change required? What problem does it solve? --> This removes the project dependency on Axe to a more appropriate location, and brings in enhanced HTML reporting and functionality. ## Type of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. --> - [x] Refactoring (non-breaking change) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would change existing functionality) - [ ] Bug fix (non-breaking change which fixes an issue) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I am familiar with the [contributing guidelines](https://github.com/nhs-england-tools/playwright-python-blueprint/blob/main/CONTRIBUTING.md) - [x] I have followed the code style of the project - [x] I have added tests to cover my changes (where appropriate) - [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.
1 parent b799de8 commit 5cdcd6c

File tree

8 files changed

+70
-33096
lines changed

8 files changed

+70
-33096
lines changed

.github/actions/check-axe-version/action.yaml

Lines changed: 0 additions & 42 deletions
This file was deleted.

.github/workflows/axe-dependency-check.yaml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
},
77
"cSpell.words": [
88
"addopts",
9+
"autouse",
910
"codegen",
1011
"customisable",
1112
"customised",
@@ -20,7 +21,8 @@
2021
"ruleset",
2122
"utilise",
2223
"utilised",
23-
"Utilising"
24+
"Utilising",
25+
"WCAG"
2426
],
2527
"python.testing.pytestArgs": [
2628
"."

docs/utility-guides/Axe.md

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
The Axe utility provided by this blueprint allows for the scanning of pages by using [axe-core](https://github.com/dequelabs/axe-core), a JavaScript
44
library used for scanning for accessibility issues and providing guidance on how to resolve these issues.
55

6+
> NOTE: This is now a direct extension of the [pytest-playwright-axe](https://github.com/davethepunkyone/pytest-playwright-axe) plugin with logic to apply WCAG 2.2 AA rules by default.
7+
68
## Table of Contents
79

810
- [Utility Guide: Axe](#utility-guide-axe)
911
- [Table of Contents](#table-of-contents)
1012
- [Using the Axe class](#using-the-axe-class)
1113
- [.run(): Single page scan](#run-single-page-scan)
12-
- [Required arguments](#required-arguments)
13-
- [Optional arguments](#optional-arguments)
14-
- [Returns](#returns)
14+
- [Further reading](#further-reading)
1515
- [Example usage](#example-usage)
1616
- [.run\_list(): Multiple page scan](#run_list-multiple-page-scan)
17-
- [Required arguments](#required-arguments-1)
18-
- [Optional arguments](#optional-arguments-1)
19-
- [Returns](#returns-1)
17+
- [Further reading](#further-reading-1)
2018
- [Example usage](#example-usage-1)
2119

2220
## Using the Axe class
@@ -43,30 +41,9 @@ By default, the `Axe.run(page)` command will do the following:
4341
- Any steps after the `Axe.run()` command will continue to execute, and it will not cause the test in progress to fail (it runs a passive scan of the page)
4442
- Will return the full response from axe-core as a dict object if the call is set to a variable, e.g. `axe_results = Axe.run(page)` will populate `axe_results` to interact with as required
4543

46-
### Required arguments
47-
48-
The following are required for `Axe.run()`:
49-
50-
| Argument | Format | Description |
51-
| -------- | ------------------------ | -------------------------------------------- |
52-
| page | playwright.sync_api.Page | A Playwright Page on the page to be checked. |
53-
54-
### Optional arguments
55-
56-
The `Axe.run(page)` has the following optional arguments that can be passed in:
57-
58-
| Argument | Format | Supported Values | Default Value | Description |
59-
| -------------------------- | ----------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
60-
| `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. |
61-
| `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. |
62-
| `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. |
63-
| `strict_mode` | `bool` | `True`, `False` | `False` | If True, when a violation is found an AxeAccessibilityException is raised, causing a test failure. |
64-
| `html_report_generated` | `bool` | `True`, `False` | `True` | If True, a HTML report will be generated summarising the axe-core findings. |
65-
| `json_report_generated` | `bool` | `True`, `False` | `True` | If True, a JSON report will be generated with the full axe-core findings. |
66-
67-
### Returns
44+
### Further reading
6845

69-
This function can be used independently, but when set to a variable returns a `dict` with the axe-core results.
46+
This class directly extends the pytest-playwright-axe plugin version of this function, so please see the [single page scan documentation](https://github.com/davethepunkyone/pytest-playwright-axe?tab=readme-ov-file#run-single-page-scan) for additional arguments that can be used.
7047

7148
### Example usage
7249

@@ -85,33 +62,9 @@ To scan multiple URLs within your application, you can use the following method:
8562

8663
This runs the `Axe.run()` function noted above against each URL provided in the `page_list` argument, and will generate reports as required.
8764

88-
### Required arguments
89-
90-
The following are required for `Axe.run_list()`:
91-
92-
| Argument | Format | Description |
93-
| --------- | ------------------------ | ------------------------------------------------------------------ |
94-
| page | playwright.sync_api.Page | A Playwright Page object to drive navigation to each page to test. |
95-
| page_list | list[str] | A list of URLs to execute against |
96-
97-
> NOTE: It is heavily recommended that when using the `run_list` command, that you set a `--base-url` either via the pytest.ini file or by passing in the value when using the `pytest` command in the command line. By doing this, the list you pass in will not need to contain the base URL value and therefore make any scanning transferrable between environments.
98-
99-
### Optional arguments
100-
101-
The `Axe.run_list(page, page_list)` function has the following optional arguments that can be passed in:
102-
103-
| Argument | Format | Supported Values | Default Value | Description |
104-
| -------------------------- | ----------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
105-
| `use_list_for_filename` | `bool` | `True`, `False` | `True` | If True, the filename will be derived from the value provided in the list. If False, the full URL will be used. |
106-
| `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. |
107-
| `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. |
108-
| `strict_mode` | `bool` | `True`, `False` | `False` | If True, when a violation is found an AxeAccessibilityException is raised, causing a test failure. |
109-
| `html_report_generated` | `bool` | `True`, `False` | `True` | If True, a HTML report will be generated summarising the axe-core findings. |
110-
| `json_report_generated` | `bool` | `True`, `False` | `True` | If True, a JSON report will be generated with the full axe-core findings. |
111-
112-
### Returns
65+
### Further reading
11366

114-
This function can be used independently, but when set to a variable returns a `dict` with the axe-core results for all pages scanned (using the URL value in the list provided as the key).
67+
This class directly extends the pytest-playwright-axe plugin version of this function, so please see the [multiple page scan documentation](https://github.com/davethepunkyone/pytest-playwright-axe?tab=readme-ov-file#run_list-multiple-page-scan) for additional arguments that can be used.
11568

11669
### Example usage
11770

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pytest-playwright>=0.5.1
22
pytest-html>=4.1.1
33
pytest-json-report>=1.5.0
4+
pytest-playwright-axe>=4.10.3

tests_utils/test_axe.py

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)