cypress: cy.get fails once in a while with "expected undefined to be enabled"

After upgrading to 6.0.1 tests that weren’t flaky became flaky and I believe it’s not an issue with our code.

Current behavior

Screen Shot 2020-12-01 at 6 33 46 PM

Desired behavior

If an element is not found I expect Cypress to fail as it normally does when it cannot find an element. (“Timed out retrying: Expected to find element: input[name=email], but never found it.”) And if an element is found it expect it not to fail 8)

Versions

Cypress 6.x (6.0.0 exhibited the same issue)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 9
  • Comments: 22 (2 by maintainers)

Most upvoted comments

This’s comeback in Cypress 7x (I checked on 7.0.0 and 7.0.1):

Screen Shot 2021-04-08 at 4 23 34 PM

It marks test as flaky, because it passes the second time.

This issue still happens to me in 9.6.0.

I have a loading spinner on page, that appears and disappears as stuff loads on screen, so I wait for the spinner to appear and then disappear, and when waiting for it to disappear the ‘undefined’ problem occurs.

cy.get('.mat-progress-spinner',{timeout: 10000}).filter(':visible',{timeout: 30000}).should('have.length.at.least',1) - works cy.get('.mat-progress-spinner',{timeout: 10000}).filter(':visible',{timeout: 30000}).should('have.length',0) - does not work, and the cy log in test runner says expected undefined to have a length of 0

Interesting enough, it does NOT reach the ‘undefined’ straight away, but waits a bit before reaching the ‘undefined’ log message

Waiting for the element to be visible, working 100% correct all the time

image

Waiting for the element to disappear, it processes for 1-2 seconds

image

And then this is the result while waiting for the element to disappear

image

This should be resolved in Cypress 12 - see https://github.com/cypress-io/cypress/pull/24628 for the big refactor of how subjects are determined and commands chain together / retry.

Sorry it took us so long to get to this - this is pretty fundamental to how Cypress executes commands, retries things, and chains subjects together. #7306 has a ton of discussion around the subject (and around how Cy12 is going to solve it), so I’m going to refer people there and close this one, just to keep things a bit more centralized.

This has been happening intermittently for me for quite a while, always very early in my tests. Forcing a cy.wait(10 * 1000) after loading the webapp doesn’t help (I thought it might be related to the webapp taking too long to load).

I don’t believe it’s related to cy.intercept - though I recently added this, it was happening long before this addition to my tests.

Currently on Cypress v9.6.1.