-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
[webdriver]: add checks for execute_script tests recognising promises #13781
[webdriver]: add checks for execute_script tests recognising promises #13781
Conversation
In case of the rejection of a promise a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @christian-bromann for having a look at those steps of Execute Script
. Your contribution is welcome! I added a couple of inline comments you want to have a look at. Also I think it might be ok, to just add those tests into execute.py
directly.
Once all issues have been clarified maybe you also want to add similar tests for Execute Async Script
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for writing these tests! 👍🏻
We have https://bugzilla.mozilla.org/show_bug.cgi?id=1398095 tracking the implementation of this in Gecko, and we are committed to implementing this soon-ish.
Notifying @jleyba of this change, since he added promises to the WebDriver spec in the first place.
@whimboo @andreastt I applied your feedback and realised that Geckodriver is actually already handling rejected promises well as So right now the following tests are failing:
|
Also question: the reason why I initial thought that Geckodriver doesn't handle rejected promises correctly is because I rejected it with a string Running a small test showed that Chrome is still rejecting the promise whatsoever: Promise.reject('hi').then(
() => console.log("a"),
() => console.log("b"))
> "b" So we might want to also return with 500 and whatever was put into the reject method as payload. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing that occurred to me is that we also want to test if awaiting promises internally in a script works:
execute_script("""
await new Promise(…);
// do something else
return "foobar";
""")
This means the wrapping function that WebDriver applies internally needs to be marked as an asynchronous function, but this may not be called out in the specification currently. Perhaps this should be solved in a separate patch as it likely requires prose changes as well.
As @whimboo pointed out, I’d also like you to address changes to the Execute Async Script command.
@christian-bromann In your latest update, making a distinction between delayed and timed out promises is good.
What the spec says is that the rejected value should be placed in a What is not called out in the spec is actually how to serialise the rejected data. For example, how do we know what to conver the Does that answer your question? |
@andreastt I added two more test types to this:
I see the following things need to get spec'ed out:
I would love to create an issue for both in the Webdriver repo if you think that is the right way to move forward. Then I can split this PR up into multiple ones. |
response = execute_script(session, """ | ||
const res = await Promise.resolve('foobar'); | ||
return res; | ||
""") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see a similar test where the promise rejects, to test that the return value isn’t what is being returned. But happy to see a follow-up PR for that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good now, with two caveats:
- Missing test for
data
field in error object. - Test that "foo" isn’t returned in
await Promise.reject(…); return "foo";
.
@christian-bromann Do you want to take on fixing these up as well in follow-up PRs?
Before we can land this, you first need to fix the lints: https://travis-ci.org/web-platform-tests/wpt/jobs/448776034 |
@andreastt I fixed lint error and added a return value to the
|
The error object can contain a
However, it’s definition says it is optional:
So as long as it’s optional there’s nothing we can test here, I guess. |
@christian-bromann Landed your changes, finally! Do you want to have a look at writing promise tests for Execute Async Script? |
@andreastt yes |
I've been come across point 4, 5, 6 and 7 of the
[execute_script](https://w3c.github.io/webdriver/#execute-script)
recognising promises if returned as such and apparently Geckodriver does resolve/reject a promise properly but don't recognise script timeouts for it (see #13781 (comment)). Chromedriver always returns with status code 200 andvalue: {}
.This is my first stab at this and would love to get initial feedback as it seems that drivers behave differently/inconsistent here which can be either a bug in the driver or in the protocol definition.