Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable pause/delay between commands to help with debugging #249

Open
jhanink opened this issue Sep 27, 2016 · 17 comments
Open

Configurable pause/delay between commands to help with debugging #249

jhanink opened this issue Sep 27, 2016 · 17 comments
Labels
existing workaround type: feature New feature that does not currently exist

Comments

@jhanink
Copy link

jhanink commented Sep 27, 2016

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

Cypress.config("waitAfterEachCommand", 2000)

@brian-mann brian-mann added the type: feature New feature that does not currently exist label Sep 28, 2016
@brian-mann brian-mann changed the title Feature Request: configurable pause/delay between commands Configurable pause/delay between commands to help with debugging Sep 28, 2016
@LiberQuack
Copy link

👍

@mmysik
Copy link

mmysik commented Aug 28, 2018

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.

@jennifer-shehane jennifer-shehane added the stage: needs investigating Someone from Cypress needs to look at this label Sep 14, 2018
@tnrich
Copy link
Contributor

tnrich commented Nov 21, 2018

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

@jacobgardner
Copy link

jacobgardner commented Nov 29, 2018

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);
        });
    });
} 

@cypress-bot cypress-bot bot added stage: proposal 💡 No work has been done of this issue and removed stage: needs investigating Someone from Cypress needs to look at this labels Jul 23, 2019
@olegario96
Copy link

olegario96 commented Mar 8, 2020

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

@heitrix
Copy link

heitrix commented Jul 31, 2020

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)

@BrettHoutz
Copy link

@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.

@WillGibson
Copy link

WillGibson commented Aug 6, 2020

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);
            });
        });
    }
}

@bahmutov
Copy link
Contributor

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

@mrchantey
Copy link

another way to set env variables for WillGibson's solution:
npm cypress open --env COMMAND_DELAY=500

@MullerEsposito
Copy link

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 can I type the command with Typescript?

@BrettHoutz
Copy link

@MullerEsposito Peeking at the type definitions, Commands.overwrite has this signature:

      overwrite<T extends keyof Chainable>(name: T, fn: CommandFnWithOriginalFn<T>): void
      overwrite<T extends keyof Chainable, S extends PrevSubject>(name: T, fn: CommandFnWithOriginalFnAndSubject<T, PrevSubjectMap[S]>): void

So i would think that command should have type keyof Chainable.

@cypress-bot cypress-bot bot added stage: icebox and removed stage: proposal 💡 No work has been done of this issue labels Apr 28, 2022
@Karla-Reyes
Copy link

@MullerEsposito / BrettHoutz , saw your messages above. Can you elaborate on how you add/use the above scripts in commands and index.d.ts files with the typescript? Thanks

Can someone help me?
image

@MullerEsposito
Copy link

@MullerEsposito / BrettHoutz , saw your messages above. Can you elaborate on how you add/use the above scripts in commands and index.d.ts files with the typescript? Thanks

Can someone help me? image

Hey @Karla-Reyes, I couldn't do it with typescript. I used only js.

@bahmutov
Copy link
Contributor

Here is my solution to this problem: plugin https://github.com/bahmutov/cypress-slow-down

@wiegell
Copy link

wiegell commented Oct 16, 2023

How can I type the command with Typescript?

const COMMAND_DELAY = 500;

['visit', 'click', 'trigger', 'type', 'clear', 'reload', 'select'].forEach((command) => {
  Cypress.Commands.overwrite(command as unknown as keyof Cypress.Chainable<any>, (originalFn, ...args) => {
    const origVal = originalFn(...args);

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

@danman01
Copy link

danman01 commented Sep 7, 2024

How can I type the command with Typescript?

const COMMAND_DELAY = 500;

['visit', 'click', 'trigger', 'type', 'clear', 'reload', 'select'].forEach((command) => {
  Cypress.Commands.overwrite(command as unknown as keyof Cypress.Chainable<any>, (originalFn, ...args) => {
    const origVal = originalFn(...args);

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

This example works for TS and also note Cypress complains unless you remove "contains" command, which appears to not like being overwritten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
existing workaround type: feature New feature that does not currently exist
Projects
None yet
Development

No branches or pull requests