0
0
Cypresstesting~10 mins

Code coverage plugin in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test uses Cypress with a code coverage plugin to check if the homepage loads and the main heading is visible. It verifies that the heading text matches the expected value and that code coverage data is collected during the test.

Test Code - Cypress
Cypress
/// <reference types="cypress" />

describe('Homepage Code Coverage Test', () => {
  beforeEach(() => {
    cy.visit('https://example.cypress.io')
  })

  it('checks main heading and collects coverage', () => {
    cy.get('h1').should('be.visible').and('contain', 'Kitchen Sink')
  })
})
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsCypress test runner initialized with code coverage plugin enabled-PASS
2Browser opensBrowser window opens controlled by Cypress-PASS
3Navigates to 'https://example.cypress.io'Page loads with homepage contentPage URL is correctPASS
4Finds element 'h1'Main heading element is present and visibleElement 'h1' is visiblePASS
5Checks that 'h1' contains text 'Kitchen Sink'Heading text matches expectedText content contains 'Kitchen Sink'PASS
6Code coverage plugin collects coverage data during testCoverage data recorded for visited codeCoverage data exists and is validPASS
Failure Scenario
Failing Condition: The 'h1' element is missing or text does not match 'Kitchen Sink'
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about the 'h1' element?
AIt contains a button element
BIt is hidden on the page
CIt is visible and contains the text 'Kitchen Sink'
DIt has a CSS class named 'header'
Key Result
Always verify key page elements are visible and contain expected text to ensure the page loaded correctly. Using a code coverage plugin helps track which parts of your code run during tests, improving test quality.