0
0
Cypresstesting~10 mins

Custom plugin development in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks a custom Cypress plugin that logs a message before the test run. It verifies the plugin runs and the log appears in the console.

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

// cypress/plugins/index.js
module.exports = (on, config) => {
  on('before:run', () => {
    console.log('Custom plugin: Test run is starting');
  });
};

// cypress/e2e/sample_spec.cy.js
describe('Custom Plugin Test', () => {
  it('should run a simple test and trigger plugin log', () => {
    cy.visit('https://example.cypress.io');
    cy.contains('type').click();
    cy.url().should('include', '/commands/actions');
  });
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Cypress test runner starts and loads pluginsCypress initializes and loads cypress/plugins/index.js-PASS
2Custom plugin logs message before test runConsole shows 'Custom plugin: Test run is starting'Verify console log message appearsPASS
3Test visits https://example.cypress.ioBrowser opens example Cypress page-PASS
4Test clicks on link containing text 'type'Page navigates to /commands/actionsURL includes '/commands/actions'PASS
5Assertion checks URL contains '/commands/actions'URL is https://example.cypress.io/commands/actionscy.url().should('include', '/commands/actions')PASS
Failure Scenario
Failing Condition: Custom plugin code has syntax error or plugin file missing
Execution Trace Quiz - 3 Questions
Test your understanding
What does the custom plugin do before the test run?
ALogs a message to the console
BClicks a button on the page
CChanges the URL
DAsserts the page title
Key Result
Always verify that custom plugins are loaded and their side effects (like logging) occur before running tests to ensure plugin integration works correctly.