Bird
0
0

Given this Cypress E2E test code, what will be the output in the test report?

medium📝 Predict Output Q13 of 15
Cypress - Component Testing
Given this Cypress E2E test code, what will be the output in the test report?
describe('Login flow', () => {
  it('should show error on wrong password', () => {
    cy.visit('/login')
    cy.get('input[name="username"]').type('user1')
    cy.get('input[name="password"]').type('wrongpass')
    cy.get('button[type="submit"]').click()
    cy.contains('Invalid credentials').should('be.visible')
  })
})
ATest passes without checking any message
BTest fails because cy.visit() is not allowed in E2E
CTest fails due to syntax error in selectors
DTest passes if 'Invalid credentials' message appears
Step-by-Step Solution
Solution:
  1. Step 1: Analyze test steps

    The test visits the login page, enters username and wrong password, clicks submit, then checks for error message visibility.
  2. Step 2: Verify correctness of commands

    All commands are valid Cypress E2E commands. The assertion checks if the error message is visible, so test passes if message appears.
  3. Final Answer:

    Test passes if 'Invalid credentials' message appears -> Option D
  4. Quick Check:

    E2E test passes if error message visible [OK]
Quick Trick: E2E tests check full flow and visible messages [OK]
Common Mistakes:
  • Thinking cy.visit() is invalid in E2E
  • Ignoring the assertion on error message
  • Assuming syntax errors in selectors without cause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes