-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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().contains() does not accept new DOM elements #2640
Comments
I read some time ago a post concerning this, and the author encouraged the use of Can you try with |
I still see the current behavior as an issue, especially because As soon as there is a list of generated items, |
Yep I know, I got to know it through this post... Maybe it is good that this behavior gets documented somewhere in the Docs. |
for me it is quiet confusing that it works with think the cypress docu is not right.. if u take a look at the also |
That's how |
I'm coming across this problem a lot in a SPA when the data isn't ready yet. It means we can't use |
Just came across this - very weird how it doesn't retry with get->contains, but it does if you use contains on its own or get->should contain |
Just for the record - this behavior is documented here: https://docs.cypress.io/guides/core-concepts/retry-ability.html |
This is a major reason for flaky tests as not every developer is fully aware of this behavior. |
But it says "Cypress only retries commands that query the DOM: cy.get()... " and yet we are all here expecting it to retry in the |
@haveaguess Cypress retries the last command with its assertions, not the entire chain. The Retry-ability guide talks a lot about how to merge commands or add an assertion in between to ensure each step finishes when you want it to. |
Thank you, you're absolutely right, and it's an interesting read: https://docs.cypress.io/guides/core-concepts/retry-ability#Only-the-last-command-is-retried |
The usage docs for contains chains
It's quite confusing for the documentation to suggest writing tests in a way that will become flakey for non-obvious reasons. I say non-obvious because Cypress's own documentation obviously anticipates the "retry last command only" behaviour confusing developers, saying things like "weird", "why isn't Cypress finding it? What is going on?", and "for a variety of implementation reasons".. Additionally, other parts of the docs explicitly suggest not using contains as per the usage example above:
Would you be interested in a pull request that updates the documentation for
and/or
Apologies if I've missed something obvious in the docs that makes this clear, but I think it should be mentioned on the contains page. |
I ran into similar situation and my solution is to set a buffer to check the amount of the element first and then use
|
This struck me today. Took 2h's of reading docs, then finding this thread, to get it working. I consider this a weak spot of cypress, not being clear in documented behaviour being the most severe issue, the actual behaviour too being non-intuitive. Expected behaviour (unless very clearly documented): .get should re-query the DOM on every retry, regardless of how many chained calls are postpended to the get call. |
In case if someone wondering, Jan-2023 :) issue still open, so I put a my "5 cents".
Yeah, maybe it's bad because of Yeah. maybe it's related with I dunno. Going to upgrade to v10, maybe there is regression bug (introduced by v9) fixed. I'm on my way to upgrade to Cypress v12... but it's hard journey to do when you are still on v6. |
In our experience, using the
|
This should be improved or resolved completely in Cypress 12 with the introduction of queries and major changes in the way Cypress retries commands. I'm going to close this as resolved; if you're still experiencing similar issues in Cy 12+, please open a new issue or leave a comment here telling me what I've missed! |
@BlueWinds can you elaborate on how this should be fixed in cypress 12+? the changelog does not mention any related changes to the existing selector handling and it does not mention any new query api. |
Current behavior:
cy.get().contains()
is called,.contains()
will only wait for the DOM elements that existed duringcy.get()
. Newly created DOM elements will not be checked against.contains()
..get().contains()
works fine in when there is only one result for the.get()
. But as soon as there is a list of generated items,.get().contains()
is no longer working as previously and race conditions start to occur. The reason is not obvious but this is a reason for tests to become flaky over time.Desired behavior:
cy.get()
should accept new DOM elements while.contains()
has not finished.I expect it to work like
cy.get().should('contain', '...');
.Also the documentation misses the hint of this significant behavior difference.
Steps to reproduce:
HTML
Cypress Test
Result:
The text was updated successfully, but these errors were encountered: