Plugins and Support
Learn the purpose of plugins, the support folder in Cypress, and how they enhance our test suite and make it reusable.
Plugins in Cypress help us to tap into the internal workings of the framework and modify it according to our taste. It allows us to execute code at various stages of the Cypress lifecycle.
The “plugins” folder comes with a single index.js
file by default. This is what Cypress will automatically look for when loading plugins.
Of course, we can customize the project structure through the cypress.json
configuration file:
{
// The default location of the plugins file
"pluginsFile": "cypress/plugins/index.js"
}
Common use cases for plugins
Let’s look at some common use cases to better understand plugins in Cypress.
Configuration
The most common way to use plugins is to configure the environment programmatically. This lets us:
- Use different configurations for different environments
- Modify the Cypress configuration values
The default plugin file exports a module with two arguments: on
and config
:
Get hands-on with 1200+ tech skills courses.