Cypress · Junior · Question 10 of 75

Why does Cypress recommend data-cy or data-test attributes for selectors?

Show the answer

Correct answer: They're stable and not tied to styling or text

Explanation

Classes change with design, text changes with copy. Dedicated test attributes survive both and show the element is used by tests.

Further reading

Problem with a question

Cypress · Junior · question 10

Test yourself

Take the Cypress · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz