0
0
Cypresstesting~5 mins

Value and attribute assertions in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a value assertion in Cypress?
A value assertion checks if an element's value matches the expected value, like verifying the text inside an input field.
Click to reveal answer
beginner
How do you assert an attribute value in Cypress?
Use .should('have.attr', 'attributeName', 'expectedValue') to check if an element has a specific attribute with the expected value.
Click to reveal answer
beginner
Example: How to check if a button has the attribute disabled in Cypress?
Use cy.get('button').should('have.attr', 'disabled'). This checks if the button has the disabled attribute, meaning it is not clickable.
Click to reveal answer
beginner
What does .should('have.value', 'text') do in Cypress?
It asserts that the element's value property equals the given text, useful for input fields or textareas.
Click to reveal answer
beginner
Why are value and attribute assertions important in testing?
They confirm that the UI elements have the correct data and states, ensuring the app behaves as expected for users.
Click to reveal answer
Which Cypress command checks if an element has a specific attribute with a certain value?
Acy.get('selector').should('have.class', 'value')
Bcy.get('selector').should('have.text', 'value')
Ccy.get('selector').should('contain', 'value')
Dcy.get('selector').should('have.attr', 'attributeName', 'value')
How do you assert the value of an input field in Cypress?
Acy.get('input').should('have.value', 'expectedValue')
Bcy.get('input').should('have.text', 'expectedValue')
Ccy.get('input').should('contain', 'expectedValue')
Dcy.get('input').should('have.attr', 'value')
What does the assertion .should('have.attr', 'disabled') verify?
AThe element contains text 'disabled'
BThe element is visible
CThe element has a disabled attribute, meaning it is disabled
DThe element has a class named 'disabled'
Which assertion would you use to check if a button's title attribute equals 'Submit'?
Acy.get('button').should('have.attr', 'title', 'Submit')
Bcy.get('button').should('have.value', 'Submit')
Ccy.get('button').should('contain', 'Submit')
Dcy.get('button').should('have.text', 'Submit')
Why is it better to use attribute assertions instead of text assertions for checking element states?
AText assertions cannot fail
BAttributes reflect element states more reliably than visible text
CAttributes are only for styling
DText assertions are faster
Explain how to use Cypress to assert that an input field contains the expected value.
Think about how you check the text inside a form field.
You got /3 concepts.
    Describe how attribute assertions help verify UI element states in Cypress tests.
    Consider how a button can be disabled or enabled.
    You got /3 concepts.