Table of content

Custom commands in Cypress

In Cypress, a user can create a new command or redefine an existing command then those commands are called custom commands. To decrease the program size these commands are used. It is recommended to add new commands instead of overwriting the existing commands.

  • The custom commands are created in the path cypress/support/command.js
  • Adding a new command named login in the command.js file.
Cypress.Commands.add("login", (username, password) => {
  //adding a new command named login
  cy.contains("Sign in").click();
Adding a new command to the cypress is like adding a new function/method.

Let us call the login command in the program.

describe("custom commands", () => {
  it("should login using the custom commands", () => {
    cy.login("username", "password");

Output :


Execution of Test programs in Cypress

0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions