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
Why should browser.waitUntil continue to wait if promise has been fulfilled or rejected? #2361
Comments
Have you tried to use the |
Thanks @christian-bromann , this is doing exactly what I needed! I'm still confused why |
No. We use waitUntil internally for all the waitFor commands. And they make use of promises. |
No concerns from me about internal use, but "is |
waitUntil supports promises, it just continues waiting if a promise was rejected, right? |
Yes - I just can't personally see how that would be the desired behavior for an external consumer. It also continues waiting if the promise was fulfilled with a falsey value. |
So to be clear, you think that it would be better if waitUntil would error out if the returned promises is rejected. If so, I can definitely see use cases where a promise is rejected and someone wants to use waitUntil to retry until it gets fulfilled. |
That use case makes sense for a function, which can potentially return a different value on any call. But promises, once settled, will never change value. It doesn't seem to make sense to continue waiting. https://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects
|
Ahh I think now I understand. I don't think waitUntil should be used with just a promise as a condition. I can't recollect what my initial intention was when I put |
The problem
I'm writing some tests that require making a call to an API and waiting for the call to finish before continuing with the test.
browser.waitUntil(condition)
seemed like a good utility to use, but I'm having some trouble understanding why it behaves the way it does whencondition
is a promise.Environment
Details
Current behavior seems to be as follows:
condition
resolves to a truthy value,waitUntil
stops waiting.condition
resolves to a falsey value, or rejects with any value,waitUntil
times out withWaitUntilTimeoutError
.API documentation describes this behavior correctly.
If
condition
is a plain function, re-checking it everyinterval
until it is either truthy or times out makes perfect sense. However, promises, once resolved, cannot be resolved again and cannot change value. I'm having a lot of trouble understanding why someone would want the test to continue to wait until the timeout is reached when the outcome of the promise is known.Proposal:
condition
resolves to a truthy value,waitUntil
stops waiting.condition
resolves to a falsey value, or rejects with any value,waitUntil
throws an error (probably notWaitUntilTimeoutError
anymore).This still feels a little strange, since when working with promises, you're usually more concerned with resolved vs. rejected than truthy vs. falsey. An alternative that would be more intuitive, but might be too big of a change, would be:
condition
resolves,waitUntil
stops waiting.condition
rejects,waitUntil
throws an error (probably notWaitUntilTimeoutError
anymore).Maybe
browser.waitUntil
is the wrong utility to use - I'm happy to consider alternative ways to synchronously wait for a promise to resolve before continuing with a test.Link to Selenium/WebdriverIO logs
N/A
Code To Reproduce Issue [ Good To Have ]
First test passes, remaining tests fail:
https://gist.github.com/jochakovsky/65cea6612f210705d470224a4da2a718
The text was updated successfully, but these errors were encountered: