Recall & Review
beginner
Why should you avoid using CSS classes or IDs that might change frequently as selectors in Cypress tests?
Because these selectors can change when the UI design changes, making tests fragile and prone to breaking even if the functionality is fine.
Click to reveal answer
beginner
What is the recommended attribute to use for selectors in Cypress tests?
Use custom data attributes like
data-cy or data-test because they are stable and only used for testing, so they don't change with UI updates.Click to reveal answer
intermediate
How does using semantic HTML elements help with selectors?
Semantic elements like
<button> or <nav> make selectors clearer and improve accessibility, which benefits both users and tests.Click to reveal answer
intermediate
What is a good practice when writing selectors to avoid brittle tests?
Write selectors that are specific enough to find the element but not too tied to styling or layout, for example, use
data-cy='submit-button' instead of .btn-primary.Click to reveal answer
beginner
Why should you avoid using text content as the only selector in Cypress tests?
Because text can change due to translations or content updates, making tests fail even if the element is still there and working.
Click to reveal answer
Which attribute is best to use for stable selectors in Cypress tests?
✗ Incorrect
Custom attributes like data-cy are meant for testing and less likely to change, making tests more stable.
What is a downside of using CSS classes as selectors in tests?
✗ Incorrect
CSS classes often change when the UI is redesigned, which can break tests that rely on them.
Why avoid using visible text as the only selector?
✗ Incorrect
Text content can change, causing tests to fail even if the element is present.
Which selector practice improves both test stability and accessibility?
✗ Incorrect
Data attributes keep selectors stable, and semantic HTML helps screen readers and test clarity.
What is a good way to write selectors to avoid brittle tests?
✗ Incorrect
Custom data attributes with clear names help tests find elements reliably without breaking easily.
Explain why using custom data attributes like data-cy is recommended for selectors in Cypress tests.
Think about what makes a selector less likely to break when the UI changes.
You got /3 concepts.
Describe how semantic HTML elements and good selector practices contribute to both accessibility and test stability.
Consider the benefits for users and testers.
You got /3 concepts.