Bird
0
0

You want to write a Cypress test to confirm a button with class .save-btn exists, is visible, and has the exact text Save. Which code snippet correctly performs all these checks?

hard📝 Application Q15 of 15
Cypress - Assertions
You want to write a Cypress test to confirm a button with class .save-btn exists, is visible, and has the exact text Save. Which code snippet correctly performs all these checks?
Acy.get('.save-btn').should('exist').should('be.visible').should('have.text', 'Save')
Bcy.get('.save-btn').should('be.visible').should('contain.text', 'Save')
Ccy.get('.save-btn').should('exist').should('have.text', 'Save')
Dcy.get('.save-btn').should('have.text', 'Save').should('be.visible')
Step-by-Step Solution
Solution:
  1. Step 1: Check presence, visibility, and exact text

    We need to confirm the element exists, is visible, and has exact text 'Save'.
  2. Step 2: Verify chaining of assertions

    cy.get('.save-btn').should('exist').should('be.visible').should('have.text', 'Save') chains should('exist'), should('be.visible'), and should('have.text', 'Save') correctly to check all conditions.
  3. Final Answer:

    cy.get('.save-btn').should('exist').should('be.visible').should('have.text', 'Save') -> Option A
  4. Quick Check:

    Chain exist, visible, exact text for full check [OK]
Quick Trick: Chain all assertions to check presence, visibility, and text [OK]
Common Mistakes:
  • Skipping 'exist' check before visibility
  • Using 'contain.text' instead of 'have.text' for exact match
  • Not chaining all required assertions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes