https://cypress.io logo
#general-chat
Title
# general-chat
b

breezy-pager-73919

02/03/2022, 2:04 PM
hey folks, is it possible to slow down the tests in cypress studio? eg. a cy.wait after each step?
f

fancy-match-96032

02/03/2022, 2:07 PM
suppose there was a way to do this -- what would be the reason? typically a manual
cy.wait
for a set amount of time would result in flaky tests, or at best slow down the test suite
b

breezy-pager-73919

02/03/2022, 2:08 PM
I just want to use our integration tests to demonstrate the app flows.
I tried to play the captured videos very slow but that doesn't work well
f

fancy-match-96032

02/03/2022, 2:27 PM
ah, i see. makes sense. to anyone reading this, please feel free to chime in with some other ideas 🙂 one way to do it would be to wrap each
cy
function you use with
Cypress.Commands.overwrite
, and in each overwrite do the
cy.wait
( https://docs.cypress.io/api/cypress-api/custom-commands#Overwrite-Existing-Commands). check for an environment variable (there's several ways to set this) called something like
demo
and only do your
wait
if it's true (https://docs.cypress.io/guides/guides/environment-variables) it would be pretty annoying to have one for every command, but you need a way to only
wait
for certain commands. for example you probably don't want to wait on a
cy.intercept
. i don't have a generic solution off the top of my head -- to make it generic you'd have to spend some time reading through the docs and trial-and-error. i haven't thought this through so it may not be doable, but for example having an array of strings that are the commands you'd want to wait on, and iterate over it with an overwrite for each.
when you get something working, i'd for sure be interested in how you ended up doing it
b

breezy-pager-73919

02/03/2022, 3:05 PM
Sounds promising, thanks! I'll give it a try 🙂
It works with custom commands, e.g.
Copy code
js
Cypress.Commands.add('getSlow', (selector, options) => {
    cy.wait(1000);
    return cy.get(selector, options);
});
But it doesn't with overwrite:
Copy code
js
Cypress.Commands.overwrite('get', (originalFn, selector, options) => {
    cy.wait(1000);
    return originalFn(selector, options);
});
which will result in this error:
Copy code
Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.

The command that returned the promise was:

  > cy.get()

The cy command you invoked inside the promise was:

  > cy.wait()

Because Cypress commands are already promise-like, you don't need to wrap them or return your own promise.

Cypress will resolve your command with whatever the final Cypress command yields.

The reason this is an error instead of a warning is because Cypress internally queues commands serially whereas Promises execute as soon as they are invoked. Attempting to reconcile this would prevent Cypress from ever resolving.
f

fancy-match-96032

02/04/2022, 2:52 PM
in your override, try
cy.wait(1000).then(...)
2 Views