0
0
Cypresstesting~10 mins

Screenshot capture (cy.screenshot) in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a webpage, clicks a button, and captures a screenshot to verify the page state visually.

Test Code - Cypress
Cypress
describe('Screenshot capture test', () => {
  it('should capture screenshot after button click', () => {
    cy.visit('https://example.cypress.io')
    cy.get('a[href="/commands/actions"]').click()
    cy.screenshot('after-click')
    cy.get('.action-email').should('be.visible')
  })
})
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, no browser opened yet-PASS
2Browser opens and navigates to 'https://example.cypress.io'Example Cypress homepage loadedPage loaded successfullyPASS
3Finds link with href '/commands/actions' and clicks itNavigated to Actions commands pageLink found and clickedPASS
4Captures screenshot named 'after-click'Screenshot saved in Cypress screenshots folderScreenshot file createdPASS
5Finds input with class '.action-email' and checks visibilityInput field visible on pageInput field is visiblePASS
Failure Scenario
Failing Condition: The link with href '/commands/actions' is not found or not clickable
Execution Trace Quiz - 3 Questions
Test your understanding
What does cy.screenshot('after-click') do in this test?
AIt saves a screenshot of the current page state with the name 'after-click'.
BIt clicks a button named 'after-click'.
CIt verifies the page URL contains 'after-click'.
DIt waits for an element with id 'after-click' to appear.
Key Result
Always verify elements exist and are interactable before taking screenshots to ensure meaningful visual validation.