breezy-pager-73919
02/03/2022, 2:04 PMfancy-match-96032
02/03/2022, 2:07 PMcy.wait
for a set amount of time would result in flaky tests, or at best slow down the test suitebreezy-pager-73919
02/03/2022, 2:08 PMbreezy-pager-73919
02/03/2022, 2:08 PMfancy-match-96032
02/03/2022, 2:27 PMcy
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.fancy-match-96032
02/03/2022, 2:30 PMbreezy-pager-73919
02/03/2022, 3:05 PMbreezy-pager-73919
02/04/2022, 9:23 AMjs
Cypress.Commands.add('getSlow', (selector, options) => {
cy.wait(1000);
return cy.get(selector, options);
});
But it doesn't with overwrite:
js
Cypress.Commands.overwrite('get', (originalFn, selector, options) => {
cy.wait(1000);
return originalFn(selector, options);
});
which will result in this error:
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.
fancy-match-96032
02/04/2022, 2:52 PMcy.wait(1000).then(...)