Directory Structure of Cypress
Define Methods in Your Project
Its own API
Cypress comes with its own API: you can call it directly without additional processing.
For details on how to use it, please refer to the documentation: https://docs.cypress.io/api
Custom global methods
Custom global methods: there are many scenarios in the test cases are the same, the code of these scenarios can be encapsulated to facilitate a unified call, which can not only reduce duplicate code, but also to unify the code specification.
In this case, you can use Cypress.Commands.add in /support/command.js.
cy.task() and cy.exec()
As Cypress is executed in the browser, some operations may need to be executed using nodejs or command.
In this case, you need to use cy.task() or cy.exec().
Of course you need to define your own methods, where the task method needs to be defined in /plugins directory and the exec method needs to be defined in root(/) directory.
A single function or class
When a function needs to be called just in a number of other files, but does not need to be defined globally, you can use this way.
Examples for call methods
cy.login() // login() is defined in command.js |