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

Commit 21fa642

Browse files
committed
chore(examples): update async/await example with better info
1 parent d7fa744 commit 21fa642

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed
+25-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1-
`async`/`await` in Protractor
2-
=============================
3-
4-
`async`/`await` is a feature that may or may not be added to javascript in
5-
the future. It is currently accessible via typescript if you compile using
6-
`tsc -t ES2015 <files>`. Protractor supports returning a promise at the end of
7-
an `it()` block, so it indirectly supports `async`/`await` (so long as your
8-
programming environment supports it).
1+
`async`/`await` and the Web Driver Control Flow
2+
===============================================
3+
4+
An `async` function returns a promise. Protractor supports returning a promise
5+
from an `it()` block, so this isn't necessarily a problem. The issue is that
6+
the Web Driver control flow only works with the promise implementation given by
7+
the `selenium-webdriver` module. So if you use `async`/`await`, you can no
8+
longer rely on Web Driver to synchronize your commands (see [github issue](
9+
https://github.com/SeleniumHQ/selenium/issues/3037)) for details. In other
10+
words, if you `async`/`await` anywhere in a spec, you should use `await` or
11+
promise chaining to handle all asynchronous activity (e.g. any command
12+
interacting with the browser) for the rest of that test.
13+
14+
In the near future there will be an option to disable the Web Driver control
15+
flow entierly (see https://github.com/angular/protractor/issues/3691). If you
16+
are using `async`/`await`, it is highly recommended that you disable the Web
17+
Driver control flow.
18+
19+
20+
Compiling `async`/`await` syntax
21+
================================
22+
23+
`async`/`await` syntax is currently accessible via typescript if you compile
24+
using `tsc -t ES2015 <files>`. You can also compile it using [regenerator](
25+
https://github.com/facebook/regenerator).

exampleTypescript/asyncAwait/spec.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Same process for importing and compiling at ../spec.ts, except you need to
2-
// pass the `-t ES2015` flag to `tsc`.
1+
// See README.md for important details.
32
import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor';
43

54
describe('async function', function() {

0 commit comments

Comments
 (0)