Bird
0
0

Which of the following test codes correctly implements this?

hard📝 framework Q15 of 15
Cypress - Basics and Setup
You want to write a Cypress test that visits https://example.com, clicks a button with class .submit-btn, and then checks if a success message with id #success-msg is visible. Which of the following test codes correctly implements this?
Adescribe('Submit test', () => { it('clicks and checks success', () => { cy.visit('https://example.com') cy.get('.submit-btn').click() cy.get('#success-msg').should('be.visible') }) })
Bdescribe('Submit test', () => { it('clicks and checks success', () => { cy.visit('https://example.com') cy.get('#submit-btn').click() cy.get('.success-msg').should('visible') }) })
Cdescribe('Submit test', () => { it('clicks and checks success', () => { cy.visit('https://example.com') cy.click('.submit-btn') cy.get('#success-msg').should('be.visible') }) })
Ddescribe('Submit test', () => { it('clicks and checks success', () => { cy.visit('https://example.com') cy.get('.submit-btn').click() cy.get('#success-msg').should('visible') }) })
Step-by-Step Solution
Solution:
  1. Step 1: Verify selectors and commands

    describe('Submit test', () => { it('clicks and checks success', () => { cy.visit('https://example.com') cy.get('.submit-btn').click() cy.get('#success-msg').should('be.visible') }) }) uses correct selectors: .submit-btn for class and #success-msg for id. It uses cy.get().click() correctly.
  2. Step 2: Check assertion syntax

    The code uses should('be.visible'), which is the correct assertion for visibility. Other options have wrong selectors or incorrect assertion keywords.
  3. Final Answer:

    describe('Submit test', () => { it('clicks and checks success', () => { cy.visit('https://example.com') cy.get('.submit-btn').click() cy.get('#success-msg').should('be.visible') }) }) -> Option A
  4. Quick Check:

    Correct selectors + click + should('be.visible') [OK]
Quick Trick: Use correct selectors and should('be.visible') for checks [OK]
Common Mistakes:
  • Mixing class and id selectors
  • Using cy.click() instead of cy.get().click()
  • Wrong assertion keyword 'visible' instead of 'be.visible'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes