0
0
Cypresstesting~20 mins

Common assertions (exist, be.visible, have.text) in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Assertion Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
assertion
intermediate
2:00remaining
Check element visibility and text content
You want to verify that a button with id #submitBtn is visible and has the exact text Submit. Which Cypress assertion chain correctly does this?
Cypress
cy.get('#submitBtn')
Ashould('exist').and('be.visible').and('have.text', 'Submit')
Bshould('be.visible').and('exist').and('contain.text', 'Submit')
Cshould('exist').and('have.text', 'Submit').and('be.visible')
Dshould('be.visible').and('have.text', 'Submit').and('exist')
Attempts:
2 left
💡 Hint
Remember the order of assertions does not affect the test, but the exact text match requires 'have.text'.
assertion
intermediate
1:30remaining
Detect missing element with assertion
You want to confirm that an element with class .error-message does NOT exist on the page. Which assertion correctly verifies this?
Cypress
cy.get('.error-message')
Ashould('have.length', 0)
Bshould('not.be.visible')
Cshould('not.have.text')
Dshould('not.exist')
Attempts:
2 left
💡 Hint
To check absence, use the 'not.exist' assertion.
Predict Output
advanced
2:00remaining
What is the test result of this assertion chain?
Given the HTML <div id='msg' style='display:none'>Hello</div>, what will be the result of this Cypress code?
Cypress
cy.get('#msg').should('exist').and('be.visible').and('have.text', 'Hello')
ATest fails at 'be.visible' assertion
BTest passes successfully
CTest fails at 'have.text' assertion
DTest fails at 'exist' assertion
Attempts:
2 left
💡 Hint
The element exists but is hidden by CSS.
locator
advanced
1:30remaining
Choose the best locator for asserting text content
You want to assert the text of a paragraph inside a section with id #info. Which locator is best to use with Cypress for this assertion?
Acy.get('.info p')
Bcy.get('#info > p')
Ccy.contains('p', 'expected text')
Dcy.get('p').eq(0)
Attempts:
2 left
💡 Hint
Use a locator that is specific and stable.
framework
expert
2:00remaining
Identify the failing assertion in a chained test
Consider this Cypress test code snippet:
cy.get('.notification')
  .should('exist')
  .and('be.visible')
  .and('have.text', 'Success')
  .and('have.class', 'active')

If the element exists, is visible, has text 'Success', but does NOT have class 'active', which assertion causes the test to fail?
Cypress
cy.get('.notification').should('exist').and('be.visible').and('have.text', 'Success').and('have.class', 'active')
A'have.text' assertion fails
B'exist' assertion fails
C'have.class' assertion fails
D'be.visible' assertion fails
Attempts:
2 left
💡 Hint
Check which condition is not met by the element.