Bird
0
0

What will be the result of this Cypress code snippet?

medium📝 Predict Output Q13 of 15
Cypress - Assertions
What will be the result of this Cypress code snippet?
cy.get('#login').should('be.visible').and('have.class', 'active').and('contain.text', 'Login')
ATest throws syntax error due to chaining.
BTest fails if element #login is visible but missing class 'active'.
CTest passes even if element #login is not visible.
DTest passes if element #login is visible, has class 'active', and contains text 'Login'.
Step-by-Step Solution
Solution:
  1. Step 1: Understand chained assertions

    The code checks three things on element with id 'login': visibility, class presence, and text content.
  2. Step 2: Determine test pass/fail conditions

    All three conditions must be true for the test to pass. If any fail, test fails. Syntax is correct.
  3. Final Answer:

    Test passes if element #login is visible, has class 'active', and contains text 'Login'. -> Option D
  4. Quick Check:

    All chained assertions must pass [OK]
Quick Trick: All chained assertions must be true for pass [OK]
Common Mistakes:
  • Assuming test passes if only some assertions pass
  • Thinking chaining causes syntax error
  • Ignoring visibility check importance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes