cypress-slow-down
Slow down your Cypress tests
Watch the introduction to this plugin in the video Slow Down Cypress Tests. For advanced usage, see the lessons in my Cypress Plugins course.
Install
Add this NPM package to your project
# install using NPM
$ npm i -D cypress-slow-down
# or install using Yarn
$ yarn add -D cypress-slow-down
Include the plugin and call its function from your spec or support file
import { slowCypressDown } from 'cypress-slow-down'
slowCypressDown()
Options
You can control the delay before each command (in milliseconds)
slowCypressDown(1000)
You can also control the delay using the Cypress environment variable commandDelay
.
const { defineConfig } = require('cypress')
module.exports = defineConfig({
e2e: {
env: {
commandDelay: 500,
},
},
})
import { slowCypressDown } from 'cypress-slow-down'
slowCypressDown()
You can set the optional logToConsole
parameter to false to prevent the plugin from logging each delay to the console.
slowCypressDown(1000, false)
Disable the slow down
You can disable the default slowdown by using false
. For example, from the command line you can pass the boolean value:
$ npx cypress run --env commandDelay=false
Or you can use the process (OS) environment variable
$ CYPRESS_commandDelay=false npx cypress run
Or you can use the cypress.config.js
to disable the slowdown
const { defineConfig } = require('cypress')
module.exports = defineConfig({
e2e: {
env: {
commandDelay: false,
},
},
})
Change the command delay from DevTools
Because this plugin uses cypress-plugin-config to read the command delay option, you can change its value or disable the plugin completely from the DevTools console using the command Cypress.setPluginConfigValue('commandDelay', <value>)
The re-run the tests by pressing the key "R" or clicking "Run All Tests" button.
Child commands
You can slow down a part of your test by using the custom dual commands cy.slowDown(ms)
and cy.slowDownEnd()
.
import { slowCypressDown } from 'cypress-slow-down'
import 'cypress-slow-down/commands'
slowCypressDown(false)
it('runs the middle part slowly', () => {
cy.visit('/')
cy.get('...').should('...').slowDown(1000)
...
cy.slowDownEnd()
})
Tip: to see how the commands are slowed down you can use the cypress-timestamps plugin.
Small print
Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2022
License: MIT - do anything with the code, but don't blame me if it does not work.
Support: if you find any problems with this module, email / tweet /
open issue on Github