File tree 2 files changed +35
-5
lines changed
2 files changed +35
-5
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ Features
15
15
16
16
- If a ` done ` function is passed to the test, waits for both the control flow and until done is called.
17
17
18
+ - If a test returns a promise, waits for both the the control flow and the promise to resolve.
19
+
18
20
- Enhances ` expect ` so that it automatically unwraps promises before performing the assertion.
19
21
20
22
Installation
@@ -58,3 +60,13 @@ describe('tests with webdriver', function() {
58
60
});
59
61
})
60
62
```
63
+
64
+ ` async ` functions / ` await `
65
+ ---------------------------
66
+
67
+ ` async ` functions and the ` await ` keyword are likely coming in ES7, and
68
+ available via several compilers. At the moment, they often break the WebDriver
69
+ control flow.
70
+ ([ GitHub issue] ( https://github.com/SeleniumHQ/selenium/issues/3037 ) ). You can
71
+ still use them, but if you do then you will have to use ` await ` /Promises for
72
+ almost all your synchronization. See ` spec/asyncAwaitSpec.ts ` for details.
Original file line number Diff line number Diff line change
1
+ /* Here we have an example of using async/await with jasminewd. We are using
2
+ * typescript to gain access to async/await, but mostly this should look like
3
+ * normal javascript to you.
4
+ *
5
+ * The key thing to note here is that once you use async/await, the webdriver
6
+ * control flow is no longer reliable. This means you have to use async/await
7
+ * or promises for all your asynchronous behavior. In Protractor this would
8
+ * mean putting `await` before every line interacting with the browser. In this
9
+ * example, we have to put `await` before `driver.sleep()`.
10
+ */
1
11
"use strict" ;
2
12
13
+ // Declare globals
3
14
declare var describe ;
4
15
declare var it ;
5
16
declare var expect ;
17
+ declare var require ;
6
18
7
- async function asyncHelper ( ) {
8
- return 7 ;
9
- }
19
+ let driver = require ( './common.js' ) . getFakeDriver ( ) ;
10
20
11
21
describe ( 'async function' , function ( ) {
22
+ let sharedVal : any ;
12
23
it ( 'should wait on async functions' , async function ( ) {
13
- let helperVal = await asyncHelper ( ) ;
14
- expect ( helperVal ) . toBe ( 7 ) ;
24
+ sharedVal = await driver . getValueA ( ) ; // Async unwraps this to 'a'
25
+ expect ( sharedVal ) . toBe ( 'a' ) ;
26
+ await driver . sleep ( 1000 ) ; // Normally you wouldn't need to `await` this, but
27
+ // the control flow is broken for async functions.
28
+ sharedVal = await driver . getValueB ( ) ;
29
+ } ) ;
30
+
31
+ it ( 'should have waited until the end of the last it() block' , function ( ) {
32
+ expect ( sharedVal ) . toBe ( 'b' ) ;
15
33
} ) ;
16
34
} ) ;
You can’t perform that action at this time.
0 commit comments