generated from NHSDigital/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
PPHA-413: Add accessbility testing using axe #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
lung_cancer_screening/core/tests/acceptance/helpers/assertion_helpers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,19 @@ | ||
| from playwright.sync_api import expect | ||
| from axe_playwright_python.sync_playwright import Axe | ||
|
|
||
|
|
||
| def expect_back_link_to_have_url(page, url): | ||
| back_link = page.locator(".nhsuk-back-link") | ||
| expect(back_link).to_have_count(1) | ||
| expect(back_link).to_have_attribute("href", url) | ||
|
|
||
|
|
||
| def expect_no_accessibility_violations(page): | ||
| axe = Axe() | ||
| axe_results = axe.run(page) | ||
| violations_msg = ( | ||
| f"Found the following accessibility violations: \n" | ||
| f"{axe_results.generate_snapshot()}" | ||
| ) | ||
| assert axe_results.violations_count == 0, violations_msg | ||
|
|
5 changes: 5 additions & 0 deletions
5
lung_cancer_screening/core/tests/acceptance/helpers/user_interaction_helpers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
194 changes: 194 additions & 0 deletions
194
lung_cancer_screening/core/tests/acceptance/test_accessibility.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| import os | ||
|
|
||
| from django.contrib.staticfiles.testing import StaticLiveServerTestCase | ||
| from django.test import tag | ||
Themitchell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from playwright.sync_api import sync_playwright | ||
|
|
||
| from .helpers.assertion_helpers import expect_no_accessibility_violations | ||
| from .helpers.user_interaction_helpers import setup_participant | ||
|
|
||
| @tag('accessibility') | ||
Themitchell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| class TestQuestionnaireAccessibility(StaticLiveServerTestCase): | ||
|
|
||
| @classmethod | ||
| def setUpClass(cls): | ||
| os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true" | ||
| super().setUpClass() | ||
| cls.playwright = sync_playwright().start() | ||
| cls.browser = cls.playwright.chromium.launch() | ||
|
|
||
| @classmethod | ||
| def tearDownClass(cls): | ||
| super().tearDownClass() | ||
| cls.browser.close() | ||
| cls.playwright.stop() | ||
|
|
||
| def test_start_page_accessibility(self): | ||
| page = self.browser.new_page() | ||
| page.goto(f"{self.live_server_url}/start") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_start_page_errors_accessibility(self): | ||
| page = self.browser.new_page() | ||
| page.goto(f"{self.live_server_url}/start") | ||
| page.click("text=Start now") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_have_you_ever_smoked_page_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/have-you-ever-smoked") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_have_you_ever_smoked_page_errors_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/have-you-ever-smoked") | ||
| page.click("text=Continue") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_date_of_birth_page_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/date-of-birth") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_date_of_birth_page_errors_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/date-of-birth") | ||
| page.click("text=Continue") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_height_page_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/height") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_height_page_errors_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/height") | ||
| page.click("text=Continue") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_height_imperial_page_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/height?unit=imperial") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_weight_page_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/weight") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_weight_page_errors_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/weight") | ||
| page.click("text=Continue") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_weight_imperial_page_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/weight?unit=imperial") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_weight_imperial_page_errors_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/weight?unit=imperial") | ||
| page.click("text=Continue") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_sex_at_birth_page_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/sex-at-birth") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_sex_at_birth_page_errors_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/sex-at-birth") | ||
| page.click("text=Continue") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_gender_page_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/gender") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_gender_page_errors_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/gender") | ||
| page.click("text=Continue") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_ethnicity_page_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/ethnicity") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_ethnicity_page_errors_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/ethnicity") | ||
| page.click("text=Continue") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| # def test_education_page_accessibility(self): | ||
| # page = self.browser.new_page() | ||
| # setup_participant(page, self.live_server_url) | ||
| # page.goto(f"{self.live_server_url}/education") | ||
| # expect_no_accessibility_violations(page) | ||
|
|
||
| # def test_respiratory_conditions_page_accessibility(self): | ||
| # page = self.browser.new_page() | ||
| # setup_participant(page, self.live_server_url) | ||
| # page.goto(f"{self.live_server_url}/respiratory-conditions") | ||
| # expect_no_accessibility_violations(page) | ||
|
|
||
| def test_asbestos_exposure_page_errors_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/asbestos-exposure") | ||
| page.click("text=Continue") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_asbestos_exposure_page_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/asbestos-exposure") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| # def test_cancer_diagnosis_page_accessibility(self): | ||
| # page = self.browser.new_page() | ||
| # setup_participant(page, self.live_server_url) | ||
| # page.goto(f"{self.live_server_url}/cancer-diagnosis") | ||
| # expect_no_accessibility_violations(page) | ||
|
|
||
| # def test_family_history_lung_cancer_page_accessibility(self): | ||
| # page = self.browser.new_page() | ||
| # setup_participant(page, self.live_server_url) | ||
| # page.goto(f"{self.live_server_url}/family-history-lung-cancer") | ||
| # expect_no_accessibility_violations(page) | ||
|
|
||
| def test_responses_page_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/responses") | ||
| expect_no_accessibility_violations(page) | ||
|
|
||
| def test_your_results_page_accessibility(self): | ||
| page = self.browser.new_page() | ||
| setup_participant(page, self.live_server_url) | ||
| page.goto(f"{self.live_server_url}/your-results") | ||
| expect_no_accessibility_violations(page) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.