Bird
0
0

Identify the error in this Cypress test code:

medium📝 Debug Q14 of 15
Cypress - Basics and Setup
Identify the error in this Cypress test code:
describe('My Test', () => {
  it('opens page', () => {
    cy.visit('https://example.com')
    cy.get('.button').should('visible')
  })
})
AIncorrect assertion keyword, should be <code>should('be.visible')</code>
BMissing parentheses in <code>should('visible')</code>
CWrong selector syntax for class
DMissing <code>it</code> block inside <code>describe</code>
Step-by-Step Solution
Solution:
  1. Step 1: Check assertion syntax

    The assertion should('visible') is incorrect. The correct form is should('be.visible') to check visibility.
  2. Step 2: Verify other parts

    The selector .button is correct for class, and it block is present. So only the assertion keyword is wrong.
  3. Final Answer:

    Incorrect assertion keyword, should be should('be.visible') -> Option A
  4. Quick Check:

    Use should('be.visible') for visibility [OK]
Quick Trick: Use exact assertion keywords like 'be.visible' [OK]
Common Mistakes:
  • Using 'visible' instead of 'be.visible'
  • Confusing selector syntax for classes
  • Omitting it block inside describe

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes