0
0
Cypresstesting~5 mins

Common assertions (exist, be.visible, have.text) in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the exist assertion check in Cypress?
The exist assertion checks if an element is present in the DOM, regardless of whether it is visible or not.
Click to reveal answer
beginner
Explain the difference between exist and be.visible assertions.
exist checks if the element is in the DOM, while be.visible checks if the element is actually visible to the user on the page.
Click to reveal answer
beginner
How do you check if an element contains specific text using Cypress?
Use the have.text assertion to verify that an element's text content exactly matches the expected string.
Click to reveal answer
beginner
Write a Cypress assertion to check if a button with id #submit is visible.
cy.get('#submit').should('be.visible');
Click to reveal answer
intermediate
Why is it important to use be.visible instead of just exist when testing user interactions?
Because an element might exist in the DOM but be hidden or covered, so be.visible ensures the user can actually see and interact with it.
Click to reveal answer
Which Cypress assertion checks if an element is present in the DOM?
Aexist
Bbe.visible
Chave.text
Dcontain
What does be.visible assertion ensure?
AElement is in the DOM but hidden
BElement contains specific text
CElement is visible to the user
DElement is clickable
How do you check if an element's text exactly matches 'Hello World'?
Ashould('contain', 'Hello World')
Bshould('have.text', 'Hello World')
Cshould('exist')
Dshould('be.visible')
Which assertion would fail if the element is hidden but present in the DOM?
Aexist and be.visible
Bexist
Chave.text
Dbe.visible
What is the correct Cypress command to check if a button with class '.btn' exists?
Acy.get('.btn').should('exist');
Bcy.get('.btn').should('be.visible');
Ccy.get('.btn').should('have.text');
Dcy.get('.btn').should('contain');
Describe the purpose of the Cypress assertions: exist, be.visible, and have.text.
Think about presence, visibility, and text content separately.
You got /3 concepts.
    Explain why using be.visible is important when testing user interactions compared to just exist.
    Consider what the user actually experiences on the page.
    You got /3 concepts.