question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cy.wait() does not resolve aliases in Cypress 6.0.x

See original GitHub issue

Current behavior

After upgrading from the latest version of v5 to v6.0.0, we are seeing issues with cy.wait() not resolving aliases set with cy.intercept(). When our app makes the request, Cypress shows that the request matched and the count # under routes shows 1. See screenshot. Additionally when the route is hit, hovering over where the request occurred in the runner shows “<route> ResponseReceived aliased as: pinReport”. The subsequent cy.wait() command however times out after the default timeout saying that request never occurred.

Temporarily switching back to cy.route() also results in the same issue.

Important to mention also is that this happens about 50% of the time. Sometimes cy.wait() knows the request happened and the test passes, other times it times out like in the screenshot below.

image

Desired behavior

cy.wait() should resolve the alias when matched by cy.intercept()

Test code to reproduce

  it('should pin a report', () => {
    cy.intercept({
      method: 'POST',
      path: '/api/report_for_report_indices/*/star',
    }).as('pinReport');

    cy.getByTestId('button__pin')
      .first()
      .click({
        force: true
      });

    cy.wait('@pinReport')
      .its('response.statusCode')
      .should('eq', 204);
  });

Versions

Cypress version v6.0.0 and v6.0.1 Worked with Cypress v5.x Browser: Chrome Version 87.0.4280.67 (Official Build) (x86_64) Operating System: macOS, also ran reproducible in GitHub Actions on a ubuntu-18 container

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:21 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
OldSchooledcommented, Dec 15, 2020

Well, something with the url is definetaly changed. (cypress 6.0.1 and cypress 6.1.0)

wait for this alias fails, but worked before (with route)

    cy.intercept({
      method: 'GET',
      url: '/Admin/api/setOffGetData?item_id=*',
    }).as('setOffGetData')

this works:

    cy.intercept({
      method: 'GET',
      url: '**/Admin/api/setOffGetData?item_id=*',
    }).as('setOffGetData')

But the cypress log shows:

image

Something is prepended to the url, but it is not visible anywhere. I hope this helps someone.

url now matches the full url, including the base path (hostname). For your first example, you would use path instead which excludes the hostname.

1reaction
DBLacicommented, Dec 21, 2020

Well, something with the url is definetaly changed. (cypress 6.0.1 and cypress 6.1.0)

wait for this alias fails, but worked before (with route)

    cy.intercept({
      method: 'GET',
      url: '/Admin/api/setOffGetData?item_id=*',
    }).as('setOffGetData')

this works:

    cy.intercept({
      method: 'GET',
      url: '**/Admin/api/setOffGetData?item_id=*',
    }).as('setOffGetData')

But the cypress log shows:

image

Something is prepended to the url, but it is not visible anywhere. I hope this helps someone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

wait - Cypress Documentation
When passing an array of aliases to cy. wait() , Cypress will wait for all requests to complete within the given requestTimeout and...
Read more >
Cypress. Why is my route alias not matching? - Stack Overflow
called wait() with a long timeout. I can watch the request complete in the network pane while the wait spinner turns happily in...
Read more >
Cypress Best Practices For Test Automation - LambdaTest
The command cy.request() will not resolve until it receives the response from the server, so adding an arbitrary waiting time is not necessary ......
Read more >
How to wait for a request to finish before moving on with Cypress
Do you know any workarounds? ERROR: Timed out retrying after 5000ms: cy.wait() timed out waiting 5000ms for the 1st request to the route:...
Read more >
Cypress - Quick Guide - Tutorialspoint
Cypress - Quick Guide, Cypress is an open-source and free test automation tool, ... //alias element as parent cy.get('#txt').find('li').first().as('parent') ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found