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

Commit 2a391bc

Browse files
sjelincnishina
authored andcommitted
chore(es7): async/await example
1 parent 0d8c37d commit 2a391bc

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.js
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
`async`/`await` in Protractor
2+
=============================
3+
4+
`async`/`await` is an 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).

exampleTypescript/asyncAwait/conf.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Because this file imports from protractor, you'll need to have it as a
2+
// project dependency.
3+
//
4+
// To run this example, run 'npm run tsc -t ES2015' to transpile the typescript
5+
// to javascript. run with 'protractor conf.js'
6+
import {Config} from 'protractor';
7+
8+
export let config: Config = {
9+
framework: 'jasmine',
10+
capabilities: {
11+
browserName: 'chrome'
12+
},
13+
specs: [ 'spec.js' ],
14+
seleniumAddress: 'http://localhost:4444/wd/hub'
15+
};

exampleTypescript/asyncAwait/spec.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Same process for importing and compiling at ../spec.ts, except you need to
2+
// pass the `-t ES2015` flag to `tsc`.
3+
import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor/globals';
4+
5+
describe('async function', function() {
6+
it('should wait on async function in conditional', async function() : Promise<any> {
7+
browser.get('http://www.angularjs.org');
8+
let todoList = element.all(by.repeater('todo in todoList.todos'));
9+
if ((await todoList.count()) > 1) {
10+
expect(todoList.get(1).getText()).toEqual('build an angular app');
11+
}
12+
});
13+
});

0 commit comments

Comments
 (0)