How to use Plugins
info
What you'll learn​
- How to install a plugin
- How to use a plugin
Cypress maintains a curated list of plugins created by us and the community. Plugins from our official list are npm modules. This enables them to be versioned and updated separately without needing to update Cypress itself.
You can install any published plugin using npm:
- npm
- yarn
- pnpm
npm install <plugin name> --save-dev
yarn add <plugin name> --dev
pnpm add --save-dev <plugin name>
Using a plugin​
Add your plugin to the
setupNodeEvents
function in the Cypress configuration. Please follow any additional instructions provided by the plugin's documentation.
Here's an example of what this might look like:
- cypress.config.js
- cypress.config.ts
const { defineConfig } = require('cypress')
module.exports = defineConfig({
// setupNodeEvents can be defined in either
// the e2e or component configuration
e2e: {
setupNodeEvents(on, config) {
// bind to the event we care about
on('<event>', (arg1, arg2) => {
// plugin stuff here
})
},
},
})
import { defineConfig } from 'cypress'
export default defineConfig({
// setupNodeEvents can be defined in either
// the e2e or component configuration
e2e: {
setupNodeEvents(on, config) {
// bind to the event we care about
on('<event>', (arg1, arg2) => {
// plugin stuff here
})
},
},
})
For information on writing plugins, please check out our Node Events Overview.