Cypress gives us the ability to create custom commands and overwrite the existing commands. It comes with its API for creating custom and overwriting existing commands.
Overwriting existing commands
Before version 9.0.0,
Cypress did not warn us when we try to add
a command that already exists
in cypress using
and it leads to the unexpected behavior with a command
since it was unclear which would take precedence.
From Cypress 9.0.0,
if we try to add a command that
already exists using
Cypress will throw an error
should be used instead to overwrite
the behavior of existing commands.
This change is a breaking one, and it will throw an error if we had previously added any new command which already existed in Cypress.
It only works with the core Cypress commands. If we try to add a duplicate custom command that we have already defined, then Cypress will not throw an error. If we define more than one custom command with the same name Cypress will execute the last defined command.