-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Implement new async API #6954
Implement new async API #6954
Conversation
2a30926
to
7b0b5aa
Compare
|
||
function wrapElementFn (promise: Promise<Clients.Browser>, cmd: Function, args: any[], prevInnerArgs?: { prop: string, args: any[] }): any { | ||
return new Proxy( | ||
Promise.resolve(promise).then((ctx: Clients.Browser) => cmd.call(ctx, ...args)), |
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.
Would this work as well? If so, do we need to try/catch this?
Promise.resolve(promise).then((ctx: Clients.Browser) => cmd.call(ctx, ...args)), | |
promise.then((ctx: Clients.Browser) => cmd.call(ctx, ...args)), |
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.
nope, because we don't know if promise
is actually a promise, so to be sure we wrap it this way
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.
Added some comments, great changes to see!
maybe it makes sense to completely get rid of everything related to wdio-sync and implemented Chainable Promise API as the only standard? In case there will appear some way to mimic sync behavior I'd better implement logic for it from scratch. |
@mgrybyk as much as I would like to get rid of it we have the majority of users that use sync mode and also like it. Many probably wouldn't like to rewrite their whole test suite so we will have to stick with it until deprecation of Node v16 |
Sorry to say you are right even though it's easier to maintain single official design. |
Anything I can do to help move this PR forward? Is more testing needed? |
@christian-bromann Good to hear! Let me know if any testing is needed and I'll do my best to help out. |
77adc2e
to
71b4fa0
Compare
Is it possible to access elements array by index instead of |
I don't think so, would that even be possible in general? Given that accessing an index is not calling a function that you can chain I am not sure. This is why this patch proposes a await $('foo').$$('bar').get(2).getTagName() |
@christian-bromann yes, it's possible with |
Cool, let me try that. I definitely prefer using indexes rather than introducing a |
* update API template to add sync depcrecation warning * rewrite API examples * update guide section examples * fix example * fix xpath code * update section * improve design of depcrecation warning * Update website/docs/SyncVsAsync.md Co-authored-by: Erwin Heitzman <15839059+erwinheitzman@users.noreply.github.com> * TypeScript support for new Async API (#7000) * base implementation * define iterator methods * throw error if element index is out of bounds * type improvements * don't use async types for sync def * add typing tests * update deps * fix build * use rimraf to remove node_modules * revert package-lock changes * more type fixes * fix unit tests * revert package-lock changes * fix call command * attempt to get build fixed * just call npm test * try a different approach * fix typings * fix typing test * Async API blog post (#7181) * Blog post with announcement on improved async api * PR feedback * update boilerplate examples (#7192) Co-authored-by: Erwin Heitzman <15839059+erwinheitzman@users.noreply.github.com>
1259ca1
to
d3e4b2f
Compare
Is this fully implemented in 7.9.0?
When using something like:
Maybe I'm using this the wrong way. |
We moved away from the const elem = await $('foo').$$('bar')[0]; |
Proposed changes
In #6702 we've evaluated what is the best path forward after it was clear that fibers support would not continue with Node.js v16 and up. As a first step this patch improves the async API by minimizing the amount of
await
necessary. Today our async API has no support for element chaining, requiring users to do things like that:This patch adds a much nicer handling of these chained calls and allows things as follows:
This change should be backwards compatible as the behavior stays the same when an element promise is resolved before calling a command on it. It will be also possible for users to have sync code with async code mixed, e.g.:
This also simplifies transitioning between both modes.
Types of changes
Checklist
Further comments
This patch requires some more work and I will also add some additional documentation changes to have all code examples be
async
by default with async
option to switch.Reviewers: @webdriverio/project-committers