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

cy.wrap does not respect timeout #5980

Closed
janakdr opened this issue Dec 17, 2019 · 9 comments · Fixed by #7284
Closed

cy.wrap does not respect timeout #5980

janakdr opened this issue Dec 17, 2019 · 9 comments · Fixed by #7284

Comments

@janakdr
Copy link

@janakdr janakdr commented Dec 17, 2019

This example spec file fails with the error below:

describe('Cypress wait', () => {
  it('wrap does not wait', () => {
    cy.wrap(
        new Promise((resolve) => setTimeout(resolve, 5000)), {timeout: 20000});
  });
});
 Cypress wait
    1) wrap does not wait


  0 passing (4s)
  1 failing

  1) Cypress wait wrap does not wait:
     Error: Cypress command timeout of '4000ms' exceeded.
      at http://localhost:57838/__cypress/runner/cypress_runner.js:103532:25

Shouldn't cy.wrap respect the timeout option? The test passes if I pass --config defaultCommandTimeout=6000 on the command line, but I want to pass a specific timeout for this cy.wrap command.

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Dec 17, 2019

I do feel like it should respect the timeout option here.

The code for the .wrap() command can be found here:

https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/misc.coffee#L28:L28

@cypress-bot cypress-bot bot added the stage: ready for work label Dec 17, 2019
janakdr added a commit to givedirectly/Google-Partnership that referenced this issue Dec 17, 2019
And use that backup if the new one is not found. We do this by catching a failure in our score promise and substituting the backup if the failure seems to be from a missing asset.

This works out because we don't do any processing of the score asset except via that promise. Stern comment added to that effect.

Test has a horrible wait because of an apparent Cypress bug (cypress-io/cypress#5980).
@datner
Copy link
Contributor

@datner datner commented Jan 26, 2020

should the entire run wait for the timeout before advancing the test? Won't that potentially make the test take too long?

@janakdr
Copy link
Author

@janakdr janakdr commented Jan 26, 2020

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Jan 28, 2020

Please read the docs for the defaultCommandTimeout definition. https://on.cypress.io/configuration#Timeouts It is not per test, but per command and yes, increasing the timeout will sometimes increase the test time when it has to potentially retry for the entirety of the command timeout.

@jasonkoon
Copy link

@jasonkoon jasonkoon commented Feb 4, 2020

I am seeing the same issue. I am using cy.wrap to make an async call to set up some data. Sometimes it takes longer than 4 seconds which causes the test to fail.

@figalex
Copy link

@figalex figalex commented Feb 27, 2020

I'm seeing the same problem. I'm setting the timeout property to 12000 and I'm still getting the "4000ms timeout exceeded" error.

Using cypress version 3.6.1

@donleqt
Copy link

@donleqt donleqt commented Mar 19, 2020

Hello here is a workaround to force Cypress to wait for a promise:

/**
 *  helper function that forces cy to wait for a promise
 *
 * @export
 * @param {Promise} promise promise to wait
 * @param {number} [interval=1000] recheck in minlisecons
 * @returns
 */
export function waitPromise(promise, interval = 1000) {
  let isDone = false;

  const runPromise = () => {
    if (isDone) {
      // Wrap and returns the result
      return cy.wrap(promise.catch(error => assert.isNotOk(true, error)));
    }
    return cy.wait(interval).then(() => runPromise());
  };

  // Marks as resolved
  promise.then(() => (isDone = true)).catch(() => (isDone = true));

  return runPromise();
}

And in-use example

it('Restore Password - Should received an email', () => {
  const task = emailHelper.searchLastEmail({
    emailAddress: user.email,
    subject: 'Reset Password',
    timeout: 2 * 60000 // 2 min
  });

  testHelpers.waitPromise(task).then(mail => {
    // Save for later test
    restorePasswordMail = mail;
    return expect(mail).not.to.be.null;
  });
});

@cypress-bot cypress-bot bot added stage: work in progress stage: needs review and removed stage: ready for work stage: work in progress stage: needs review labels May 8, 2020
@cypress-bot cypress-bot bot added stage: needs review and removed stage: work in progress labels Jun 1, 2020
@cypress-bot cypress-bot bot added the stage: pending release label Jun 1, 2020
@cypress-bot
Copy link

@cypress-bot cypress-bot bot commented Jun 1, 2020

The code for this is done in cypress-io/cypress#7284, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot cypress-bot bot removed the stage: needs review label Jun 1, 2020
@cypress-bot
Copy link

@cypress-bot cypress-bot bot commented Jun 8, 2020

Released in 4.8.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v4.8.0, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: pending release label Jun 8, 2020
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jun 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants