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
XHR aborted within Cypress tests, but not outside of test. #6938
Comments
The second click for 'Create my resume' is not necessary to show what the application is doing - it is force redirecting back to the main page with url Test code to reproduce: it('test', () => {
cy.server()
cy.route('POST', 'https://perf-accounts.com/accounts/v4/createguestuser').as('createUser')
cy.visit('https://www.myperfectresume.com/');
cy.contains('BUILD MY RESUME').click()
cy.url().should('include', 'build-resume')
cy.wait('@createUser').its('status').should('eq', 200)
}) I'm not sure why this POST is aborting in Cypress and not outside. Outside CypressInside Cypress |
Any updates on this? |
Facing the same issue with 7.6.0. Very strange behavior: I'm building pagination tests and when cypress changes the page there's a request that goes out to fetch data for the new page. That request is aborted 90% of the time and 10% of the times is successful. However, if you just change pages in the browser you can never see an aborted request. All other tests are running smoothly, just the pagination one is breaking. Here's a snippet of the test and some screenshots. describe('Verify if table pagination works correctly', () => {
it('Changes page', () => {
cy.login()
cy.visit('http://localhost:3000/menu/campaigns/ALL')
cy.url().should('eq', 'http://localhost:3000/menu/campaigns/ALL')
cy.contains("Izakaya Kirby")
cy.get('.center-page_count').find('input').clear().type('2{enter}')
})
}) |
Oh so I just noticed something strange about that request. The problem occurs when the initial fetch is delayed. On the aborted screenshot you can see that the response was processed between line 5 and 6, whereas on the successful response it that initial fetch is processed between line 2 and 3. I fixed it by inserting an arbitrary wait of 3 seconds. cy.url().should('eq', 'http://localhost:3000/menu/campaigns/ALL')
cy.wait(3000) // wait until pending requests are resolved.
cy.contains("Izakaya Kirby") Not the most elegant solution but it did work. |
I tried to rewrite it with intercepters and tried waiting for an alias. However the problem persists. cy.intercept({
pathname: '/api/v2/collection-view/campaigns*',
}).as('campaigns')
cy.url().should('eq', 'http://localhost:3000/menu/campaigns/ALL')
cy.wait(@campaigns) // wait until pending campaigns request is resolved.
cy.contains("Izakaya Kirby") Here's the cypress code block from the stack trace which triggers the abort (Line: 159073): XHR.prototype.abort = function (...args) {
// if we already have a readyState of 4
// then do not get the abort stack or
// set the aborted property or call onXhrAbort
// to test this just use a regular XHR
if (this.readyState !== 4) {
server.abortXhr(this); // <- this line invokes the abort.
}
return abort.apply(this, args);
}; I guess I'll have to go with an anti pattern |
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided. |
This issue has been closed due to inactivity. |
CypressError: The network request for this XHR could not be made. Check your console for the reason.
Steps to reproduce:
Browse https://www.myperfectresume.com/
Click on "Build My Resume" button.
Verify https://www.myperfectresume.com/build-resume is opened.
Click on "Create My Resume" button.
Expected Result: Verify it has redirected to https://www.myperfectresume.com/build-resume/experience-level.
Actual Result: XHR post request accounts/v4/createguestuser is ABORTED.
Please find below the snapshot.
Can you please look into this issue?
Versions
Cypress : 4.3.0
Operating System : Windows 8.1
Browser : Electron 80
The text was updated successfully, but these errors were encountered: