0
0
Cypresstesting~10 mins

cy.click() in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a webpage, finds a button by its data-cy attribute, clicks it, and verifies that a confirmation message appears.

Test Code - Cypress
Cypress
describe('Button click test', () => {
  it('Clicks the submit button and checks confirmation', () => {
    cy.visit('https://example.com/form')
    cy.get('[data-cy="submit-button"]').click()
    cy.get('[data-cy="confirmation-message"]').should('be.visible').and('contain', 'Submitted successfully')
  })
})
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, no browser opened yet-PASS
2Browser opens and navigates to 'https://example.com/form'Browser displays the form page with a submit button-PASS
3Find element with selector '[data-cy=submit-button]'Submit button is located on the pageElement exists and is visiblePASS
4Click the submit button using cy.click()Button is clicked, form submission triggered-PASS
5Find element with selector '[data-cy=confirmation-message]'Confirmation message element is present after clickElement is visible and contains text 'Submitted successfully'PASS
6Test endsTest completed successfully with confirmation message shown-PASS
Failure Scenario
Failing Condition: The submit button is not found or not clickable
Execution Trace Quiz - 3 Questions
Test your understanding
What does cy.click() do in this test?
ANavigates to the form page
BClicks the submit button to trigger form submission
CFinds the confirmation message element
DChecks if the confirmation message is visible
Key Result
Always use clear, stable selectors like data-cy attributes for locating elements before clicking to ensure reliable tests.