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

XHR aborted within Cypress tests, but not outside of test. #6938

Closed
rajendragola opened this issue Apr 5, 2020 · 7 comments
Closed

XHR aborted within Cypress tests, but not outside of test. #6938

rajendragola opened this issue Apr 5, 2020 · 7 comments
Labels
stage: needs investigating Someone from Cypress needs to look at this stale no activity on this issue for a long period

Comments

@rajendragola
Copy link

CypressError: The network request for this XHR could not be made. Check your console for the reason.

Steps to reproduce:

  1. Browse https://www.myperfectresume.com/

  2. Click on "Build My Resume" button.

  3. Verify https://www.myperfectresume.com/build-resume is opened.

  4. 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
xhrfailMpr
ForcedStuckInUserCreation

@jennifer-shehane
Copy link
Member

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 https://www.myperfectresume.com/?forceRedirect=StuckInUserCreation

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 Cypress

Screen Shot 2020-04-08 at 11 57 38 AM

Inside Cypress

Screen Shot 2020-04-08 at 12 02 35 PM

@jennifer-shehane jennifer-shehane changed the title CypressError: The network request for this XHR could not be made. Check your console for the reason. XHR aborted within Cypress tests, but not outside of test. Apr 8, 2020
@cypress-bot cypress-bot bot added the stage: needs investigating Someone from Cypress needs to look at this label Apr 8, 2020
@ArtMyWeb
Copy link

ArtMyWeb commented May 5, 2021

Any updates on this?
I'm facing the same issue, cypress version is 7.2.0

@whoiskonstantin
Copy link

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}')
  })
})

Aborted:
Screen Shot 2021-07-05 at 11 00 14 PM

Successful:
Screen Shot 2021-07-05 at 10 59 35 PM

@whoiskonstantin
Copy link

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.

@whoiskonstantin
Copy link

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 wait(3000) for now.

@cypress-app-bot
Copy link
Collaborator

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.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label May 17, 2023
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs investigating Someone from Cypress needs to look at this stale no activity on this issue for a long period
Projects
None yet
Development

No branches or pull requests

5 participants