Skip to content
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

Acceptance Tests: Guidance on [aria-*] attributes #663

Merged
merged 1 commit into from
Jul 19, 2022

Conversation

seanpdoyle
Copy link
Contributor

@seanpdoyle seanpdoyle commented May 9, 2022

When exercising pages that implement behaviors through custom or
third-party widgets, tests might locate elements or drive actions based
on CSS classes (e.g. .expanded or .collapsed) or [data-*]
attributes (e.g. [data-disclosure-toggled-value="true"] or
[data-test-id="toggle-widget"]).

While these techniques can be helpful work-arounds that exercise the
page, they're low-fidelity alternatives to end-users experiences.

When widgets cannot be exercised by Capybara's suite of selectors or
matchers like click_on, test authors should rely on the same sets of
WAI-ARIA compliant attributes that assistive technologies would expect.

For example, if an application's constraints obstruct the author from
implementing a "checkbox" form control with an <input type="checkbox">, the tests that drive the alternative should "check" a
form control with the [role="checkbox"] attribute, assert changes to
its [aria-checked] attribute, and conform to any of the other expected
attributes and behaviors outlined by the WAI ARIA Authoring
Practices
.

@seanpdoyle seanpdoyle requested a review from JoelQ May 9, 2022 18:10
@@ -55,9 +55,18 @@
- Use `it` block descriptions that describe the success and failure paths.
- Use spec/system directory to store system specs.
- Use spec/support/system for support code related to system specs.
- Don't assert an element's state with `[class]` or `[data-*]` attributes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@MatheusRich
Copy link
Contributor

Love it! It would be cool to have a blog post on this theme so we can link it here

When exercise pages that implement behaviors through custom or
third-party widgets, tests might locate elements or drive actions based
on CSS classes (e.g. `.expanded` or `.collapsed`) or `[data-*]`
attributes (e.g. `[data-disclosure-toggled-value="true"]` or
`[data-test-id="toggle-widget"]`).

While these techniques can be helpful work-arounds that exercise the
page, they're low-fidelity alternatives to end-users experiences.

When widgets cannot be exercised by Capybara's suite of selectors or
matchers like `click_on`, test authors should rely on the same sets of
WAI-ARIA compliant attributes that assistive technologies would expect.

For example, if an application's constraints obstruct the author from
implementing a "checkbox" form control with an `<input
type="checkbox">`, the tests that drive the alternative should "check" a
form control with the `[role="checkbox"]` attribute, assert changes to
its `[aria-checked]` attribute, and conform to any of the other expected
attributes and behaviors outlined by the [WAI ARIA Authoring
Practices][wai-aria-checkbox].

[wai-aria-checkbox]: https://www.w3.org/TR/wai-aria-practices/#checkbox
@seanpdoyle seanpdoyle force-pushed the testing-aria-attributes branch from 287dcc6 to ce342a7 Compare July 19, 2022 00:46
@seanpdoyle seanpdoyle merged commit 0027479 into main Jul 19, 2022
@seanpdoyle seanpdoyle deleted the testing-aria-attributes branch July 19, 2022 00:47
@KonnorRogers
Copy link

@MatheusRich totally just dropping in, but DOM-testing-library does a pretty good job of highlighting using roles and then using associated aria-* attributes for a given role.

https://testing-library.com/docs/queries/about#priority

https://testing-library.com/docs/queries/byrole

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants