Skip to content

Commit a94c9d6

Browse files
committed
cleanup and clarity
1 parent db9fe83 commit a94c9d6

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

docs/accessibility/get-started/introduction.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ sidebar_position: 10
99

1010
<AccessibilityAddon />
1111

12-
Cypress Accessibility provides organized, visual, and actionable accessibility reports, based completely on the tests you record to Cypress Cloud, and powered by Axe Core® by Deque Systems. This is the documentation page for that product.
13-
14-
To learn about the general topic of accessibility testing using the Cypress App, see [our guide on this topic](/app/guides/accessibility-testing).
12+
Cypress Accessibility provides organized, visual, and actionable accessibility reports, based completely on the tests you record to Cypress Cloud, and powered by Axe Core® by Deque Systems. This is the documentation page for that product. To learn about the general topic of accessibility testing using the Cypress App, see [our guide on this topic](/app/guides/accessibility-testing).
1513

1614
<DocsImage
1715
src="/img/accessibility/get-started/cypress-accessibility-overview.png"

docs/app/guides/accessibility-testing.mdx

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,45 @@ title: Accessibility Testing
44

55
Accessibility testing helps to confirm that an application works correctly for people with disabilities.
66

7-
To set a good foundation for an accessible user experience, web sites and apps must conform to certain guidelines, known as the [Web Content Accessibility Guidelines](https://www.w3.org/WAI/standards-guidelines/wcag/)(WCAG). Meeting or exceeding these guidelines will help ensure your disabled users can independently perceive the content of your application, navigate through your pages and sections, and complete the available actions.
7+
To set a good foundation for an accessible user experience, web sites and apps must conform to certain guidelines, known as the [Web Content Accessibility Guidelines](https://www.w3.org/WAI/standards-guidelines/wcag/) (WCAG). Meeting or exceeding these guidelines will help ensure your disabled users can independently perceive the content of your application, navigate through your pages and sections, and complete the available actions.
88

9-
Cypress supports many kinds of accessibility testing, including through a rich plugin ecosystem, standard test practices, as well as a commercial, enterprise-ready solution in Cypress Cloud.
9+
Cypress supports many kinds of accessibility testing, through standard test practices, a rich plugin ecosystem, as well as a commercial, enterprise-ready solution in Cypress Cloud.
1010

1111
## Including accessibility in your Cypress tests
1212

13-
There are three main ways to account for accessibility when testing with Cypress:
13+
Here are the main ways to account for accessibility when testing with Cypress:
1414

15+
### Accessibility scans
1516
- In-test plugins
1617
- Cypress Accessibility
17-
- Accessibility-focused assertions
18+
19+
### Explicit, application-specific tests
20+
- Accessibility-focused assertions and locators
21+
- Tests for specific functionality relevant to assistive technology
1822

1923
We will discuss each of these below.
2024

25+
26+
## Accessibility Scans
27+
28+
:::info
29+
Automated scans are effective because many accessibility issues are caused by incorrect HTML structure or missing data that would be required by assistive technologies like screen readers, voice control systems, Braille displays, and more. Browsers transform the current HTML on the page into a standardized format that other technologies can hook into. Automated scans in your tests will alert you if specific items needed for this process are missing.
30+
:::
31+
32+
:::warning
33+
Note that while automated scans do a good job at detecting violations of a known list of rules, no automated scan can prove that the interface is **fully** accessible and works well for users with disabilities. It is always necessary to understand the limitations and expected coverage provided by the library you choose, and then make a plan to cover the gaps with manual testing and/or traditional Cypress assertions about additional expected behavior, based on your knowledge of what is needed by your users.
34+
:::
35+
2136
### In-test plugins
2237

2338
The [`cypress-axe`](https://www.npmjs.com/package/cypress-axe) plugin integrates the popular [Axe Core® library by Deque Systems](https://github.com/dequelabs/axe-core/) into your Cypress tests.
2439

2540
After setting up the plugin, command are added to your project to inject the library and use it to run an accessibility check. Running the included `checkA11y()` command performs a scan of the current state of the page or component that you are testing, and you can choose to fail the test in response to accessibility issues detected. Detailed configuration is available to scope this to the specific WCAG Success Criteria and related rules that you want to test.
2641

27-
There are further plugins that are themselves built on top of `cypress-axe` and extend it in various ways, such as [`wick-a11y`](https://www.npmjs.com/package/wick-a11y) and [`cypress-a11y-report`](https://www.npmjs.com/package/cypress-a11y-report), as well as other accessibility testing libraries like the [IBM Equal Access Checker](https://www.npmjs.com/package/cypress-accessibility-checker). All of these tools have their own dedicated documentation for installation, setup, and executing the checks, which we won't repeat here.
42+
There are also some newer plugins that are themselves built on top of `cypress-axe` and extend it in various ways, such as [`wick-a11y`](https://www.npmjs.com/package/wick-a11y) and [`cypress-a11y-report`](https://www.npmjs.com/package/cypress-a11y-report), as well as other accessibility testing libraries like the [IBM Equal Access Checker](https://www.npmjs.com/package/cypress-accessibility-checker). All of these tools have their own dedicated documentation for installation, setup, and executing the checks, which we won't repeat here.
2843

2944
The general "add a command to trigger a scan" approach helps detect and prevent all-too-common issues like poor color contrast, missing labels for icons and buttons, images without alt text, and other errors in the implementation of a user interface that can be detected with generic checks.
3045

31-
:::warning
32-
Note that no automated scan can prove that the interface is fully accessible and works well for users with disabilities, so it is always necessary to understand the limitations and expected coverage provided by the library you choose, and then make a plan to cover the gaps with manual testing and/or traditional Cypress assertions about additional expected behavior.
33-
:::
34-
3546
A combination of automated checks to reveal mistakes in the implementation, and specific assertions about the important user flows can be extremely powerful and helps catch much more accessibility regressions than either approach taken alone.
3647

3748

@@ -41,11 +52,11 @@ In-test accessibility checks are the only kind available in typical testing plat
4152

4253
To learn more, you can read our [dedicated docs](/accessibility/get-started/introduction), or review a [public live example of an automatically-generated accessibility report](http://on.cypress.io/rwa-accessibility-views) in our Cypress Realworld App demo project.
4354

44-
### Accessibility-focused assertions
55+
## Accessibility-specific tests
4556

4657
While automation like Axe Core® can detect missing attributes and other aspects of code quality that impact the experience of people with disabilities using the web, this kind of automation doesn't know anything about your specific application and the expectations you have for your users. That's where including accessibility in your specs comes in.
4758

48-
#### Asserting alt text of images
59+
### Asserting alt text of images
4960

5061
To assert that the correct alternative text is present on your logo image, an explicit test can be written:
5162

@@ -73,7 +84,7 @@ This kind of accessibility-friendly locator approach is also possible with the [
7384
cy.findByRole('img', { name: 'Cypress Logo' })
7485
.should('be.visible')
7586
```
76-
#### Asserting the accessible name of a button
87+
### Asserting the accessible name of a button
7788

7889
A similar accessibility-minded locator technique can be used with interactive elements like buttons:
7990

@@ -91,7 +102,7 @@ And using the Testing Library `ByRole` locator:
91102

92103
There are some important differences to consider between locating specific HTML elements themselves and locating those same elements only by their `role`, which is the main Testing Library recommendation. We'll discuss these in the next section.
93104

94-
#### Test IDs, Testing Library, and Accessibility
105+
### Test IDs, Testing Library, and Accessibility
95106

96107
The use of `data-cy`-style test ID attributes to help with test stability has been a longstanding [best practice recommendation](/app/core-concepts/best-practices#Selecting-Elements) by Cypress. Test IDs are resilient to non-functional functional UI changes because they don't specify anything about the nature of the code or content itself, only that some element with that data attribute is present. When code changes, as long as the `data-cy` attributes are preserved in the right places, all the tests using them should continue to pass.
97108

@@ -105,7 +116,7 @@ Whether you primarily use Testing Library element locators, test IDs, or a diffe
105116

106117
There is much more to this topic than we can cover here, but we will provide a small example, and a recommendation for what to do.
107118

108-
#### Roles vs elements - button example
119+
### Roles vs elements - button example
109120

110121
The native HTML `button` element has a complex accessibility contract implemented by the browser for keyboard and screen reader users:
111122

@@ -122,15 +133,15 @@ On the other hand, a `div` with `role` of `button` does not get this default bro
122133

123134
This means that, without some assertions about either the `button` element itself, or a full test of the accessibility "contract" of that element, it is not safe for a developer to refactor from from a `button` to a `div`, even though Testing Library will treat each as the same if located using the `ByRole` locator. This is because, much like test IDs, the `ByRole` approach is intended to _avoid_ testing the implementation directly, to keep tests resilient.
124135

125-
#### Where to test accessibility
136+
## Where to test accessibility
126137

127138
So what should you do in your test automation to help confirm the UI is accessible? First of all, for known critical areas like forms or checkout flows, ensure that the accessibility behavior is tested explicitly in at least one place. The means verifying that form fields and buttons have the correct labels and use the expected HTML elements, and other aspects of the DOM that communicate necessary information.
128139

129140
Component tests are a fantastic place to do this centralized accessibility spec work, whether using [Cypress Component testing](/app/component-testing/get-started) or something else. Component tests are run locally during development, written by developers as they build UI, and can easily specify the specific HTML that is intended to be rendered, without being a distraction in an end-to-end test of a specific user flow.
130141

131142
Accessibility should be tested at least once for a given component, area of the application, or workflow. Once that is achieved, there is no additional accessibility benefit to repeatedly asserting subsets of the same things in other tests, unless those tests introduce new combinations of components that have not been tested for accessibility anywhere else.
132143

133-
#### Choosing a locator approach
144+
### Choosing a locator approach
134145

135146
Test IDs are the most resilient locator option and are a good choice for maximizing the stability of your pipeline, especially if end-to-end tests are written by people who are not familiar with accessibility, and don't already know the correct roles, elements, and behavior that should be expected. You do not lose any accessibility "coverage", as long as accessibility is explicitly tested for with assertions, and a library like Axe Core® is in place to catch mistakes.
136147

0 commit comments

Comments
 (0)