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

Commit a5c7786

Browse files
committed
chore(docs): Document disabling the control flow
* Added information about `SELENIUM_PROMISE_MANAGER` to `docs/control-flow.md`, including pointing to `/spec/ts/` for examples * Added `docs/async-await.md`, which redirects to `exampleTypescript/asyncAwait/README.md`. * Updated `exampleTypescript/asyncAwait/README.md`, including pointing to `/spec/ts/` for more examples. * Added `docs/typescript.md`, which redirects to `/exampleTypescript/`. * Added information about `@types/jasminewd2` to `exampleTypescript/README.md`. Website updates to come in a future change. Closes #3692.
1 parent dc361ce commit a5c7786

File tree

8 files changed

+52
-22
lines changed

8 files changed

+52
-22
lines changed

docs/async-await.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
`async`/`await`
2+
===============
3+
4+
Please see [our TypeScript examples which use `async`/`await`](/exampleTypescript/asyncAwait/).

docs/control-flow.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ which are managed by a [control flow](https://github.com/SeleniumHQ/selenium/wik
66
and adapted for [Jasmine](http://jasmine.github.io/2.3/introduction.html).
77
A short summary about how Protractor interacts with the control flow is presented below.
88

9+
Disabling the Control Flow
10+
--------------------------
11+
12+
In the future, the control flow is being removed (see
13+
[SeleniumHQ's github issue](https://github.com/SeleniumHQ/selenium/issues/2969)
14+
for details). To disable the control flow in your tests, you can use the
15+
`SELENIUM_PROMISE_MANAGER: false` [config option](/lib/config.ts#L644).
16+
17+
Instead of the control flow, you can synchronize your commands
18+
with promise chaining or the upcoming ES7 feature `async`/`await`. See
19+
[`/spec/ts/`](/spec/ts/) for examples of tests with the control flow disabled.
20+
21+
Because `async`/`await` uses native promises, it will make the Control Flow
22+
unreliable. As such, if you're writing a library or plugin which needs to work
23+
whether or not the Control Flow is enabled, you'll need to handle
24+
synchronization using promise chaining.
925

1026
Promises and the Control Flow
1127
-----------------------------

docs/typescript.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
TypeScript
2+
==========
3+
4+
Please see [our TypeScript examples](/exampleTypescript/).

exampleTypescript/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ export let config: Config = {
6565

6666
## Ambient typings
6767

68-
Protractor also uses ambient types including jasmine and node. These are brought in via the `tsconfig.json` file, which uses npm module resolution to get types from `node_modules/@types`.
68+
Protractor also uses ambient types including jasmine, jasminewd2, and node. These are brought in via the `tsconfig.json` file, which uses npm module resolution to get types from `node_modules/@types`.
6969

70+
If you are using the jasmine framework for your tests, make sure to do:
71+
72+
```
73+
npm install --save-dev @types/jasmine @types/jasminewd2
74+
```
7075

7176
## Compiling your code
7277

exampleTypescript/asyncAwait/README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22
===============================================
33

44
The Web Driver Control Flow is used to synchronize your commands so they reach
5-
the browser in the correct order (see [control-flow.md](
6-
../../docs/control-flow.md) for details). In the future, the control flow is
7-
being removed, however (see [github issue](
8-
https://github.com/SeleniumHQ/selenium/issues/2969) for details). Instead of
9-
the control flow, you can synchronize your commands with promise chaining or the
10-
upcomming ES7 feature `async`/`await`. However, you cannot use a mix of
11-
`async`/`await` and the control flow: `async`/`await` causes the control flow to
12-
become unreliable (see [github issue](
13-
https://github.com/SeleniumHQ/selenium/issues/3037)). So if you `async`/`await`
14-
anywhere in a spec, you should use `await` or promise chaining to handle all
15-
asynchronous activity (e.g. any command interacting with the browser) for the
16-
rest of that test.
17-
18-
In the near future there will be an option to disable the Web Driver control
19-
flow entierly (see https://github.com/angular/protractor/issues/3691). If you
20-
are using `async`/`await`, it is highly recommended that you disable the Web
21-
Driver control flow.
5+
the browser in the correct order (see
6+
[/docs/control-flow.md](/docs/control-flow.md) for details). In the future, the
7+
control flow is being removed (see [SeleniumHQ's github issue](
8+
https://github.com/SeleniumHQ/selenium/issues/2969) for details). Instead of the
9+
control flow, you can synchronize your commands with promise chaining or the
10+
upcoming ES7 feature `async`/`await`.
2211

12+
However, you cannot use a mix of `async`/`await` and the control flow:
13+
`async`/`await` causes the control flow to become unreliable (see
14+
[github issue]( https://github.com/SeleniumHQ/selenium/issues/3037)). So if you
15+
`async`/`await` anywhere in a spec, you should use the
16+
`SELENIUM_PROMISE_MANAGER: false` [config option](/lib/config.ts#L644).
2317

2418
Compiling `async`/`await` syntax
2519
================================
2620

2721
`async`/`await` syntax is currently accessible via typescript if you compile
28-
using `tsc -t ES2015 <files>`. You can also compile it using [regenerator](
22+
using `--target ES2015` or above. You can also compile it using [regenerator](
2923
https://github.com/facebook/regenerator).
24+
25+
26+
More Examples
27+
=============
28+
29+
More examples can be found under [`/spec/ts/`](/../../spec/ts).

exampleTypescript/asyncAwait/conf.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ export let config: Config = {
1111
browserName: 'chrome'
1212
},
1313
specs: [ 'spec.js' ],
14-
seleniumAddress: 'http://localhost:4444/wd/hub'
14+
seleniumAddress: 'http://localhost:4444/wd/hub',
15+
SELENIUM_PROMISE_MANAGER: false
1516
};

exampleTypescript/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"dependencies": {
1313
"@types/jasmine": "^2.5.38",
14+
"@types/jasminewd2": "^2.0.0",
1415
"jasmine": "^2.4.1",
1516
"protractor": "file:../",
1617
"typescript": "~2.0.0"

exampleTypescript/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"sourceMap": false,
77
"declaration": false,
88
"noImplicitAny": false,
9-
"outDir": "tmp",
10-
"types": ["node", "jasmine"]
9+
"outDir": "tmp"
1110
},
1211
"exclude": [
1312
"node_modules",

0 commit comments

Comments
 (0)