Bird
0
0

When adding data-cy attributes to elements for Cypress testing, which practice ensures the best maintainability?

easy📝 Conceptual Q2 of 15
Cypress - Selecting Elements
When adding data-cy attributes to elements for Cypress testing, which practice ensures the best maintainability?
AUse descriptive and unique values that reflect the element's purpose
BReuse the same <code>data-cy</code> value for multiple buttons to save time
CAdd <code>data-cy</code> attributes only to visible elements
DUse random strings as <code>data-cy</code> values to avoid conflicts
Step-by-Step Solution
Solution:
  1. Step 1: Identify maintainability factors

    Selectors should be clear and unique to avoid confusion.
  2. Step 2: Evaluate options

    Descriptive and unique data-cy values make tests easier to read and maintain.
  3. Final Answer:

    Use descriptive and unique values that reflect the element's purpose -> Option A
  4. Quick Check:

    Clear naming prevents selector conflicts and improves readability [OK]
Quick Trick: Name data-cy attributes clearly and uniquely [OK]
Common Mistakes:
  • Duplicating data-cy values
  • Using meaningless random strings
  • Ignoring hidden elements that need testing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes