angular/jasminewd

Idea: Overwrite global `Promise` with `webdriver.promise.Promise`

sjelin opened this issue · 1 comments

This would allow for async/await support without breaking the control flow. It would be an option, not the default, and we'd pick a name in the Protractor config that made it obvious that this feature would be risky. Potential pitfalls:

  1. Some other code might try to do the same thing, and I see no way to merge two classes like we do with patched functions (i.e. you can't "call" the original class like you do with functions).
  2. Someone might save the global Promise somewhere before we overwrite it (for example, selenium does this, though this case isn't a problem for us).
  • This would break instanceof tests, though we could patch the webdriver.promise.Promise class to inherit from the global Promise
  • This would break equality tests, though why you might do that I don't know.
  • This could have other unexpected behavior
  1. In the internal implementation of selenium-webdriver, they sometimes use native promises. Presumably, it could cause a problem if they accidentally used webdriver.promise.Promise instead. I don't think this would be a problem though because they're require()'d first and make a point of saving the global Promise to a local variable.
  2. Savvy users might be aware of the difference between webdriver.promise.Promise and the global Promise class, and want to avoid using a webdriver promise for some reason
  3. The webdriver.promise.Promise might behave differently than the global Promise in some unforeseen way
  4. This is hacking and something unexpected could go wrong.
  5. Once async/await are native to JS, it's unclear what this will do.

This experiment worked, but isn't a good idea