Skip to content
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

Updated API examples to use async/await #5081

Merged
merged 1 commit into from
Dec 17, 2018

Conversation

devoto13
Copy link
Contributor

@devoto13 devoto13 commented Dec 6, 2018

Fixes #5080

* 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/');
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

@devoto13 devoto13 Dec 11, 2018

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.

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Member

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.

Copy link
Member

@cnishina cnishina left a 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.

@vsravuri
Copy link

@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

@cnishina
Copy link
Member

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 => we should be okay.

@cnishina
Copy link
Member

Squash merging this. Thanks everyone for the comments and @devoto13 thank you for this PR!

@cnishina cnishina merged commit 4b4e9a9 into angular:selenium4 Dec 17, 2018
cnishina pushed a commit to cnishina/protractor that referenced this pull request Dec 19, 2018
cnishina pushed a commit to cnishina/protractor that referenced this pull request Mar 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants