Bird
0
0

Identify the error in this Cypress test code snippet:

medium📝 Debug Q6 of 15
Cypress - Test Organization and Patterns
Identify the error in this Cypress test code snippet:
describe('Suite', () => {
  beforeEach(() => {
    cy.visit('/page')
  })

  it('Test', () => {
    cy.get('.btn').click()
  })

  afterEach(() => {
    cy.clearCookies
  })
})
AbeforeEach should be after afterEach
Bcy.visit should be inside the test, not beforeEach
Ccy.clearCookies is missing parentheses to call the function
Dcy.get selector '.btn' is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check afterEach syntax

    cy.clearCookies is a function and must be called with parentheses.
  2. Step 2: Identify missing parentheses error

    Missing () means the function is not executed, causing no cookie clearing.
  3. Final Answer:

    cy.clearCookies is missing parentheses to call the function -> Option C
  4. Quick Check:

    Function calls need () in Cypress [OK]
Quick Trick: Always add () to call Cypress commands [OK]
Common Mistakes:
  • Placing beforeEach after afterEach
  • Putting cy.visit inside test unnecessarily
  • Using invalid selectors without checking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes