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

Problem cancelling XHRs from previous test #761

Closed
AshMcConnell opened this issue Oct 18, 2017 · 62 comments · Fixed by #2969
Closed

Problem cancelling XHRs from previous test #761

AshMcConnell opened this issue Oct 18, 2017 · 62 comments · Fixed by #2969
Assignees
Milestone

Comments

@AshMcConnell
Copy link

AshMcConnell commented Oct 18, 2017

Current behavior:

Yep, there is an issue if you don't wait for all XHRs to finish after a test. When it tries to cancel the XHR it fails with the error: -

UnsubscriptionError: 1 errors occurred during unsubscription:
  1) TypeError: Cannot set property 'aborted' of undefined

if I do an explicit cy.wait(2000) or cy.wait('@myxhr') it works
note it's the following test that fails, not the one with the XHR

Desired behavior:

The XHR should be cancelled correctly before the next test starts

How to reproduce:

Have a longish running XHR fire at the end of one test and have a subsequent test.

Additional Info (images, stack traces, etc)

It seems to happen when I am faking a route failure (status 500) and then make another (non-faked) XHR (to report the error to a server). e.g.: -

cy.route({
  method: 'PUT',
  url: '/Endpoint/Id',
  status: 500,
  response: ''
}).as('saveStuff');
  • Operating System: Ubuntu 16.04
  • Cypress Version: 1.0.2
  • Browser Version: Electron 53
@brian-mann
Copy link
Member

Related to #686 and almost a duplicate, but I'll leave this open for now until I can confirm it is.

@brian-mann brian-mann self-assigned this Oct 18, 2017
@jennifer-shehane jennifer-shehane added the stage: needs investigating Someone from Cypress needs to look at this label Oct 19, 2017
@Mende
Copy link

Mende commented Nov 3, 2017

Same issue.
Cypress CLI: 0.13.1
Cypress App: 0.19.2
Electron 53
Mac OS X Sierra

@brian-mann
Copy link
Member

We no longer abort XHR's in between tests.

This was actually fixed in 0.20.0 and I forgot to close this issue then.

@brian-mann brian-mann added this to the 0.20.0 milestone Nov 3, 2017
@daniil-g-8sph
Copy link

daniil-g-8sph commented Nov 19, 2017

@brian-mann I still have the problem in 1.0.3 (Chrome 62, Electron 53 in both)

cypress_runner.js:136633 TypeError: Cannot set property 'aborted' of undefined
    at XMLHttpRequest.XHR.abort (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:65539:23)
    at XMLHttpRequest.onReadyStateFn (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:65617:27)
From previous event:
    at run (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:61887:15)
    at Object.cy.(anonymous function) [as visit] (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:62107:11)
    at Context.runnable.fn (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:62238:20)
    at callFn (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32092:21)
    at Test.Runnable.run (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32085:7)
    at https://spb.tele2.ru/__cypress/runner/cypress_runner.js:65090:28
From previous event:
    at Object.onRunnableRun (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:65089:20)
    at $Cypress.action (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:60592:51)
    at Test.Runnable.run (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:64240:20)
    at Runner.runTest (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32555:10)
    at https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32661:12
    at next (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32475:14)
    at https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32485:7
    at next (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32417:14)
    at https://spb.tele2.ru/__cypress/runner/cypress_runner.js:32453:5
    at timeslice (https://spb.tele2.ru/__cypress/runner/cypress_runner.js:27694:27)
logError @ cypress_runner.js:136633

@RandallKent RandallKent reopened this Nov 25, 2017
@TopWebGhost
Copy link

I have the same problem

@wijwoj
Copy link
Contributor

wijwoj commented Dec 18, 2017

I'm getting these errors when calling visit on a new url after running over from one test spec file to the next.

Currently having to do something nasty like:

Cypress.on('uncaught:exception', (err, runnable) => {
    return err.message.indexOf('Cannot set property \'aborted\' of undefined') === -1
});

@tan-nhu
Copy link

tan-nhu commented Jan 17, 2018

I'm facing the same problem with cypress 1.4.1.

@ScottSpittle

This comment has been minimized.

@joshmccure

This comment has been minimized.

@shcallaway
Copy link

shcallaway commented Feb 16, 2018

I am also experiencing this with 1.4.2. I am not making any requests or even repeating cy.visit at the beginning of each test. I also don't see any aborted XHRs in the Cypress sidebar or failed requests in the Chome Dev Tools.

@adrinr
Copy link

adrinr commented Feb 16, 2018

Having the same problem with 1.4.1. Did somebody find some workaround?

@dracos
Copy link

dracos commented Mar 26, 2018

Just to add still happening for us in 2.1.0, we've added an extra cy.visit("/") to make sure whatever was in progress is aborted.

@rafaelchiti
Copy link

rafaelchiti commented Mar 27, 2018

@dracos where did you add the cy.visist("/")? I'm trying all the combinations possible and still having issues. In my case I have pub nub configured in the app. I'm trying to 'disable it' but wondering if this should work out of the box. Just came from TestCafe and this seemed to work just fine, wondering how they handle it. Thanks!!

@dracos
Copy link

dracos commented Mar 28, 2018

@rafaelchiti At the end of the test that caused the next test to fail, went for a 404 in the end. See the cleanUpXHR function in https://github.com/mysociety/fixmystreet/blob/ed6c2501/.cypress/cypress/integration/regressions.js - hope that's helpful.

@mparpaillon
Copy link

@brian-mann If you no longer abort XHRs between tests how come we all still get this error ? I'm using 2.1.0 and I keep having this problem. Thanks

@royston-c
Copy link

@rafaelchiti did you have any success with the PubNub long polling and Cypress? Some of the functionality i want to test is dependent on it so I don't really want to stub it out.

@rafaelchiti
Copy link

mm I managed to get it going but seemed a bit off the stuff I had to do. Let me share the example here. I followed what dracos suggested. Either way I didn't experiment much, after this I switched to Test Cafe (due to other company requirements).

My test would have this:

  beforeEach(() => {
    cy.visit(Cypress.env("yourAppUrl"));
  });

  afterEach(() => {
    cy.cleanUpXHR();
  });

my commands.js

Cypress.Commands.add("cleanUpXHR", function() {
  if (Cypress.env("run_all_suite")) {
    cy.visit(`${Cypress.env("yourAppUrl")}/404`, { failOnStatusCode: false });
  }

my make file for running them:

test-cypress-open:
	cd test/e2e && npx cypress open

test-cypress-run:
	cd test/e2e && npx cypress run --env run_all_suite=true

I only executed the clean up when running the whole suite. When working on 1 test with the visual debugger I didn't want that behavior to kick in, since that visual debugger is sort of meant for working on one test at a time (from what I understand) and not to run multiple tests.
I didn't try but that is the latest I found in my repo I think that was the solution that ended up working.

@StormPooper
Copy link

Also seeing this with 2.10, but the extra page visit after the tests only fixes it most of the time, plus it adds time to each test to visit the extra page.

@pperry-atlassian
Copy link

Same here. Similar to @rafaelchiti and @roy46, our app has long polling requests that will trigger this error on every spec. I didn't have any luck at all with an afterEach hook, so I had to add a command as the last step in every spec to route to a static 404 html page. It slows the suites down since every spec has to reload the page.

@StormPooper
Copy link

Still an issue with 3.0.1 too.

@jennifer-shehane jennifer-shehane removed this from the 0.20.0 milestone Jun 1, 2018
@jechlin
Copy link

jechlin commented Jun 8, 2018

I was getting this too but only on test failures, which made it very hard to debug. In my case it turned out to be through using:

this.retries(1)

in an attempt to get it to retry failing tests once... this is a mocha thing that turned out never worked anyway, but I accidentally left it in. This caused the problem... maybe related upgrading to 3.0.1 but I doubt it.

@amenk
Copy link

amenk commented Dec 6, 2018

@jennifer-shehane How is the status of this, now having a reproducible example?

@jennifer-shehane jennifer-shehane modified the milestones: Sprint 13, Sprint 16 Dec 19, 2018
@jennifer-shehane jennifer-shehane added stage: needs review The PR code is done & tested, needs review and removed stage: ready for work The issue is reproducible and in scope labels Dec 19, 2018
brian-mann added a commit that referenced this issue Dec 19, 2018
@mlc-mlapis
Copy link

mlc-mlapis commented Dec 20, 2018

@brian-mann ... thank you, Brian.

@jennifer-shehane
Copy link
Member

The code for this is done, but this has yet to be released. We'll update this issue and reference the changelog when it's released.

@jennifer-shehane jennifer-shehane added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Dec 20, 2018
@brian-mann
Copy link
Member

Released in 3.1.4.

@tomaass
Copy link

tomaass commented Jan 2, 2019

Hi, I'm using rxjs and redux-obsevables in my app. There was no problem in Cypress 3.1.2 with aborting requests by takeUntil operator from rxjs. But after upgrade to 3.1.4 I sometimes have an error like:

Error: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'json').

I think it's caused by solving this 🐛

@mlc-mlapis
Copy link

@tomaass ... as always ... without a simple reproduction demo, it's hard to guess.

@tomaass
Copy link

tomaass commented Jan 3, 2019

@mlc-mlapis example of aborting request by using rxjs and redux-observables ;-)

const exampleEpic = action$ =>
  action$.ofType(FETCH_ACTION)
    .switchMap(() =>
      Observable.ajax.getJSON('example.url')
        .takeUntil(action$.ofType(ANOTHER_ACTION))
        .map(fetchExampleFulfilled)
  1. If ANOTHER_ACTION comes before a response from a server it aborts the request and an error was thrown.

  2. If another FETCH_ACTION comes before a response from a server it does the same after aborting

@mlc-mlapis
Copy link

@tomaass ... which RxJS version is used here? Because I can't see pipe-able operators.

@jennifer-shehane
Copy link
Member

Hey @tomaass, this is a bug introduced in 3.1.4 - documented here: #3008

@nabby27
Copy link

nabby27 commented Dec 5, 2019

Hey, I can solve it with cy.wait(100) before cy.visit()

@jennifer-shehane
Copy link
Member

This issue will be closed to further comment as the exact issue here was resolved and tested.

If you're experiencing a bug similar to this in Cypress, please open a new issue with a fully reproducible example that we can run. There may be a specific edge case with the issue that we need more detail to fix.

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Jan 2, 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.