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

cy.get fails once in a while with "expected undefined to be enabled" #9404

Closed
bukharov opened this issue Dec 1, 2020 · 22 comments
Closed

cy.get fails once in a while with "expected undefined to be enabled" #9404

bukharov opened this issue Dec 1, 2020 · 22 comments

Comments

@bukharov
Copy link

bukharov commented Dec 1, 2020

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)

@bukharov
Copy link
Author

bukharov commented Dec 2, 2020

Another incarnation of this issue, could it be because it happens after visit?

Screen Shot 2020-12-01 at 7 03 26 PM

@OdedSoluto
Copy link

I also experience this issue randomally accross my tests, happened in previous cypress versions when I've enabled route2, now this is enabled by default and I cannot use cypress (v6)

@jennifer-shehane
Copy link
Member

What's the last version you used where this was working correctly? It likely has something to do with the timing of the app where the input disappears after it's queried. We'd need a reproducible example to investigate it fully though.

Can either of you provide a reproducible example? Here are some tips for providing a Short, Self Contained, Correct, Example and our own Troubleshooting Cypress guide.

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Dec 4, 2020
@bukharov
Copy link
Author

bukharov commented Dec 7, 2020

I checked with 4.7.0 and then with 5.6.0 it's fine with both. The main issue is that it doesn’t fail consistently, it works fine roughly 6 out of 10 runs.

@antonyfuentes
Copy link

I'm experiencing exactly the same issue:

Screen Shot 2020-12-28 at 12 00 48

For some reason, cypress doesn't retry finding the element. Instead, it fails with the issue seen above.
I'm currently on Cypress 6.0.1

@bukharov
Copy link
Author

bukharov commented Mar 2, 2021

I can no longer reproduce this with 6.6.0.

@bukharov bukharov closed this as completed Mar 2, 2021
@bukharov bukharov reopened this Apr 8, 2021
@bukharov
Copy link
Author

bukharov commented Apr 8, 2021

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.

@erwindetesters
Copy link

I see this with version 8.3.0.

expected undefined to exist
expected undefined to be visible

This happens when the initial pageload (first paint) is slow

@erwindetesters
Copy link

Does anyone have some pointers on how I can provide the required information that you need in order to look into this?

@jrchongo
Copy link

We are using Cypress 8.3.1. Last week, we migrated from routes to intercepts and began seeing this issue. Like the others mentioned above, reproducing it has been difficult.

@jrchongo
Copy link

Is there anything worth enabling in the debug logs? We're seeing it regularly in our CI pipeline, but I cannot reproduce it locally - even when running the test in a loop 50 times.

@jrchongo
Copy link

jrchongo commented Dec 7, 2021

@jennifer-shehane

It likely has something to do with the timing of the app where the input disappears after it's queried.

Does cypress "hang onto" or keep a record of anything relating to a cy.get()? I'm imagining something like a record of what's already been found in the DOM via a cy.get('.mySelector') so that actions like "type", "click" etc. can be run on the same selector at different points within an it without cypress having to traverse the DOM multiple times?

Could there be a scenario between cy.visits()'s, where Cypress retains knowledge of a selector for a brief moment, allowing cy.get('.mySelector') to think that the selector was found, but by the time actions like "type" or "click" are attempted, it is gone?

Possible Scenario:

  • cy.visit()
  • cy.get('.mySelector').click()
  • cy.visit() a different page
  • Page starts to load
  • cy.get('.mySelector') is attempted, but Cypress still thinks that .mySelector is found because the previous record has not yet been cleared yet
  • Because Cypres thinks '.mySelector' has been found (even if it hasn't loaded yet), a "click" or "type" action on cy.get('mySelector').click() is allowed to proceed resulting in "the subject received was undefined".

@erwindetesters
Copy link

erwindetesters commented Dec 9, 2021

@jrchongo what you are describing is exactly what I was thinking and is also the scenario we see.

In our case

cy.visit()
// some actions
// some assertion(s)
cy.visit()
// some assertions which fails with the error

@meeranharish
Copy link

Any update on this issue or work around. This is a pain!!

@BlaiseBocz
Copy link

I also saw this issue happens randomly in 9.5.0

expected undefined to be true
AssertionError
expected undefined to be true
  59 |         cy.wait('@reqest').then((xhr) => {
  60 |         expect(xhr?.request?.body?.variables?.settings?.reviewQueue).to.be
> 61 |           .true;
     |            ^

as a quick fix I used Test Retries functionality

@SealviewTW
Copy link

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

@dmaicher
Copy link

This also happened a lot to us recently after we added some global cy.intercept('*').as('request'); inside a beforeEach hook.

We now removed this intercept and since then no fails anymore 🤔 🤷‍♂️

@cypress-bot cypress-bot bot added stage: backlog and removed stage: needs information Not enough info to reproduce the issue labels Apr 29, 2022
@rlyttle
Copy link

rlyttle commented May 21, 2022

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.

@AurelienKun
Copy link

We have the same kind of issues here. We tried all Cypress 10.2, 10.4 & 10.5
It randomly fails on headless run especially on electron/firefox using the cypress-included docker image while chaining commands like :
cy.get(SELECTOR).should("exist").and("be.visible")
It seems to appear less when using chrome though.

@olitomas
Copy link

This keeps happening to me after updating to 10.X from 8.X and its driving me absolutely nuts!

This:
cy.url().should('eq', 'http://localhost:8000/');

Returns this:
expected undefined to equal 'http://localhost:8000/'

@sir-dunxalot
Copy link

I get this error message, occasionally, when a previous step or command in the test failed. For me, the solution is not to solve the failing step. Instead, the solution is to identify any other steps failing prior to the one throwing this error message expected undefined to be enabled.

For example, look for the first step highlighted in red in the spec:

image

That might be the culprit.

@BlueWinds
Copy link
Contributor

This should be resolved in Cypress 12 - see #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests