/// <reference types="cypress" />
// cypress/support/commands.js
Cypress.Commands.add('loginByCustomCommand', (email, password) => {
cy.get('input[name=email]').type(email)
cy.get('input[name=password]').type(password)
cy.get('button[type=submit]').click()
})
// cypress/e2e/login_spec.cy.js
describe('Login with custom plugin command', () => {
it('should login successfully using the custom command', () => {
cy.visit('https://example.cypress.io/login')
cy.loginByCustomCommand('user@example.com', 'Password123!')
cy.url().should('include', '/dashboard')
})
})The Cypress.Commands.add function is used to add a new custom command called loginByCustomCommand. This command types the email and password into the login form and clicks submit.
The test file login_spec.cy.js uses this new command to perform login. It visits the login page, calls the custom command with test credentials, and then asserts that the URL includes '/dashboard' indicating successful login.
This shows how plugins extend Cypress by adding reusable commands that simplify test scripts.