Bird
0
0

Consider this Cypress code snippet:

medium📝 Predict Output Q13 of 15
Cypress - Assertions
Consider this Cypress code snippet:
cy.get('.alert').should('not.exist')
cy.get('.alert').should('not.be.visible')

What will happen if the element .alert is present but hidden?
AThe first assertion fails, the second passes.
BThe first assertion passes, the second fails.
CBoth assertions pass.
DBoth assertions fail.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze should('not.exist') when element is present but hidden

    This assertion fails because the element exists in the DOM, even if hidden.
  2. Step 2: Analyze should('not.be.visible') when element is hidden

    This assertion passes because the element is present but not visible.
  3. Final Answer:

    The first assertion fails, the second passes. -> Option A
  4. Quick Check:

    Existence vs visibility differ: exist fails, visibility passes [OK]
Quick Trick: Existence and visibility are different checks [OK]
Common Mistakes:
  • Assuming 'not.exist' passes if element is hidden
  • Confusing visibility with existence
  • Thinking both assertions behave the same

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes