Cypress: Cannot read property '_setRequestBody' of undefined

Created on 25 Jun 2020  路  5Comments  路  Source: cypress-io/cypress

Current behavior:

Whenever visiting a page in which the XHR id is protected via Object.defineProperties, cypress throws the following error:

Cannot read property '_setRequestBody' of undefined 

The issue here is that the following code in packages/driver/src/cypress/server.js is trying to override the XHR id with a unique id

add (xhr, attrs = {}) {
    const id = _.uniqueId('xhr')

    _.extend(xhr, attrs)
    xhr.id = id
    xhrs[id] = xhr
    proxies[id] = $XHR.create(xhr)

    return proxies[id]
}

But since the id property is immutable in my environment and is referencing the value of another property, like so

Object.defineProperties(XMLHttpRequest.prototype, {
    "id": {
        get: function() {
            return XMLHttpRequest.prototype._id
        }
    }
})

The result is that the code is not being able to locate the proxy for the request, returning undefined instead, thus, causing the error

proxy._setRequestBody(requestBody)

Desired behavior:

I would expect to be able to parameterise the property I want to be considered as an ID, in a way that I would be able to tell cypress to override the property _id instead of id.

Test code to reproduce

Reproduction is available here https://github.com/fltonii/cypress-test-tiny

pkserver needs investigating

Most helpful comment

Hi All,
I am experiencing the same issue. The UI library by SAP (Fiori Launchpad based on SAPUI5) is overwriting the XHR Id, which unfortunatly makes it impossible to use cypress for end-to-end UI tests for SAP software.
Is there any option to switch to a different attribute name?

See the following code-snipped of the Fiori Launchpad library (as Fiori Launchpad itself is under commercial license i can unfortunatly not provide a running example - but the issue should be pretty clear from the screenshot).
grafik

Regards,
Timo

All 5 comments

we tried to create an example with our environment, but since we use closed-source tools, we can't share it 馃槶

This code has been there for quite a while, so I don't think this was a recently introduced thing.

I can recreate this with the following code:

it("Sample error when XHR id is not available", () => {
  cy.server()
  cy.route("GET", "/api/myService").as("myService");
  cy.visit("https://cy-test-page.uc.r.appspot.com");
  cy.wait("@myService");
  cy.get("#response").should("equal", `{"working":true}`);
});

Hi All,
I am experiencing the same issue. The UI library by SAP (Fiori Launchpad based on SAPUI5) is overwriting the XHR Id, which unfortunatly makes it impossible to use cypress for end-to-end UI tests for SAP software.
Is there any option to switch to a different attribute name?

See the following code-snipped of the Fiori Launchpad library (as Fiori Launchpad itself is under commercial license i can unfortunatly not provide a running example - but the issue should be pretty clear from the screenshot).
grafik

Regards,
Timo

Tagging @jennifer-shehane : any Update on the investigation?

I am having same issue. @jennifer-shehane is there any work around for this ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jennifer-shehane picture jennifer-shehane  路  3Comments

rbung picture rbung  路  3Comments

egucciar picture egucciar  路  3Comments

jennifer-shehane picture jennifer-shehane  路  3Comments

SecondFlight picture SecondFlight  路  3Comments