Overview - data-cy attributes for test stability
What is it?
Data-cy attributes are special markers added to HTML elements to help automated tests find and interact with them reliably. They act like name tags that testing tools use to identify parts of a webpage without confusion. Using data-cy attributes makes tests less likely to break when the page design changes. This helps keep tests stable and trustworthy over time.
Why it matters
Without stable ways to find elements, tests break often when developers change the page layout or styles. This causes wasted time fixing tests instead of improving the product. Data-cy attributes solve this by providing a clear, dedicated way to locate elements that won't change unless the feature itself changes. This keeps tests reliable and saves teams from constant test maintenance.
Where it fits
Before learning about data-cy attributes, you should understand basic HTML and how automated tests select elements on a page. After this, you can learn about writing robust test selectors and best practices for test automation frameworks like Cypress.