0
0
Cypresstesting~5 mins

data-cy attributes for test stability in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of using data-cy attributes in testing?

data-cy attributes are used to create stable and reliable selectors for tests. They help tests find elements without depending on classes or IDs that might change during development.

Click to reveal answer
beginner
Why should you avoid using classes or IDs for selectors in Cypress tests?

Classes and IDs often change as the UI evolves, which can break tests. data-cy attributes are dedicated for testing and usually stay the same, making tests more stable.

Click to reveal answer
beginner
How do you select an element with data-cy='submit-button' in Cypress?

You use cy.get('[data-cy="submit-button"]') to select the element with that attribute.

Click to reveal answer
intermediate
What is a key benefit of using data-cy attributes for test selectors?

They separate test selectors from styling or functionality code, reducing the chance that UI changes will break tests.

Click to reveal answer
beginner
Can data-cy attributes affect the user experience or page layout?

No, data-cy attributes are invisible to users and do not affect styling or layout. They are only used for testing purposes.

Click to reveal answer
What is the main reason to use data-cy attributes in Cypress tests?
ATo improve page loading speed
BTo style elements with CSS
CTo add IDs to elements
DTo create stable selectors that don't break when UI changes
Which selector is best practice for selecting a button with data-cy='login'?
Acy.get('[data-cy="login"]')
Bcy.get('.login')
Ccy.get('#login')
Dcy.get('button')
What happens if you use classes for selectors and the class name changes?
ATests continue to work without changes
BTests may fail because selectors no longer match
CThe page layout breaks
DThe browser crashes
Are data-cy attributes visible to users on the webpage?
AYes, they show as labels
BYes, they change the color of elements
CNo, they are invisible and only used for testing
DNo, but they slow down the page
Which of the following is NOT a benefit of using data-cy attributes?
AMakes tests run faster
BSeparates test selectors from styling
CReduces test breakage from UI changes
DImproves test stability
Explain why using data-cy attributes improves test stability in Cypress.
Think about what breaks tests when UI changes.
You got /4 concepts.
    Describe how to write a Cypress command to select a button with data-cy='submit' and click it.
    Remember the syntax for attribute selectors in Cypress.
    You got /3 concepts.