Find elements the way your users do with cy.getByRole()
Blog post from Cypress
Cypress 16.2.0 introduces the built-in cy.getByRole() query, which locates elements through their accessible roles and names, offering a supported alternative to Cypress Testing Library’s findByRole() queries and encouraging tests that reflect how assistive technologies identify controls. The query returns all matching elements, retries automatically, excludes accessibility-hidden elements by default, supports name matching and shadow DOM, and uses chained filters for states such as selected, checked, expanded, or heading level. For roles with native HTML equivalents, it deliberately matches only native elements by default, so a div with role="button" is excluded unless native: false is specified; this behavior is intended to expose accessibility risks because ARIA roles alone do not provide keyboard handling, disabled behavior, form submission, or other built-in native control functionality. Teams can selectively enable non-native matching, configure it as a project default, and migrate gradually from Cypress Testing Library, accounting for differences in matching multiple elements and filtering states. The feature complements Cypress Accessibility, which uses axe-core to audit broader page states, while cy.getByRole() focuses on making the controls directly used in tests accessible and semantically clear.
| Trend | Post Mentions | Total Month Mentions | Posts | Companies | MoM |
|---|---|---|---|---|---|
| AI Agents | 1 | 2,616 | 663 | 181 | -53% |
Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.