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

Commit

Permalink
chore(examples): update async/await example with better info
Browse files Browse the repository at this point in the history
  • Loading branch information
sjelin committed Nov 2, 2016
1 parent d7fa744 commit 21fa642
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
33 changes: 25 additions & 8 deletions exampleTypescript/asyncAwait/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
`async`/`await` in Protractor
=============================

`async`/`await` is a feature that may or may not be added to javascript in
the future. It is currently accessible via typescript if you compile using
`tsc -t ES2015 <files>`. Protractor supports returning a promise at the end of
an `it()` block, so it indirectly supports `async`/`await` (so long as your
programming environment supports it).
`async`/`await` and the Web Driver Control Flow
===============================================

An `async` function returns a promise. Protractor supports returning a promise
from an `it()` block, so this isn't necessarily a problem. The issue is that
the Web Driver control flow only works with the promise implementation given by
the `selenium-webdriver` module. So if you use `async`/`await`, you can no
longer rely on Web Driver to synchronize your commands (see [github issue](
https://github.com/SeleniumHQ/selenium/issues/3037)) for details. In other
words, if you `async`/`await` anywhere in a spec, you should use `await` or
promise chaining to handle all asynchronous activity (e.g. any command
interacting with the browser) for the rest of that test.

In the near future there will be an option to disable the Web Driver control
flow entierly (see https://github.com/angular/protractor/issues/3691). If you
are using `async`/`await`, it is highly recommended that you disable the Web
Driver control flow.


Compiling `async`/`await` syntax
================================

`async`/`await` syntax is currently accessible via typescript if you compile
using `tsc -t ES2015 <files>`. You can also compile it using [regenerator](
https://github.com/facebook/regenerator).
3 changes: 1 addition & 2 deletions exampleTypescript/asyncAwait/spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Same process for importing and compiling at ../spec.ts, except you need to
// pass the `-t ES2015` flag to `tsc`.
// See README.md for important details.
import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor';

describe('async function', function() {
Expand Down

0 comments on commit 21fa642

Please sign in to comment.