Bird
0
0

Consider this Page Object method:

medium📝 Predict Output Q5 of 15
Cypress - Test Organization and Patterns
Consider this Page Object method:
getErrorMessage() {
  return cy.get('.error-message')
}

What will happen if you call getErrorMessage().should('be.visible') in a test when the error message is not present on the page?
AThe test will throw a syntax error
BThe test will pass because Cypress ignores missing elements
CThe test will fail because the element is not found or not visible
DThe test will skip the assertion silently
Step-by-Step Solution
Solution:
  1. Step 1: Understand Cypress behavior on missing elements

    Cypress retries finding elements and waits for assertions. If the element never appears, the assertion fails.
  2. Step 2: Apply this to the should('be.visible') assertion

    If the '.error-message' element is missing or hidden, the assertion will fail and the test fails.
  3. Final Answer:

    The test will fail because the element is not found or not visible -> Option C
  4. Quick Check:

    Missing element assertion = Test fails [OK]
Quick Trick: Missing elements cause Cypress assertions to fail [OK]
Common Mistakes:
  • Thinking Cypress ignores missing elements
  • Expecting silent skips on failed assertions
  • Confusing syntax errors with runtime failures

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes