You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add functionality to execute Axe against multiple URLs (#32)
<!-- markdownlint-disable-next-line first-line-heading -->
## Description
<!-- Describe your changes in detail. -->
This functionality adds the ability to execute Axe against multiple URLs
using a list, rather than just one URL at a time.
## Context
<!-- Why is this change required? What problem does it solve? -->
Allows for easier, generalised accessibility testing.
## Type of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply. -->
- [ ] 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. -->
- [ ] 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.
Copy file name to clipboardExpand all lines: README.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,8 @@ To utilise the blueprint code, you will need to have the following installed:
34
34
35
35
-[Python](https://www.python.org/downloads/) 3.12 or greater
36
36
37
+
> NOTE: There are currently known issues with Python 3.13 and Playwright, so if you encounter issues running this project whilst using Python 3.13 it is recommended to downgrade to Python 3.12 in the interim.
38
+
37
39
Whilst not required to get started, you may also want to [configure a Python virtual environment for your project](https://docs.python.org/3/library/venv.html) before proceeding with
38
40
the configuration. If you are using an IDE such as Visual Studio Code or PyCharm, you will normally be prompted to do this automatically.
You can initialise the Axe class by using the following code in your test file:
@@ -12,6 +28,8 @@ You can initialise the Axe class by using the following code in your test file:
12
28
This Axe module has been designed as a static class, so you do not need to instantiate it when you want to run a scan on a page you have navigated to
13
29
using Playwright.
14
30
31
+
## .run(): Single page scan
32
+
15
33
To conduct a scan, you can just use the following once the page you want to check is at the right location:
16
34
17
35
Axe.run(page)
@@ -20,37 +38,93 @@ This will inject the axe-core code into the page and then execute the axe.run()
20
38
21
39
By default, the `Axe.run(page)` command will do the following:
22
40
23
-
* Scan the page passed in to the WCAG 2.2 AA standard (which is the current expectation for NHS services outlined in the [NHS Service Manual](https://service-manual.nhs.uk/accessibility/what-all-NHS-services-need-to-do))
24
-
* Generate a HTML and JSON report with the findings in the `axe-reports` directory, regardless of if any violations are found
25
-
* 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)
26
-
* 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
41
+
- Scan the page passed in to the WCAG 2.2 AA standard (which is the current expectation for NHS services outlined in the [NHS Service Manual](https://service-manual.nhs.uk/accessibility/what-all-NHS-services-need-to-do))
42
+
- Generate a HTML and JSON report with the findings in the `axe-reports` directory, regardless of if any violations are found
43
+
- 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)
44
+
- 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
27
45
28
-
## Required arguments
46
+
###Required arguments
29
47
30
48
The following are required for `Axe.run()`:
31
49
32
-
|Argument|Format|Description|
33
-
|--------|------|-----------|
34
-
|page|playwright.sync_api.Page|A Playwright Page on the page to be checked.|
|`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.|
43
-
|`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.|
44
-
|`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.|
45
-
|`strict_mode`|`bool`|`True`, `False`|`False`|If True, when a violation is found an AxeAccessibilityException is raised, causing a test failure.|
46
-
|`html_report_generated`|`bool`|`True`, `False`|`True`|If True, a HTML report will be generated summarising the axe-core findings.|
47
-
|`json_report_generated`|`bool`|`True`, `False`|`True`|If True, a JSON report will be generated with the full axe-core findings.|
58
+
| 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', '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
48
68
49
-
## Example usage
69
+
This function can be used independently, but when set to a variable returns a `dict` with the axe-core results.
| 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 |
|`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
113
+
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).
115
+
116
+
### Example usage
117
+
118
+
When using the following command: `pytest --base-url https://www.github.com`:
This runs axe-core against a list of pages provided.
72
+
73
+
NOTE: It is recommended to set a --base-url value when running Playwright using this functionality, so you only need to pass in a partial URL within the page_list.
74
+
75
+
Args:
76
+
page (playwright.sync_api.Page): The page object to execute axe-core against.
77
+
page_list (list[playwright.sync_api.Page): A list of URLs to execute against.
78
+
use_list_for_filename (bool): If true, based filenames off the list provided. If false, use the full URL under test for the filename.
79
+
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').
80
+
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.
81
+
strict_mode (bool): [Optional] If true, raise an exception if a violation is detected. If false (default), proceed with test execution.
82
+
html_report_generated (bool): [Optional] If true (default), generates a html report for the page scanned. If false, no html report is generated.
83
+
json_report_generated (bool): [Optional] If true (default), generates a json report for the page scanned. If false, no json report is generated.
0 commit comments