pytest-playwright-axe 0.0.1b0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. pytest_playwright_axe-0.0.1b0/.editorconfig +23 -0
  2. pytest_playwright_axe-0.0.1b0/.github/PULL_REQUEST_TEMPLATE.md +18 -0
  3. pytest_playwright_axe-0.0.1b0/.github/actions/check-axe-version/action.yaml +42 -0
  4. pytest_playwright_axe-0.0.1b0/.github/dependabot.yaml +18 -0
  5. pytest_playwright_axe-0.0.1b0/.github/workflows/axe-dependency-check.yaml +41 -0
  6. pytest_playwright_axe-0.0.1b0/.github/workflows/build.yaml +29 -0
  7. pytest_playwright_axe-0.0.1b0/.github/workflows/python-package.yml +40 -0
  8. pytest_playwright_axe-0.0.1b0/.github/workflows/python-publish.yml +39 -0
  9. pytest_playwright_axe-0.0.1b0/.gitignore +5 -0
  10. pytest_playwright_axe-0.0.1b0/.vscode/extensions.json +13 -0
  11. pytest_playwright_axe-0.0.1b0/.vscode/settings.json +30 -0
  12. pytest_playwright_axe-0.0.1b0/LICENCE.md +21 -0
  13. pytest_playwright_axe-0.0.1b0/PKG-INFO +173 -0
  14. pytest_playwright_axe-0.0.1b0/README.md +150 -0
  15. pytest_playwright_axe-0.0.1b0/pyproject.toml +42 -0
  16. pytest_playwright_axe-0.0.1b0/pytest.ini +11 -0
  17. pytest_playwright_axe-0.0.1b0/requirements.txt +1 -0
  18. pytest_playwright_axe-0.0.1b0/setup.cfg +4 -0
  19. pytest_playwright_axe-0.0.1b0/src/pytest_playwright_axe/__init__.py +3 -0
  20. pytest_playwright_axe-0.0.1b0/src/pytest_playwright_axe/axe.py +376 -0
  21. pytest_playwright_axe-0.0.1b0/src/pytest_playwright_axe.egg-info/PKG-INFO +173 -0
  22. pytest_playwright_axe-0.0.1b0/src/pytest_playwright_axe.egg-info/SOURCES.txt +25 -0
  23. pytest_playwright_axe-0.0.1b0/src/pytest_playwright_axe.egg-info/dependency_links.txt +1 -0
  24. pytest_playwright_axe-0.0.1b0/src/pytest_playwright_axe.egg-info/requires.txt +1 -0
  25. pytest_playwright_axe-0.0.1b0/src/pytest_playwright_axe.egg-info/top_level.txt +1 -0
  26. pytest_playwright_axe-0.0.1b0/tests/test_axe.py +95 -0
  27. pytest_playwright_axe-0.0.1b0/tests/test_example.py +9 -0
@@ -0,0 +1,23 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ indent_size = 2
7
+ indent_style = space
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.md]
12
+ indent_size = unset
13
+
14
+ [*.py]
15
+ indent_size = 4
16
+
17
+ [{axe.js,axe.min.js}]
18
+ charset = unset
19
+ end_of_line = unset
20
+ insert_final_newline = unset
21
+ trim_trailing_whitespace = unset
22
+ indent_style = unset
23
+ indent_size = unset
@@ -0,0 +1,18 @@
1
+ <!-- markdownlint-disable-next-line first-line-heading -->
2
+ ## Description
3
+
4
+ <!-- Describe your changes in detail. -->
5
+
6
+ ## Context
7
+
8
+ <!-- Why is this change required? What problem does it solve? -->
9
+
10
+ ## Checklist
11
+
12
+ <!-- Go over all the following points, and put an `x` in all the boxes that apply. -->
13
+
14
+ - [ ] I am familiar with the [contributing guidelines](https://github.com/nhs-england-tools/playwright-python-blueprint/blob/main/CONTRIBUTING.md)
15
+ - [ ] I have followed the code style of the project
16
+ - [ ] I have added tests to cover my changes (where appropriate)
17
+ - [ ] I have updated the documentation accordingly
18
+
@@ -0,0 +1,42 @@
1
+ name: "Check axe-core version"
2
+ description: "Checks if our copy of axe-core is up to date"
3
+
4
+ jobs:
5
+ build:
6
+
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - uses: actions/checkout@v4
11
+ - name: Create dependency update branch
12
+ run: |
13
+ git checkout -b axe-dependency-check
14
+ git config --local user.email "action@github.com"
15
+ git config --local user.name "GitHub Action"
16
+ - name: Install Node.js
17
+ uses: actions/setup-node@v4
18
+ with:
19
+ node-version: 'latest'
20
+ - name: Install axe-core in temp dir
21
+ run: |
22
+ cd src/resouces
23
+ mkdir temp
24
+ cd temp
25
+ npm install axe-core
26
+ - name: Retrieve axe.js file
27
+ run: |
28
+ cd node_modules/axe-core
29
+ mv axe.js ../../../
30
+ - name: Remove temp directory
31
+ run: |
32
+ cd ../../../
33
+ rm -rf temp
34
+ - name: Stage & commit file
35
+ run: |
36
+ git stage axe.js
37
+ git diff-index --quiet HEAD || (git commit -a -m "axe.js scheduled update" --allow-empty)
38
+ - name: Push changes to branch
39
+ uses: ad-m/github-push-action@v0.6.0
40
+ with:
41
+ github_token: ${{ secrets.PUSH_TOKEN }}
42
+ branch: axe-dependency-check
@@ -0,0 +1,18 @@
1
+ version: 2
2
+
3
+ updates:
4
+
5
+ - package-ecosystem: "github-actions"
6
+ directory: "/"
7
+ schedule:
8
+ interval: "daily"
9
+
10
+ - package-ecosystem: "npm"
11
+ directory: "/"
12
+ schedule:
13
+ interval: "daily"
14
+
15
+ - package-ecosystem: "pip"
16
+ directory: "/"
17
+ schedule:
18
+ interval: "daily"
@@ -0,0 +1,41 @@
1
+ name: Run Axe Dependency Check
2
+
3
+ on:
4
+ workflow_dispatch:
5
+
6
+ jobs:
7
+ axe-dependency-check:
8
+ name: "Axe Version Check"
9
+ runs-on: ubuntu-latest
10
+ timeout-minutes: 10
11
+
12
+ steps:
13
+ - name: Checkout code
14
+ uses: actions/checkout@v4
15
+ - run: |
16
+ git checkout ${{ github.head_ref || github.ref_name }}
17
+ - name: Install Node.js
18
+ uses: actions/setup-node@v4
19
+ with:
20
+ node-version: 'latest'
21
+ - name: Install axe-core in temp dir
22
+ run: |
23
+ cd src/resources
24
+ mkdir temp
25
+ cd temp
26
+ npm install axe-core
27
+ - name: Retrieve axe.js file
28
+ run: |
29
+ cd src/resources/temp/node_modules/axe-core
30
+ mv axe.js ../../../
31
+ - name: Remove temp directory
32
+ run: |
33
+ cd src/resources
34
+ rm -rf temp
35
+ - name: Commit to axe-dependency-check branch
36
+ run: |
37
+ git config user.name "github-actions[bot]"
38
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
39
+ git add src/resources/axe.js
40
+ git commit -m "axe-core automated update"
41
+ git push
@@ -0,0 +1,29 @@
1
+ name: "Build"
2
+
3
+ on: [pull_request]
4
+
5
+ jobs:
6
+ run-tests:
7
+ name: "Run Tests"
8
+ runs-on: ubuntu-latest
9
+ timeout-minutes: 3
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - name: Set up Python
13
+ uses: actions/setup-python@v5
14
+ with:
15
+ python-version: '3.12'
16
+ - name: Install dependencies
17
+ run: |
18
+ python -m pip install --upgrade pip
19
+ pip install -r requirements.txt
20
+ - name: Ensure browsers are installed
21
+ run: python -m playwright install --with-deps
22
+ - name: Run tests
23
+ run: pytest
24
+ - uses: actions/upload-artifact@v4
25
+ if: ${{ !cancelled() }}
26
+ with:
27
+ name: result-output
28
+ path: test-results/
29
+ retention-days: 5
@@ -0,0 +1,40 @@
1
+ # This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3
+
4
+ name: Python package
5
+
6
+ on:
7
+ push:
8
+ branches: [ "main" ]
9
+ pull_request:
10
+ branches: [ "main" ]
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ python-version: ["3.12", "3.13"]
20
+
21
+ steps:
22
+ - uses: actions/checkout@v3
23
+ - name: Set up Python ${{ matrix.python-version }}
24
+ uses: actions/setup-python@v3
25
+ with:
26
+ python-version: ${{ matrix.python-version }}
27
+ - name: Install dependencies
28
+ run: |
29
+ python -m pip install --upgrade pip
30
+ python -m pip install flake8
31
+ if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
32
+ - name: Lint with flake8
33
+ run: |
34
+ # stop the build if there are Python syntax errors or undefined names
35
+ flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
36
+ # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
37
+ flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
38
+ - name: Test with pytest
39
+ run: |
40
+ python -m unittest discover -s ./test
@@ -0,0 +1,39 @@
1
+ # This workflow will upload a Python Package using Twine when a release is created
2
+ # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3
+
4
+ # This workflow uses actions that are not certified by GitHub.
5
+ # They are provided by a third-party and are governed by
6
+ # separate terms of service, privacy policy, and support
7
+ # documentation.
8
+
9
+ name: Upload Python Package
10
+
11
+ on:
12
+ release:
13
+ types: [published]
14
+
15
+ permissions:
16
+ contents: read
17
+
18
+ jobs:
19
+ deploy:
20
+
21
+ runs-on: ubuntu-latest
22
+
23
+ steps:
24
+ - uses: actions/checkout@v3
25
+ - name: Set up Python
26
+ uses: actions/setup-python@v3
27
+ with:
28
+ python-version: '3.12'
29
+ - name: Install dependencies
30
+ run: |
31
+ python -m pip install --upgrade pip
32
+ pip install build
33
+ - name: Build package
34
+ run: python -m build
35
+ - name: Publish package
36
+ uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
37
+ with:
38
+ user: __token__
39
+ password: ${{ secrets.PYPI_API_TOKEN }}
@@ -0,0 +1,5 @@
1
+ __pycache__/
2
+ .pytest_cache/
3
+ .venv/
4
+ test-results/
5
+ axe-reports/
@@ -0,0 +1,13 @@
1
+ {
2
+ "recommendations": [
3
+ "alefragnani.bookmarks",
4
+ "davidanson.vscode-markdownlint",
5
+ "github.codespaces",
6
+ "github.github-vscode-theme",
7
+ "github.remotehub",
8
+ "github.vscode-github-actions",
9
+ "github.vscode-pull-request-github",
10
+ "ms-python.python"
11
+ ],
12
+ "unwantedRecommendations": []
13
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "markdownlint.config": {
3
+ "MD013": false,
4
+ "MD024": { "siblings_only": true },
5
+ "MD033": false
6
+ },
7
+ "cSpell.words": [
8
+ "addopts",
9
+ "codegen",
10
+ "customisable",
11
+ "customised",
12
+ "initialise",
13
+ "Licence",
14
+ "organisation",
15
+ "pytest",
16
+ "pytestmark",
17
+ "pythonpath",
18
+ "recognise",
19
+ "retcode",
20
+ "ruleset",
21
+ "utilise",
22
+ "utilised",
23
+ "Utilising"
24
+ ],
25
+ "python.testing.pytestArgs": [
26
+ "."
27
+ ],
28
+ "python.testing.unittestEnabled": false,
29
+ "python.testing.pytestEnabled": true
30
+ }
@@ -0,0 +1,21 @@
1
+ # MIT Licence
2
+
3
+ Copyright (c) 2025 Dave Harding.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,173 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytest-playwright-axe
3
+ Version: 0.0.1b0
4
+ Summary: An axe-core integration for accessibility testing using Playwright Python.
5
+ Author-email: Dave Harding <dave@punkamania.org>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/davethepunkyone/pytest-playwright-axe
8
+ Project-URL: Repository, https://github.com/davethepunkyone/pytest-playwright-axe
9
+ Project-URL: Issues, https://github.com/davethepunkyone/pytest-playwright-axe/issues
10
+ Keywords: accessibility,playwright,axe,axe-core,pytest,wcag,testing
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Topic :: Software Development :: Testing
13
+ Classifier: Framework :: Pytest
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Requires-Python: >=3.12
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENCE.md
21
+ Requires-Dist: pytest-playwright>=0.5.1
22
+ Dynamic: license-file
23
+
24
+ # Playwright Axe
25
+
26
+ This is a utility for Playwright Python that allows for the execution of [axe-core](https://github.com/dequelabs/axe-core), a JavaScript
27
+ library used for scanning for accessibility issues and providing guidance on how to resolve these issues.
28
+
29
+ ## Table of Contents
30
+
31
+ - [Playwright Axe](#playwright-axe)
32
+ - [Table of Contents](#table-of-contents)
33
+ - [Setup](#setup)
34
+ - [Using the Axe class](#using-the-axe-class)
35
+ - [.run(): Single page scan](#run-single-page-scan)
36
+ - [Required arguments](#required-arguments)
37
+ - [Optional arguments](#optional-arguments)
38
+ - [Returns](#returns)
39
+ - [Example usage](#example-usage)
40
+ - [.run\_list(): Multiple page scan](#run_list-multiple-page-scan)
41
+ - [Required arguments](#required-arguments-1)
42
+ - [Optional arguments](#optional-arguments-1)
43
+ - [Returns](#returns-1)
44
+ - [Example usage](#example-usage-1)
45
+ - [Licence](#licence)
46
+ - [Acknowledgements](#acknowledgements)
47
+
48
+ ## Setup
49
+
50
+ You can clone this whole repository using the code below:
51
+
52
+ ```shell
53
+ git clone https://github.com/davethepunkyone/playwright-axe.git
54
+ ```
55
+
56
+ ## Using the Axe class
57
+
58
+ You can initialise the Axe class by using the following code in your test file:
59
+
60
+ from utils.axe import Axe
61
+
62
+ 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 using Playwright.
63
+
64
+ ## .run(): Single page scan
65
+
66
+ To conduct a scan, you can just use the following once the page you want to check is at the right location:
67
+
68
+ Axe.run(page)
69
+
70
+ This will inject the axe-core code into the page and then execute the axe.run() command, generating an accessibility report for the page being tested.
71
+
72
+ By default, the `Axe.run(page)` command will do the following:
73
+
74
+ - Scan the page passed in to the WCAG 2.2 AA standard
75
+ - Generate a HTML and JSON report with the findings in the `axe-reports` directory, regardless of if any violations are found
76
+ - 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)
77
+ - 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
78
+
79
+ ### Required arguments
80
+
81
+ The following are required for `Axe.run()`:
82
+
83
+ | Argument | Format | Description |
84
+ | -------- | ------------------------ | -------------------------------------------- |
85
+ | page | playwright.sync_api.Page | A Playwright Page on the page to be checked. |
86
+
87
+ ### Optional arguments
88
+
89
+ The `Axe.run(page)` has the following optional arguments that can be passed in:
90
+
91
+ | Argument | Format | Supported Values | Default Value | Description |
92
+ | -------------------------- | ----------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
93
+ | `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. |
94
+ | `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. |
95
+ | `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. |
96
+ | `strict_mode` | `bool` | `True`, `False` | `False` | If True, when a violation is found an AxeAccessibilityException is raised, causing a test failure. |
97
+ | `html_report_generated` | `bool` | `True`, `False` | `True` | If True, a HTML report will be generated summarising the axe-core findings. |
98
+ | `json_report_generated` | `bool` | `True`, `False` | `True` | If True, a JSON report will be generated with the full axe-core findings. |
99
+
100
+ ### Returns
101
+
102
+ This function can be used independently, but when set to a variable returns a `dict` with the axe-core results.
103
+
104
+ ### Example usage
105
+
106
+ from utils.axe import Axe
107
+ from playwright.sync_api import Page
108
+
109
+ def test_axe_example(page: Page) -> None:
110
+ page.goto("https://github.com/nhs-england-tools/playwright-python-blueprint")
111
+ Axe.run(page)
112
+
113
+ ## .run_list(): Multiple page scan
114
+
115
+ To scan multiple URLs within your application, you can use the following method:
116
+
117
+ Axe.run_list(page, page_list)
118
+
119
+ This runs the `Axe.run()` function noted above against each URL provided in the `page_list` argument, and will generate reports as required.
120
+
121
+ ### Required arguments
122
+
123
+ The following are required for `Axe.run_list()`:
124
+
125
+ | Argument | Format | Description |
126
+ | --------- | ------------------------ | ------------------------------------------------------------------ |
127
+ | page | playwright.sync_api.Page | A Playwright Page object to drive navigation to each page to test. |
128
+ | page_list | list[str] | A list of URLs to execute against |
129
+
130
+ > 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.
131
+
132
+ ### Optional arguments
133
+
134
+ The `Axe.run_list(page, page_list)` function has the following optional arguments that can be passed in:
135
+
136
+ | Argument | Format | Supported Values | Default Value | Description |
137
+ | -------------------------- | ----------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
138
+ | `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. |
139
+ | `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. |
140
+ | `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. |
141
+ | `strict_mode` | `bool` | `True`, `False` | `False` | If True, when a violation is found an AxeAccessibilityException is raised, causing a test failure. |
142
+ | `html_report_generated` | `bool` | `True`, `False` | `True` | If True, a HTML report will be generated summarising the axe-core findings. |
143
+ | `json_report_generated` | `bool` | `True`, `False` | `True` | If True, a JSON report will be generated with the full axe-core findings. |
144
+
145
+ ### Returns
146
+
147
+ 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).
148
+
149
+ ### Example usage
150
+
151
+ When using the following command: `pytest --base-url https://www.github.com`:
152
+
153
+ from utils.axe import Axe
154
+ from playwright.sync_api import Page
155
+
156
+ def test_accessibility(page: Page) -> None:
157
+ # A list of URLs to loop through
158
+ urls_to_check = [
159
+ "nhs-england-tools/playwright-python-blueprint",
160
+ "nhs-england-tools/playwright-python-blueprint/wiki"
161
+ ]
162
+
163
+ Axe.run_list(page, urls_to_check)
164
+
165
+
166
+ ## Licence
167
+
168
+ Unless stated otherwise, the codebase is released under the [MIT License](LICENCE.md). This covers both the codebase and any sample code in the documentation.
169
+
170
+ ## Acknowledgements
171
+
172
+ This package was created based on work initially designed for the
173
+ [NHS England Playwright Python Blueprint](https://github.com/nhs-england-tools/playwright-python-blueprint).
@@ -0,0 +1,150 @@
1
+ # Playwright Axe
2
+
3
+ This is a utility for Playwright Python that allows for the execution of [axe-core](https://github.com/dequelabs/axe-core), a JavaScript
4
+ library used for scanning for accessibility issues and providing guidance on how to resolve these issues.
5
+
6
+ ## Table of Contents
7
+
8
+ - [Playwright Axe](#playwright-axe)
9
+ - [Table of Contents](#table-of-contents)
10
+ - [Setup](#setup)
11
+ - [Using the Axe class](#using-the-axe-class)
12
+ - [.run(): Single page scan](#run-single-page-scan)
13
+ - [Required arguments](#required-arguments)
14
+ - [Optional arguments](#optional-arguments)
15
+ - [Returns](#returns)
16
+ - [Example usage](#example-usage)
17
+ - [.run\_list(): Multiple page scan](#run_list-multiple-page-scan)
18
+ - [Required arguments](#required-arguments-1)
19
+ - [Optional arguments](#optional-arguments-1)
20
+ - [Returns](#returns-1)
21
+ - [Example usage](#example-usage-1)
22
+ - [Licence](#licence)
23
+ - [Acknowledgements](#acknowledgements)
24
+
25
+ ## Setup
26
+
27
+ You can clone this whole repository using the code below:
28
+
29
+ ```shell
30
+ git clone https://github.com/davethepunkyone/playwright-axe.git
31
+ ```
32
+
33
+ ## Using the Axe class
34
+
35
+ You can initialise the Axe class by using the following code in your test file:
36
+
37
+ from utils.axe import Axe
38
+
39
+ 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 using Playwright.
40
+
41
+ ## .run(): Single page scan
42
+
43
+ To conduct a scan, you can just use the following once the page you want to check is at the right location:
44
+
45
+ Axe.run(page)
46
+
47
+ This will inject the axe-core code into the page and then execute the axe.run() command, generating an accessibility report for the page being tested.
48
+
49
+ By default, the `Axe.run(page)` command will do the following:
50
+
51
+ - Scan the page passed in to the WCAG 2.2 AA standard
52
+ - Generate a HTML and JSON report with the findings in the `axe-reports` directory, regardless of if any violations are found
53
+ - 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)
54
+ - 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
55
+
56
+ ### Required arguments
57
+
58
+ The following are required for `Axe.run()`:
59
+
60
+ | Argument | Format | Description |
61
+ | -------- | ------------------------ | -------------------------------------------- |
62
+ | page | playwright.sync_api.Page | A Playwright Page on the page to be checked. |
63
+
64
+ ### Optional arguments
65
+
66
+ The `Axe.run(page)` has the following optional arguments that can be passed in:
67
+
68
+ | Argument | Format | Supported Values | Default Value | Description |
69
+ | -------------------------- | ----------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
70
+ | `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. |
71
+ | `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. |
72
+ | `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. |
73
+ | `strict_mode` | `bool` | `True`, `False` | `False` | If True, when a violation is found an AxeAccessibilityException is raised, causing a test failure. |
74
+ | `html_report_generated` | `bool` | `True`, `False` | `True` | If True, a HTML report will be generated summarising the axe-core findings. |
75
+ | `json_report_generated` | `bool` | `True`, `False` | `True` | If True, a JSON report will be generated with the full axe-core findings. |
76
+
77
+ ### Returns
78
+
79
+ This function can be used independently, but when set to a variable returns a `dict` with the axe-core results.
80
+
81
+ ### Example usage
82
+
83
+ from utils.axe import Axe
84
+ from playwright.sync_api import Page
85
+
86
+ def test_axe_example(page: Page) -> None:
87
+ page.goto("https://github.com/nhs-england-tools/playwright-python-blueprint")
88
+ Axe.run(page)
89
+
90
+ ## .run_list(): Multiple page scan
91
+
92
+ To scan multiple URLs within your application, you can use the following method:
93
+
94
+ Axe.run_list(page, page_list)
95
+
96
+ This runs the `Axe.run()` function noted above against each URL provided in the `page_list` argument, and will generate reports as required.
97
+
98
+ ### Required arguments
99
+
100
+ The following are required for `Axe.run_list()`:
101
+
102
+ | Argument | Format | Description |
103
+ | --------- | ------------------------ | ------------------------------------------------------------------ |
104
+ | page | playwright.sync_api.Page | A Playwright Page object to drive navigation to each page to test. |
105
+ | page_list | list[str] | A list of URLs to execute against |
106
+
107
+ > 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.
108
+
109
+ ### Optional arguments
110
+
111
+ The `Axe.run_list(page, page_list)` function has the following optional arguments that can be passed in:
112
+
113
+ | Argument | Format | Supported Values | Default Value | Description |
114
+ | -------------------------- | ----------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
115
+ | `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. |
116
+ | `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. |
117
+ | `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. |
118
+ | `strict_mode` | `bool` | `True`, `False` | `False` | If True, when a violation is found an AxeAccessibilityException is raised, causing a test failure. |
119
+ | `html_report_generated` | `bool` | `True`, `False` | `True` | If True, a HTML report will be generated summarising the axe-core findings. |
120
+ | `json_report_generated` | `bool` | `True`, `False` | `True` | If True, a JSON report will be generated with the full axe-core findings. |
121
+
122
+ ### Returns
123
+
124
+ 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).
125
+
126
+ ### Example usage
127
+
128
+ When using the following command: `pytest --base-url https://www.github.com`:
129
+
130
+ from utils.axe import Axe
131
+ from playwright.sync_api import Page
132
+
133
+ def test_accessibility(page: Page) -> None:
134
+ # A list of URLs to loop through
135
+ urls_to_check = [
136
+ "nhs-england-tools/playwright-python-blueprint",
137
+ "nhs-england-tools/playwright-python-blueprint/wiki"
138
+ ]
139
+
140
+ Axe.run_list(page, urls_to_check)
141
+
142
+
143
+ ## Licence
144
+
145
+ Unless stated otherwise, the codebase is released under the [MIT License](LICENCE.md). This covers both the codebase and any sample code in the documentation.
146
+
147
+ ## Acknowledgements
148
+
149
+ This package was created based on work initially designed for the
150
+ [NHS England Playwright Python Blueprint](https://github.com/nhs-england-tools/playwright-python-blueprint).