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

WaitUntill works only with Cypress methods #241

Closed
JonahKK opened this issue Feb 24, 2021 · 9 comments
Closed

WaitUntill works only with Cypress methods #241

JonahKK opened this issue Feb 24, 2021 · 9 comments

Comments

@JonahKK
Copy link

JonahKK commented Feb 24, 2021

It is more like a question, or a request for clarification. I was not able to find an answer in docs.
So in my case I have a class with method that is responsible for fetching some data from API. This method uses waitUntil and returns a Cypress' promise.
So now in test I want to fetch this data till the returned json will have certain value. In order to do it I wrote:
cy.waitUntil(() => apiClient.get(item.id).then(i => i.items[0].Name === item.items[1].Name));
What happened during execution was Cypress waited indefinitely long for this wait. Timeout was never raised (although time passed).
So in my second attempt I wrapped the whole expression in cy.wrap:
cy.waitUntil(() => cy.wrap(apiClient.get(item.id).then(i => i.items[0].Name === item.items[1].Name)););
In this form, the wait worked flawlessly.
My question is, whether waitUntil is limited only to cy commands, or is it some kind of the defect. Maybe usage of two waitUntil is the issue here?

@NoriSte
Copy link
Owner

NoriSte commented Feb 25, 2021

Hi @JonahKK
Thanks for asking, could you share a minimal repository to play with, please?
Thanks
Stefano

@NoriSte
Copy link
Owner

NoriSte commented Feb 25, 2021

Nested cy.waitUntil calls should work as expected 😉

@NoriSte
Copy link
Owner

NoriSte commented Mar 1, 2021

@JonahKK, up 😉

@JonahKK
Copy link
Author

JonahKK commented Mar 1, 2021

@NoriSte Sorry about the delay, had a lot on my mind recently. I will try to prepare the example this week.

@NoriSte
Copy link
Owner

NoriSte commented Mar 1, 2021

Perfect, thanks!!! I appreciate it 😊

@JonahKK
Copy link
Author

JonahKK commented Mar 3, 2021

I have been experimenting with the different setups, trying to reproduce the exact error I've been describing, yet without luck. Obviously I cannot share code from work.
All I have observed was that waitUntil nested inside of another wait can take a lot of time, before the timeout happens. It might work as expected, yet with default timeouts (5 seconds) it takes over 60 seconds to fail!
image
Maybe I was experiencing this extended wait time, that made me think there is an error - I use bigger timeouts in my production code.

@NoriSte
Copy link
Owner

NoriSte commented Mar 4, 2021

Thanks for the feedback @JonahKK!! 😊

All I have observed was that waitUntil nested inside of another wait can take a lot of time, before the timeout happens. It might work as expected, yet with default timeouts (5 seconds) it takes over 60 seconds to fail!

Could you share a repo with this example, please? I didn't notice it in my tests 🤔

@JonahKK
Copy link
Author

JonahKK commented Mar 4, 2021

Please check the https://github.com/JonahKK/cypress-test-tiny/tree/wait-until. Just open the Cypress runner and launch the spec. The test should timeout after 70 seconds (unless you will be lucky and have a match in the wait 😉)

@NoriSte
Copy link
Owner

NoriSte commented Mar 7, 2021

You're right, I hadn't realized it until now... well, how waitUntil works:

  1. it runs the checkFunction
  2. if the result is falsy, it waits (through cy.wait)
  3. return to step n°1 25 times (by default, it's the result of 5000/200, the default timeout, and the default interval)

Then, what happens when two waitUntil calls are nested

  1. parent: it runs the checkFunction
    1.1. child: it runs the checkFunction
    1.2. child: if the result is falsy, it waits (through cy.wait)
    1.3. child: return to step n°1.1 25 times
  2. parent: if the result is falsy, it waits (through cy.wait)
  3. return to step n°1 25 times

so the parent waitUntil call will retry 25 times (by default) but every time the child waitUntil call runs 25 retries, completely breaking the concept of "time" of the parent call.

I'm going to add this note to the README, thanks a lot for the dedication @JonahKK!!!!!! ❤️

@NoriSte NoriSte closed this as completed in 07c35e1 Mar 7, 2021
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

2 participants