-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Updated API examples to use async/await #5081
Conversation
* browser.get('https://angularjs.org/'); | ||
* expect(browser.getCurrentUrl()).toBe('https://angularjs.org/'); | ||
* await browser.get('https://angularjs.org/'); | ||
* expect(await browser.getCurrentUrl()).toBe('https://angularjs.org/'); |
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.
Actually, you don't need to add await
into expect when using Jasmine because result comparison performs when promise in expect is already resolved.
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.
In JavaScript world, yes. But in TypeScript latest type definitions for Jasmine would not allow it... Let me see if I can correct type definitions, before changing this.
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.
Ok, thanks for the quick response
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've had a look and it seems that the functionality was available, because Protractor patched Jasmine and it relies on the control flow, which is being removed now. Jasmine itself does not support passing Promise
into expect()
function (even resolved one).
So you'll have to use the form described in this PR or alternatively new expectAsync function.
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.
@devoto13 , thanks for the explanation
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.
@devoto13 is right, jasminewd
was removed in selenium4
branch
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.
Yup, jasminewd
was removed because we are no longer using the control flow (because selenium-webdriver deprecated their control flow). Also if I can get jasmine3.3 to work, we could also write this as:
expectAsync(browser.getCurrentUrl()).toBe('https://angularjs.org');
Could be nifty but I think the way that this is written is great.
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 is awesome! Thank you for doing this.
@cnishina All the API examples provided for async / await use => syntax IE11 doesn't support => syntax. Does it mean that next version of Protractor cannot be used in IE11?. Also i'm converting my code to async / await following the updated examples in this PR. selenium4 branch you are working on is testable? I would like to run my code on any working Protractor branch to see my code is working |
This is fine. The node process that runs Protractor can use the fat arrows. We send client side functions to the browser that are not fat arrows. As long as we do not change the client side scripts to |
Squash merging this. Thanks everyone for the comments and @devoto13 thank you for this PR! |
Fixes #5080