0
0
Cypresstesting~10 mins

Why plugins extend Cypress capabilities - Test Execution Impact

Choose your learning style9 modes available
Test Overview

This test checks that a Cypress custom command correctly extends Cypress commands by adding a custom command. It verifies the custom command runs and produces the expected result.

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

// cypress/support/commands.js
Cypress.Commands.add('login', (username, password) => {
  cy.get('#username').type(username)
  cy.get('#password').type(password)
  cy.get('#login-btn').click()
})

// cypress/integration/login_spec.js
describe('Login with custom command', () => {
  it('should login successfully using the custom login command', () => {
    cy.visit('https://example.cypress.io/login')
    cy.login('user1', 'password123')
    cy.url().should('include', '/dashboard')
    cy.get('h1').should('contain.text', 'Dashboard')
  })
})
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsCypress test runner initialized-PASS
2Browser opens and navigates to 'https://example.cypress.io/login'Login page with username, password fields and login button is visible-PASS
3Custom command 'login' is called with username 'user1' and password 'password123'Username and password fields are filled, login button is clicked-PASS
4Test waits for navigation to '/dashboard' pageDashboard page loads with heading 'Dashboard'URL includes '/dashboard'PASS
5Check that the page heading contains text 'Dashboard'Heading element visible with correct textHeading text contains 'Dashboard'PASS
6Test ends successfullyTest passed, no errors-PASS
Failure Scenario
Failing Condition: Custom command 'login' is not registered or fails to fill fields and click login
Execution Trace Quiz - 3 Questions
Test your understanding
What does the custom Cypress command 'login' do in this test?
AFills username and password fields and clicks login button
BNavigates directly to the dashboard page
CChecks if the login button is visible
DReloads the login page
Key Result
Using custom commands in Cypress helps reuse code and extend testing capabilities, making tests simpler and easier to maintain.