New issue
Advanced search Search tips
Starred by 8 users

Issue metadata

Status: Available
Owner: ----



Sign in to add a comment

executeAsyncScript should promise-call script, and handle rejected promise

Reported by glukki.s...@gmail.com, Apr 24

Issue description

See http://goo.gl/ll2FvQ for common issues.

Issue Description:
executeAsyncScript doesn't execute a `script` within a `new Promise` with a `Promise-call`, as defined in specification. Steps6 and 7 are not implemented properly: https://www.w3.org/TR/webdriver/#h-execute-async-script

As a result, current implementation doesn't take into account rejected promise, returned from `script`.

Source: https://cs.chromium.org/chromium/src/chrome/test/chromedriver/js/execute_async_script.js?sq=package:chromium&l=85-90

Steps to reproduce:
Test function, as in `execute_async_script_test.html`, that will fail, but should pass
```
function testScriptThrowsAsync() {
  resetAsyncScriptInfo();
  var info = getAsyncScriptInfo();
  var script = "return Promise.reject('Catch me if you can!');"

  executeAsyncScript(script, [], true);
  assertEquals(StatusCode.JAVASCRIPT_ERROR, info.result.status);
  executeAsyncScript(script, [], false);
  assertEquals(StatusCode.UNKNOWN_ERROR, info.result.status);
}
```

How this issue could be fixed (just a partial implementation):
```
// Execute Async Script
return new Promise((resolve, reject) => {
  promiseCall(new Function(script), ...(args.concat(resolve)))
    .catch(reject);
})

// Promise-Calling
function promiseCall(f, ...args) {
  try {
    return Promise.resolve(f(...args));
  } catch (e) {
    return Promise.reject(e);
  }
}
```

I may be mistaken, I don't read specs often, but this is my current understanding.
Fix of this issue could drastically help to write tests and handle async errors!
 
Project Member

Comment 1 by johnchen@chromium.org, Apr 25

Cc: kereliuk@chromium.org
kereliuk@chromium.org: Could you take a look at this some time? Thanks.
I could make a PR if this issue was confirmed :)
Owner: kereliuk@chromium.org
Project Member

Comment 4 by kereliuk@chromium.org, Jul 26

Cc: -kereliuk@chromium.org
Owner: ----
Status: Untriaged (was: Unconfirmed)
Project Member

Comment 5 by johnchen@chromium.org, Aug 22

Labels: StandardsCompliance Pri-2
Status: Available (was: Untriaged)
I agree that executeAsyncScript (and executeScript as well) is no spec compliant, and does not properly handle rejected promise.

glukki.s...@gmail.com: Sorry that I wasn't able to look at this earlier. If your offer to make a PR still stands, it will be most welcome. Thanks.

Sign in to add a comment