Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Updated API examples to use async/await #5081

Merged
merged 1 commit into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,8 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
* the wrapped webdriver directly.
*
* @example
* 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
Contributor

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.

*
* @param {string} destination Destination URL.
* @param {number=} opt_timeout Number of milliseconds to wait for Angular to
Expand Down Expand Up @@ -894,9 +894,9 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
* Browse to another page using in-page navigation.
*
* @example
* browser.get('http://angular.github.io/protractor/#/tutorial');
* browser.setLocation('api');
* expect(browser.getCurrentUrl())
* await browser.get('http://angular.github.io/protractor/#/tutorial');
* await browser.setLocation('api');
* expect(await browser.getCurrentUrl())
* .toBe('http://angular.github.io/protractor/#/api');
*
* @param {string} url In page URL using the same syntax as $location.url()
Expand All @@ -922,8 +922,8 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
*
* @deprecated Please use `browser.getCurrentUrl()`
* @example
* browser.get('http://angular.github.io/protractor/#/api');
* expect(browser.getLocationAbsUrl())
* await browser.get('http://angular.github.io/protractor/#/api');
* expect(await browser.getLocationAbsUrl())
* .toBe('http://angular.github.io/protractor/#/api');
* @returns {Promise<string>} The current absolute url from
* AngularJS.
Expand Down
Loading