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
Copy file name to clipboardExpand all lines: docs/accessibility/get-started/introduction.mdx
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,9 +9,7 @@ sidebar_position: 10
9
9
10
10
<AccessibilityAddon />
11
11
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).
Copy file name to clipboardExpand all lines: docs/app/guides/accessibility-testing.mdx
+27-16Lines changed: 27 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,34 +4,45 @@ title: Accessibility Testing
4
4
5
5
Accessibility testing helps to confirm that an application works correctly for people with disabilities.
6
6
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.
8
8
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.
10
10
11
11
## Including accessibility in your Cypress tests
12
12
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:
14
14
15
+
### Accessibility scans
15
16
- In-test plugins
16
17
- 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
18
22
19
23
We will discuss each of these below.
20
24
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
+
21
36
### In-test plugins
22
37
23
38
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.
24
39
25
40
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.
26
41
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.
28
43
29
44
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.
30
45
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
-
35
46
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.
36
47
37
48
@@ -41,11 +52,11 @@ In-test accessibility checks are the only kind available in typical testing plat
41
52
42
53
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.
43
54
44
-
###Accessibility-focused assertions
55
+
## Accessibility-specific tests
45
56
46
57
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.
47
58
48
-
####Asserting alt text of images
59
+
### Asserting alt text of images
49
60
50
61
To assert that the correct alternative text is present on your logo image, an explicit test can be written:
51
62
@@ -73,7 +84,7 @@ This kind of accessibility-friendly locator approach is also possible with the [
73
84
cy.findByRole('img', { name:'Cypress Logo' })
74
85
.should('be.visible')
75
86
```
76
-
####Asserting the accessible name of a button
87
+
### Asserting the accessible name of a button
77
88
78
89
A similar accessibility-minded locator technique can be used with interactive elements like buttons:
79
90
@@ -91,7 +102,7 @@ And using the Testing Library `ByRole` locator:
91
102
92
103
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.
93
104
94
-
####Test IDs, Testing Library, and Accessibility
105
+
### Test IDs, Testing Library, and Accessibility
95
106
96
107
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.
97
108
@@ -105,7 +116,7 @@ Whether you primarily use Testing Library element locators, test IDs, or a diffe
105
116
106
117
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.
107
118
108
-
####Roles vs elements - button example
119
+
### Roles vs elements - button example
109
120
110
121
The native HTML `button` element has a complex accessibility contract implemented by the browser for keyboard and screen reader users:
111
122
@@ -122,15 +133,15 @@ On the other hand, a `div` with `role` of `button` does not get this default bro
122
133
123
134
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.
124
135
125
-
####Where to test accessibility
136
+
## Where to test accessibility
126
137
127
138
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.
128
139
129
140
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.
130
141
131
142
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.
132
143
133
-
####Choosing a locator approach
144
+
### Choosing a locator approach
134
145
135
146
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.
0 commit comments