Bird
0
0

Why should data-cy attributes be preferred over classes or IDs for test stability in Cypress, especially in large projects?

hard📝 Conceptual Q10 of 15
Cypress - Selecting Elements
Why should data-cy attributes be preferred over classes or IDs for test stability in Cypress, especially in large projects?
A<code>data-cy</code> attributes are dedicated to testing and less likely to change with UI redesigns
BClasses and IDs are deprecated in modern HTML and should not be used
C<code>data-cy</code> attributes automatically improve page load speed
DUsing <code>data-cy</code> attributes allows Cypress to bypass browser security
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of data-cy attributes

    They are custom attributes used only for testing, so they remain stable and unaffected by UI or style changes.
  2. Step 2: Compare with classes and IDs

    Classes and IDs often change due to design updates or refactoring, causing tests to break frequently.
  3. Final Answer:

    data-cy attributes are dedicated to testing and less likely to change with UI redesigns -> Option A
  4. Quick Check:

    Dedicated test attributes = B [OK]
Quick Trick: Use dedicated data-cy attributes to avoid test breakage [OK]
Common Mistakes:
  • Believing classes and IDs are deprecated
  • Thinking data-cy affects performance
  • Assuming data-cy bypasses security

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes