Cypress: Frequent InvalidStateError when running tests in 3.1.4 update

Created on 27 Dec 2018  ·  30Comments  ·  Source: cypress-io/cypress

Current behavior:

When running certain tests, I will frequently get an InvalidStateError on tests that worked previously in 3.1.3. Additionally, this does not happen everytime the test is run. Sometimes the test will pass, but many times this error will happen.

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

Desired behavior:

The test should pass without any errors.
Consistent behavior from one test run to another.

Steps to reproduce: (app code and test code)

The below test is on a page that loads a HERE map, and consequently receives many XHR responses upon loading.
Example code of a test case that resulted in this error, but worked in previous Cypress versions.

const Accounts = require('../../constants/accounts');
const Routes = require('../../constants/routes');

describe('Switching organizations, then refreshes the page', () => {
  before(() => {
    cy.viewport('macbook-15');
    cy.visit(Routes().dashboardBaseUrl);
    cy.get('input[name=email]').type(Accounts().email);
    cy.get('input[name=password]')
      .type(Accounts().pw)
      .type('{enter}');
  });

  it('should default back to original organization view upon refresh', () => {
    context('switch from parent organization to child organization', () => {
      cy.get('[data=subscribedName]').should(
        'have.text',
        'organization name'
      );

      //open the dropdown
      cy.get('[data=dropdown-toggle]').click();

      //Click on the first child organization
      cy.get('[data=orgName]:first').click();

      //organization title should have changed
      cy.get('[data=subscribedName]').should(
        'have.text',
        'blacklist'
      );
    });

    cy.reload();
    cy.get('[data=subscribedName]').should(
      'have.text',
      'organization name'
    );
  });
});

Versions 3.1.4

2️⃣ pkdriver regression

Most helpful comment

I've started a PR to fix this, so hopefully should get out in 3.1.5 https://github.com/cypress-io/cypress/pull/3054

All 30 comments

Hey @Dan195, does this happen during cypress open, cypress run, or both?
Could you also specify OS/browser being used?

I open cypress with cypress open and run the tests by clicking on them or using "Run all specs". This is run on MacOS with Chrome.

Do you have a screenshot of the command log that you could provide? Also any console logs/stack traces from the console dev tools may be helpful.

A reproducible example would be the most ideal thing to provide, but more logging information will at least be better than none.

Is there a way I can send this privately?

Yes. Email [email protected]

I am having the same issue - running the tests inside docker, with cypress run command

Same here. I'm getting Error: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'arraybuffer'). when running inside docker with cypress run --spec=cypress/tests/visual/*.test.js --browser chrome.

Docker base image: cypress/browsers:chrome69

Yes. Email [email protected]

Sent just now.

Experiencing the same issue across multiple test suites, only started happening recently (after the 26th December).

Thanks so much everyone for providing details of this regression!

I've created a repo demonstrated this bug: https://github.com/jennifer-shehane/array-buffer-bug

It seems this error throws when there are XHR requests of responseType arraybuffer that are aborted. This also makes sense since we made several changes to how we handle aborted requests in 3.1.4.

Basic example within repo:

<!DOCTYPE html>
<html>
  <head>
    <title>Array Buffer</title>
  </head>
  <body>
    <h1 class="page-title">Array Buffer Check</h1>
    <script type="text/javascript">
      (function () {
        var xhr = new XMLHttpRequest()
        xhr.responseType = 'arraybuffer'
        xhr.open('get', '/fake/data')
        xhr.send()
        xhr.abort()
      }())
    </script>
  </body>
</html>
it('throws error on aborted request with type arraybuffer', () => {
  cy.visit('index.html')
})

Screenshot
screen shot 2019-01-03 at 3 36 34 pm

Problematic code is here - this should check that the responseType is '' or 'text' before checking responseText. https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cypress/server.coffee#L34

Experiencing the same issue.
When you guys are planning to fix this?

We have a similar error since the 3.1.4 update

Error: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'blob').
    at isAbortedThroughUnload (http://localhost:9999/__cypress/runner/cypress_runner.js:62461:57)
    at onReadyStateFn (http://localhost:9999/__cypress/runner/cypress_runner.js:62816:17)
    at XMLHttpRequest.<anonymous> (http://localhost:9999/__cypress/runner/cypress_runner.js:62773:25)

The difference is text' (was 'blob') instead of arraybuffer

Tests fail when running cypress run with Electron 59. The tests do run successful with cypress open running Chrome 71 but fail with the above message with cypress open running Electron 59

I've started a PR to fix this, so hopefully should get out in 3.1.5 https://github.com/cypress-io/cypress/pull/3054

I have also been hit by this issue, thanks for fixing it.

Hey guys!
I'm also getting this error randomly on cypress run or cypress open.
My XHR requests have JSON bodies however. Same error otherwise.

Hopefully 3.1.5 is released soon!

Hey Guyz!

Am also facing the same issue.
When i can expect 3.1.5 release with this fix?

Same here. Spent a whole day debugging...

Hi @jennifer-shehane,

We are waiting for 3.1.5 release.
When will 3.1.5 be released ?
Will it be released by end on this month ?

Would 3.1.5 also fix the text' (was 'blob') issue?

I've also seen similar fails since upgrading to 3.1.4, however mine "was Json":

Error: Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'json').
at isAbortedThroughUnload (http://localhost:3020/__cypress/runner/cypress_runner.js:64608:57)
at onReadyStateFn (http://localhost:3020/__cypress/runner/cypress_runner.js:64963:17)
at XMLHttpRequest.<anonymous> (http://localhost:3020/__cypress/runner/cypress_runner.js:64920:25)

Seems related, is anyone else able to confirm if the fixes in 3.1.5 will also resolve this?

I am having the same issue with "json" response

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 pulled down the issue-branch and built it locally. We had the (was ’blob’) which was solved.

Looking at the changes in the fix-branch, it looks like every (was ’xxx’) will be covered.

Thanks a bunch @jennifer-shehane 🎉

Any plans to release the fix?

Released in 3.1.5.

I have the same situation -> "cypress": "^4.0.1". using cypres run and open.

    cy.server()
     cy.route('GET', 'api/dic').as('dic')
     cy.visit('/')
     cy.wait('@dic').then((xhr) => {
               expect(xhr).to.have.property('status', 200)
           })

and error

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

@kamiloski I have the same issue after upgrading to Cypress 4.0.1.

@pchorus workaround

        cy.wait(['@dictionary').then((xhr) => {
            expect(xhr.status).to.eq(200)
        })

@jennifer-shehane I too have just run into this issue after 4.0.1 update

cy.route({ method: 'GET', url: `**?name=${filterText}` }).as(aliases.typeaheadLookupRequest);

...

cy.waitAlias(aliases.typeaheadLookupRequest).should('have.property', 'status', 200);

image

the fix is @kamiloski's workround

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.

Was this page helpful?
0 / 5 - 0 ratings