-
Notifications
You must be signed in to change notification settings - Fork 2.3k
TypeScript: ElementArrayFinder::filter uses wdpromise
instead of a standard Promise
, breaking backwards compatibility
#4049
Comments
wdpromise
over a standard Promise
wdpromise
instead of a standard Promise
, breaking backwards compatibility
Sorry for the slow response, I've been very busy wrapping things up before I transfer to a new team. Here's the thing: you really should be returning a That said, |
No worries, that's a shocker, I'm sad to see you go! Hope the new team is fun :-) To address the issue you've raised - I don't think using Using standard promises also allows for chaining webdriver and es6 promise-based library calls together (which I don't believe need to be themselves wrapped in webdriver.promises, since a standard promise chained onto a webdriver promise will not be executed until the webdriver one is completed from what I've witnessed). But if I missed anything, please do let me know! :-) On your second point - is there any ticket related to @types/selenium-webdriver publishing the changes you mentioned? Do I understand correctly that they've already been implemented and only need to be published? Thanks! |
I've had issues with native promises wrapped in webdriver promises in the past. From Protractor's point of view, it's best to just have this be a type error for now. The |
I'm not so convinced that sticking with the wdpromise.Promise is not the best course of action. I've raised an issue #4058 which shows that async/await is broken because of this. We've had to force version |
I've pinned Serenity/JS peer dependency on Protractor to 5.0.0 as well, until I have some time to investigate @sjelin's suggestion further. @massimocode - I'm curious, how does the issue affect async/await? |
Indeed, async/await returns a native promise. I want to be clear: A bug I encountered while trying to support You don't have to pin yourself to 5.0.0 to get around this problem - you could just use type casting. But I want to be clear: you are playing with fire here. For instance: els.map(async function clickFooBars(el: ElementFinder): boolean {
if (await el.getAttribute('foo') == 'bar') {
// Because of the native promise generated by async/await, we are now in a separate
// control flow task
el.click();
}
}).each((el) {
expect(el).toHaveBeenClicked(); // Race condition here
}) Obviously that's You could argue that the issue is just that |
Thanks for the link to SeleniumHQ/selenium#3037, @sjelin. That's a very interesting conversation indeed! After further investigation I decided to provide the I think that your observations from SeleniumHQ/selenium#3037 make perfect sense - mixing up sync and async styles can be problematic. However, since in Serenity/JS we chain the scheduling of a native promise, rather than the already started promise, onto a
Thanks for your help, it's been a very useful conversation! |
It's true, Protractor is perhaps a little overly strict here. But if you're using native promises, you should really turn the control flow off. And with the control flow off, |
@sjelin I noticed a missing await in the example code you posted on this comment #4049 (comment) I think you meant to do |
I was looking to move away from protractor and use webdriverjs natively, because after much usage I believe protractor actually causes more pain than it does good. I noticed this: https://github.com/SeleniumHQ/selenium/wiki/WebDriverJs#moving-to-asyncawait It seems as though Webdriver JS will very soon be deprecating the terrible promise manager and asking people to use async/await instead. For that reason, I think the protractor team should not be using webdriver promises in the signatures of methods. This is of course aside from the fact that I already showed how the example code given above trying to show the drawbacks of not using webdriver promises wasn't written correctly. If you're going to use async/await then you should use it, not randomly forget to apply it! |
Any updates on this? Looking for a way to use |
Protractor
5.1.0
File: element.ts:232
Hey @sjelin!
It seems like the change in the signature of the
ElementArrayFinder::filter
introduced in commit 995b1466, breaks some of the more advanced filter functions.Changing the definition of the
filterFn
fromto
or even
should fix the problem.
The problem in more detail.
From what I can see, the signature has changed from:
to
This breaks backwards compatibility and forces any existing
filterFn
s to now return awdpromise.Promise
, rather than a standardPromise
or even better - aPromiseLike
.One example of such
filterFn
, coming from the Serenity/JS code base, could look like this:As you can see, the signature of the
optionsToClick
function above iswhich, even though working perfectly fine with Protractor 5.0.0, no longer works with 5.1.0.
Looking forward to hearing your thoughts!
Best,
Jan
The text was updated successfully, but these errors were encountered: