Cypress: Cannot read property 'ownerDocument' of null

Created on 2 Apr 2020  路  6Comments  路  Source: cypress-io/cypress

Current behavior:

Clicking on a chart element causes the retry to fail.

This is the error:

image

Desired behavior:

The click action should work as expected. The click should select the chart in the following point:

image

Test code to reproduce

context('Actions', () => {

  beforeEach(() => {
    cy.visit('https://demo.spotfire.cloud.tibco.com/spotfire/wp/analysis?file=/Public/Airbnb%20Boston%20Listings')
  })

  it('select chart value', () => {
    cy.wait(6000) // Give time for the chart to render. Ideally, this should wait on the specific HTML element.
    cy.get('div[title="Property Type Distribution"]').parent().parent().parent().click(150, 60) // This click will fail.
  })

})

Second version of code to reproduce that does not rely on cy.wait():

context('Actions', () => {

  beforeEach(() => {
    cy.visit('https://demo.spotfire.cloud.tibco.com/spotfire/wp/analysis?file=/Public/Airbnb%20Boston%20Listings')
  })

  it('select chart value', () => {
    cy.get('div[title="Property Type Distribution"]').as('chartTitle').parent().parent().parent()
      .within(el => {
        cy.get('div.sf-element-canvas-image').invoke('attr', 'sf-busy').should('eq', 'false')
        cy.wrap(el).as('chart').click(150, 60) // This click will fail.
      })
  })

})

Versions

Windows 10, Chrome or Electron, any version.

  "devDependencies": {
    "cypress": "^4.3.0"
  },
bug

All 6 comments

I can recreate this.

Screen Shot 2020-04-06 at 2 06 22 PM

This is throwing from here: https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/dom/document.ts#L34:L34

If you track the stack trace up further - this method is resolving to null, which is being passed along to the other commands.

https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/mouse.js#L548:L548

Screen Shot 2020-04-06 at 3 34 44 PM

The getFirstCommonAncestor basically does not find the current element within their common ancestors - looping through until it gets to curEl.parentNode that is null.

Screen Shot 2020-04-06 at 3 40 21 PM

Probably a similar situation to https://github.com/cypress-io/cypress/pull/6787 and/or https://github.com/cypress-io/cypress/issues/6707 cc @sainthkh

I'll check this out.

@sainthkh You may want to VPN into east coast US because this site loads incredibly slow in Asia.

Thankfully, the site wasn't slow in South Korea. It might be because of the world's fastest Internet South Korea has.

Anyway, I researched the problem and found the cause.

cy.click() command doesn't issue native mouse event, but it only simulates it (#311).

To run that simulation, we check mouseUpPhase and mouseDownPhase:

https://github.com/cypress-io/cypress/blob/069b22b0d55e42ecfcddfc8f1cabf539dac0266d/packages/driver/src/cy/mouse.js#L530-L534

And then, check if the target element of mouseDownPhase exists:

https://github.com/cypress-io/cypress/blob/069b22b0d55e42ecfcddfc8f1cabf539dac0266d/packages/driver/src/cy/mouse.js#L542-L545

This code doesn't consider this case: what if the target element of mouseUpPhase doesn't exist?

That's the cause of the problem in this issue.

When you click an item in the chart, the app tries to make a drag area, div.sf-canvas-drag-cursor. That's the target element of mouseUpPhase because it's right below the mouse pointer.

Screenshot from 2020-04-07 17-39-18

But it doesn't exist any more when getFirstCommonAncestor() starts. That's why getFirstCommonAncestor() loops up to the <html> tag and null.

The solution might be just returning the mouseDownPhase element.

Implementation isn't hard, but I'm asking this just in case to avoid breaking change:

When this code was written, was there a specific case that mouseUpPhase always exists?

The code for this is done in cypress-io/cypress#7010, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

Released in 4.4.1.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v4.4.1, please open a new issue.

Was this page helpful?
0 / 5 - 0 ratings