Cypress: Configurable pause/delay between commands to help with debugging

Created on 28 Sep 2016  路  9Comments  路  Source: cypress-io/cypress

ability to slow down the execution of a test via a configurable delay, e.g.

Cypress.config("waitAfterEachCommand", 2000)

existing workaround proposal 馃挕 feature

Most helpful comment

This is what I've been doing to get a delay between commands. You just have to make sure you're enumerating all the commands that you want a delay on in that array.

// support/commands.js
const COMMAND_DELAY = 500;


for (const command of ['visit', 'click', 'trigger', 'type', 'clear', 'reload', 'contains']) {
    Cypress.Commands.overwrite(command, (originalFn, ...args) => {
        const origVal = originalFn(...args);

        return new Promise((resolve) => {
            setTimeout(() => {
                resolve(origVal);
            }, COMMAND_DELAY);
        });
    });
} 

All 9 comments

:+1:

Hi guys, I am curious, is there any update on this ticket so far? I am looking for such a feature right now to avoid myself to add delay between all test steps. Thanks for your response.

Also whenever a drag command lands it would be nice to have the option to specify the speed of the drag.

This is what I've been doing to get a delay between commands. You just have to make sure you're enumerating all the commands that you want a delay on in that array.

// support/commands.js
const COMMAND_DELAY = 500;


for (const command of ['visit', 'click', 'trigger', 'type', 'clear', 'reload', 'contains']) {
    Cypress.Commands.overwrite(command, (originalFn, ...args) => {
        const origVal = originalFn(...args);

        return new Promise((resolve) => {
            setTimeout(() => {
                resolve(origVal);
            }, COMMAND_DELAY);
        });
    });
} 

@jacobgardner this solution is way better than cypress-wait-until package. Thank you!

This is what I've been doing to get a delay between commands. You just have to make sure you're enumerating all the commands that you want a delay on in that array.

// support/commands.js
const COMMAND_DELAY = 500;


for (const command of ['visit', 'click', 'trigger', 'type', 'clear', 'reload', 'contains']) {
    Cypress.Commands.overwrite(command, (originalFn, ...args) => {
        const origVal = originalFn(...args);

        return new Promise((resolve) => {
            setTimeout(() => {
                resolve(origVal);
            }, COMMAND_DELAY);
        });
    });
} 

How do I use this in the spec.js script? @jacobgardner
I'm a beginner.

something like this?

cy.get(".item").click(1000)

@heitrix All you have to do is add the code to support/index.js (or support/commands.js if it exists). Then you just call the commands as usual: cy.get(".item").click(). The commands will have the delay set by COMMAND_DELAY.

Update on the snippets above so you can just decide when to introduce the delay on an adhoc basis...

// support/commands.js
// Set CYPRESS_COMMAND_DELAY above zero for demoing to stakeholders,
// E.g. CYPRESS_COMMAND_DELAY=1000 node_modules/.bin/cypress open
const COMMAND_DELAY = Cypress.env('COMMAND_DELAY') || 0;
if (COMMAND_DELAY > 0) {
    for (const command of ['visit', 'click', 'trigger', 'type', 'clear', 'reload', 'contains']) {
        Cypress.Commands.overwrite(command, (originalFn, ...args) => {
            const origVal = originalFn(...args);

            return new Promise((resolve) => {
                setTimeout(() => {
                    resolve(origVal);
                }, COMMAND_DELAY);
            });
        });
    }
}

I am slowing down certain commands in this repo http://github.com/bahmutov/cypress-movie

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dkreft picture dkreft  路  3Comments

zbigniewkalinowski picture zbigniewkalinowski  路  3Comments

carloscheddar picture carloscheddar  路  3Comments

igorpavlov picture igorpavlov  路  3Comments

jennifer-shehane picture jennifer-shehane  路  3Comments