-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Comments
👍 |
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! |
How do I use this in the spec.js script? @jacobgardner something like this? cy.get(".item").click(1000) |
@heitrix All you have to do is add the code to |
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 |
another way to set env variables for WillGibson's solution: |
How can I type the command with Typescript? |
@MullerEsposito Peeking at the type definitions, 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 |
@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 |
Hey @Karla-Reyes, I couldn't do it with typescript. I used only js. |
Here is my solution to this problem: plugin https://github.com/bahmutov/cypress-slow-down |
|
This example works for TS and also note Cypress complains unless you remove "contains" command, which appears to not like being overwritten. |
ability to slow down the execution of a test via a configurable delay, e.g.
Cypress.config("waitAfterEachCommand", 2000)
The text was updated successfully, but these errors were encountered: