Bird
0
0

Which of the following is the correct syntax to assert that an element with class alert contains the text 'Error' in Cypress?

easy📝 assertion Q3 of 15
Cypress - Assertions
Which of the following is the correct syntax to assert that an element with class alert contains the text 'Error' in Cypress?
Acy.get('.alert').should('contain.text', 'Error')
Bcy.get('.alert').assert('text', 'Error')
Ccy.find('.alert').should('have.text', 'Error')
Dcy.get('.alert').check('Error')
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct Cypress assertion syntax

    The correct method to assert text content is using should('contain.text', 'text') with cy.get().
  2. Step 2: Identify incorrect syntax options

    Options A, B, and C use invalid methods or commands not supported by Cypress.
  3. Final Answer:

    cy.get('.alert').should('contain.text', 'Error') -> Option A
  4. Quick Check:

    Correct assertion syntax = D [OK]
Quick Trick: Use should('contain.text', 'text') for text assertions [OK]
Common Mistakes:
  • Using assert instead of should
  • Using cy.find instead of cy.get
  • Using check for assertions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes