if we are calling some XHR request on the end of the test then it will pass,
but if we want to catch XHR request on page load it's not working...
example:

describe('Help Page', () => {
it('visit /help', () => {
const USER = Cypress.env('username');
const PASS = Cypress.env('userpass');
cy.visit('/');
cy.server();
cy.route('POST', '**login').as('auth');
cy.get('input[name=username]').type(USER);
cy.get('input[name=password]').type(PASS);
cy.get('button[type=submit]').click();
cy.wait('@auth');
latest cypress version 3.0.2
same for reset password
it('try to check content', () => {
cy.server();
cy.route('POST','**').as('getLogin');
cy.route('POST', '**/check-reset-password-token').as('ra');
cy.wait('@ra').then((xhr) => {
expect(xhr.status).to.equal(401);
});
cy.get('input');
cy.contains('Token Time Expired');
});
everything fine in browser, but cypress ignores this request...
but for example if I have login test, that is working
it('try to login (wrong credentials)', () => {
cy.server();
cy.route('POST', '*login').as('getLogin');
cy.get('button[type=submit]').as('submitButton');
cy.get('@submitButton')
.click()
.should('be.disabled');
cy.wait('@getLogin').then((xhr) => {
expect(xhr.status).to.equal(401);
cy.get('input.is-invalid').should('have.length', 2);
});
});
You want to ensure that the page routes and loads before waiting for the xhr? If this is the case, I would rewrite the assertions to ensure the page has transitioned first before waiting like this:
describe('Help Page', () => {
it('visit /help', () => {
const USER = Cypress.env('username');
const PASS = Cypress.env('userpass');
cy.visit('/');
cy.server();
cy.route('POST', '**login').as('auth');
cy.get('input[name=username]').type(USER);
cy.get('input[name=password]').type(PASS);
cy.get('button[type=submit]').click();
cy.url().should('include', 'dashboard') // <-- add whatever route you land on after login.
cy.wait('@auth');
Let me know if I understood your issue correctly.
@jennifer-shehane it doesn't matter... from your example cy.wait('@auth'); can be before cy.url() and should work but it doesn't
it's react application so page is already loaded, and then I call XHR request to the server, but that request is not logged..
so cypress is attached with some delay to page, after first XHR call
now I fixed my tests and it's running in Chrome but in Electron they didn't catch XHR, an application is faster than Cypress...
this code is working in chrome. but fail in electron
cy.server();
cy.route('POST', '**/check-reset-password-token').as('check');
cy.visit('/reset-password/random-token');
// Should be on a new URL which includes '/reset-password'
cy.url().should('include', '/reset-password');
cy.wait('@check').then((xhr) => {
expect(xhr.status).to.equal(400);
});
The issue is the same error as before? The wait times out?
hi @jennifer-shehane yes same issue, but now just in electron
The same for me. The idea is that I have some filters and every time that a value is changed a XHR call takes place. I want to be able to wait when the call is finished. Something like:
cy.server();
cy.route({method: 'GET', url: '**/communications/system/posts/*'}).as('getPosts');
cy.get('#search').click();
cy.wait("@getPosts");
Unfortunately we'll have to close this issue if no reproducible example is provided. Can anyone provide a way to reproduce this?
Can't catch the xhr
cy.visit('http://dreamsets.me/mp3/file/maroon%205')
cy.get('.track').eq(2).as('track')
cy.server()
cy.route('GET', '**.roskomnadzor.cc**').as('getMp3')
cy.get('@track').find('div.buttPl.play').first()
.click()
cy.wait('@getMp3', {timeout: 15000}).its('status').should('be.gte', 200).should('be.lessThan', 400)
Same here. I have a protected route that will check if the user is logged in then pull the user profile information if it doesn't exist, etc... as a result, this will occur around / during page load time.
context('given the user is logged in', () => {
const username = 'admin';
const accessToken = 'token';
before(() => {
cy.server({ force404: true });
});
beforeEach(() => {
StorageService.storeUserCredentials({
accessToken,
username,
});
});
context('given they have non-cached charts configured', () => {
beforeEach(() => {
cy.fixture('userConfig').as('usersJSON');
cy.route({
method: 'GET',
url: `${REST_API}${REST_API.USER_PROFILE}/${username}`,
status: 200,
headers: {
'Cache-Control': 'no-cache',
'x-access-token': accessToken,
},
response: '@usersJSON',
}).as('getUserProfile');
});
context('when I navigate to the Dashboard page', () => {
beforeEach(() => {
cy.visit(DASHBOARD_PATH);
});
it('should render my charts', () => {
cy.wait('@getUserProfile').then(xhr => {
cy.get('div[data-cy=graph]')
.each(($el, index, $list) => {}) // TODO verify order
.then($lis => {
cy.fixture('userConfig').then(config => {
expect($lis).to.have.length(config.charts.length); // true
});
});
});
});
});
Protected Route: React, Redux, Redux Saga, React-Router
<ProtectedRoute exact path={DASHBOARD_PATH} component={Dashboard} />
In that HOC component, it will dispatch the call just before rendering the Dashboard page
Hey @dzhagon, I've noticed there is an uncaught exception within a promise in your code when attempting to click to play the mp3. I can't be sure whether it is related to causing the wait to fail, but I think the request is not going out because of it.

The error includes a link to https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
Since there is not an actual user engaging with the audio (it's being driven in Cypress), Chrome does not allow the audio to play. You should take special notice of the "Developer switches" section of this document for workarounds - especially passing flags --disable-features=PreloadMediaEngagementData,AutoplayIgnoreWebAudio, MediaEngagementBypassAutoplayPolicies - see how to pass flags here: https://on.cypress.io/browser-launch-api
@iamgollum I understand sharing the code is difficult, but we'll need something we can run locally to reproduce the exact error state in order to investigate the cause of the issue.
I'm experiencing the same issue. The XHR is triggered by .click() on a <li> element. Everything that is using a <button> element is being caught.
I ended up adding a cy.wait(500) since the XHR is too fast for the cy.wait('@postAPI') to catch. :(
Hi,
I'm having the same issue. I have an XHR that runs when calling .click() on an <li> element. I see it in devtools console but not in the cypress console. It timeouts on the cy.wait('@alias') of my route.
I have the same issue, the xhr call is too fast
cy.route('GET', this.exampleJson.xhr_para_perfilar.perfilar).as('perfilar')
cy.get('[name="searchButton"]')
.click()
.wait('@perfilar')
CypressError: Timed out retrying: cy.wait() timed out waiting 5000ms for the 1st request to the route: 'perfilar'. No request ever occurred.
Info to reproduce the issue

@luismiguelbravo can you start the server and spy on the route _before_ cy.visit? Seems cy.visit loads the app, the app makes XHR call right away and by the time you set your spy with cy.route it is too late
@bahmutov yes, I can, this example is just for reproduce de main issue in the thread
The problem: "XHR call is too fast and occur before the .wait('@*')"
I think in your case "the request happens before cy.route"
On Wed, Mar 27, 2019 at 9:36 AM Luis Miguel Bravo notifications@github.com
wrote:
@bahmutov https://github.com/bahmutov yes, I can, this example is just
for reproduce de main issue in the threadThe problem: "XHR call is too fast and occur before the .wait('@*')"
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/cypress-io/cypress/issues/2188#issuecomment-477157155,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACHAps1gU9a1BCiTcdAQQDG5aCUsHSk8ks5va3PCgaJpZM4VZnfB
.
--
Dr. Gleb Bahmutov, PhD
Schedule video chat / phone call / meeting with me via
https://calendly.com/bahmutov
gleb.[email protected] @bahmutov https://twitter.com/@bahmutov
https://glebbahmutov.com/ https://glebbahmutov.com/blog
https://github.com/bahmutov
@bahmutov
I get the same problem in this case, (some execution work nice but some other get this error: CypressError: Timed out retrying: cy.wait() timed out waiting 5000ms for the 1st request to the route: 'perfilar'. No request ever occurred.)
cy.route('GET', this.exampleJson.xhr_para_perfilar.perfilar).as('perfilar')
cy.get('[name="searchButton"]')
.click()
.wait('@perfilar')
I think in your case "the request happens before cy.route"
…
On Wed, Mar 27, 2019 at 9:36 AM Luis Miguel Bravo @.*> wrote: @bahmutov https://github.com/bahmutov yes, I can, this example is just for reproduce de main issue in the thread The problem: "XHR call is too fast and occur before the .wait('@*')" — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#2188 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/ACHAps1gU9a1BCiTcdAQQDG5aCUsHSk8ks5va3PCgaJpZM4VZnfB .
-- Dr. Gleb Bahmutov, PhD Schedule video chat / phone call / meeting with me via https://calendly.com/bahmutov gleb.[email protected] @bahmutov https://twitter.com/@bahmutov https://glebbahmutov.com/ https://glebbahmutov.com/blog https://github.com/bahmutov
Luis, you have just shown a different code snippet, please check your
original one - does it work when you move cy.server and cy.route BEFORE
cy.visit?
On Wed, Mar 27, 2019 at 9:43 AM Luis Miguel Bravo notifications@github.com
wrote:
I get the same problem in this cas, (some execution work nice but some
other get this error: CypressError: Timed out retrying: cy.wait() timed out
waiting 5000ms for the 1st request to the route: 'perfilar'. No request
ever occurred.)cy.route('GET', this.exampleJson.xhr_para_perfilar.perfilar).as('perfilar')
cy.get('[name="searchButton"]') .click() .wait('@perfilar')I think in your case "the request happens before cy.route"
… <#m_-4229374854950402830_>
On Wed, Mar 27, 2019 at 9:36 AM Luis Miguel Bravo @.*> wrote:
@bahmutov https://github.com/bahmutov https://github.com/bahmutov
https://github.com/bahmutov yes, I can, this example is just for
reproduce de main issue in the thread The problem: "XHR call is too fast
and occur before the .wait('@*')" — You are receiving this because you
were mentioned. Reply to this email directly, view it on GitHub <#2188
(comment)
https://github.com/cypress-io/cypress/issues/2188#issuecomment-477157155>,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACHAps1gU9a1BCiTcdAQQDG5aCUsHSk8ks5va3PCgaJpZM4VZnfB
.
-- Dr. Gleb Bahmutov, PhD Schedule video chat / phone call / meeting with
me via https://calendly.com/bahmutov gleb.[email protected] @bahmutov
https://github.com/bahmutov https://twitter.com/@bahmutov
https://glebbahmutov.com/ https://glebbahmutov.com/blog
https://github.com/bahmutov—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/cypress-io/cypress/issues/2188#issuecomment-477160696,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACHAprJc0bovUeFfXBmYrhTVBgqj8Epfks5va3WQgaJpZM4VZnfB
.
--
Dr. Gleb Bahmutov, PhD
Schedule video chat / phone call / meeting with me via
https://calendly.com/bahmutov
gleb.[email protected] @bahmutov https://twitter.com/@bahmutov
https://glebbahmutov.com/ https://glebbahmutov.com/blog
https://github.com/bahmutov
@bahmutov In this case work perfect

Luis, you have just shown a different code snippet, please check your original one - does it work when you move cy.server and cy.route BEFORE cy.visit? On Wed, Mar 27, 2019 at 9:43 AM Luis Miguel Bravo notifications@github.com wrote:
…
I get the same problem in this cas, (some execution work nice but some other get this error: CypressError: Timed out retrying: cy.wait() timed out waiting 5000ms for the 1st request to the route: 'perfilar'. No request ever occurred.) cy.route('GET', this.exampleJson.xhr_para_perfilar.perfilar).as('perfilar') cy.get('[name="searchButton"]') .click() .@.') I think in your case "the request happens before cy.route" … <#m_-4229374854950402830_> On Wed, Mar 27, 2019 at 9:36 AM Luis Miguel Bravo *@.> wrote: @bahmutov https://github.com/bahmutov https://github.com/bahmutov https://github.com/bahmutov yes, I can, this example is just for reproduce de main issue in the thread The problem: "XHR call is too fast and occur before the .wait('@')" — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#2188 (comment) <#2188 (comment)>>, or mute the thread https://github.com/notifications/unsubscribe-auth/ACHAps1gU9a1BCiTcdAQQDG5aCUsHSk8ks5va3PCgaJpZM4VZnfB . -- Dr. Gleb Bahmutov, PhD Schedule video chat / phone call / meeting with me via https://calendly.com/bahmutov @.* @bahmutov https://github.com/bahmutov @.* https://glebbahmutov.com/ https://glebbahmutov.com/blog https://github.com/bahmutov — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#2188 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/ACHAprJc0bovUeFfXBmYrhTVBgqj8Epfks5va3WQgaJpZM4VZnfB .
-- Dr. Gleb Bahmutov, PhD Schedule video chat / phone call / meeting with me via https://calendly.com/bahmutov gleb.[email protected] @bahmutov https://twitter.com/@bahmutov https://glebbahmutov.com/ https://glebbahmutov.com/blog https://github.com/bahmutov
@luismiguelbravo can you paste the screenshot of the second situation that times out?
I can not public the screenshot of second situation because "confidentiality", but I will make an example with express js to expose the problem.
@luismiguelbravo can you paste the screenshot of the second situation that times out?
@bahmutov this work just right

I will check my code
Thanks for your atention :D
I've been having the same problem, when i was running the app via yarn start it worked perfectly.
When i change to run on the the builded version, it was too fast for it.
To fix it, i've done:
describe('Edit a transport plan is already ok', () => {
beforeEach(() => {
cy.server();
cy.route({
method: 'GET',
url: '/v1/pcp/bf/branches/300/transportplans**',
response: 'fixture:transportplan/GET_ListTPUnconfigured.json'
}).as('filterTransportPlan');
});
it('Start the test', () => {
cy.wait(500); //waited then i access the first page and the stub xhr start to work
cy.visit('/');
});
it('Load the list of transport plans', () => {
cy.wait('@filterTransportPlan').its('url').should('include', '?configured=false');
});
});
Closing, some have mentioned resolving their issues after providing a reproducible example while others have not provided a reproducible example.
Please open a new issue with a fully reproducible example if you are experiencing a related issue that appears to be a bug in Cypress. We can't do anything without understanding the complete picture and seeing the problem ourselves.
Was experiencing the same issue but then found this documented workaround - https://github.com/cypress-io/cypress/issues/95#issuecomment-281273126
We find this workaround for the .click() and .wait() for xhr
...
cy.server();
cy.route('GET', '**/api/v1/hcl/').as('syncdone');
cy.get("[type=button]").contains('Sync HCL').as('submitButton');
cy.get('@submitButton').click();
cy.wait('@syncdone').then((xhr) => {
console.log(xhr)
});
...
It doesn't work to me too with Cypress 3.4.1
When I launch Google Chrome and follow scenario manually step by step and check traffic (inspector) I see the HXR request which is not displayed while Cypress test is run :(
I see request in cypress terminal, but the response is missing in cypress log (view where I see all test steps while the test is ongoing)
Here is a reproducible example: https://stackoverflow.com/questions/57403153/network-requests-not-showing-up-in-cypress-command-log
describe('example', () => {
it('visits a page', () => {
cy.server();
cy.route('POST', '**');
cy.visit('https://www.academia.edu/12297791/Open_Access_Meets_Discoverability_Citations_to_Articles_Posted_to_Academia.edu');
});
});
@bleakley-ps Running the test case you pasted passes. I'm not sure what it meant to be wrong in your example exactly.

Hi, I'm having the same issue, the wait always timeout! Even if I increase the timeout time. I'm using cypress 4.7.0 and the API is a graphql API, the requests don't appear on the sidebar! I think that the request might be to fast and for that reason, it's not caught by cypress!


@danisal See this issue #5999
Thanks for pointing out the open issue. Also, I've updated cypress to version 4.11.0 and I manage to get it working!, so far the tests are passing!
Most helpful comment
Closing, some have mentioned resolving their issues after providing a reproducible example while others have not provided a reproducible example.
Please open a new issue with a fully reproducible example if you are experiencing a related issue that appears to be a bug in Cypress. We can't do anything without understanding the complete picture and seeing the problem ourselves.