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

Commit

Permalink
chore(es7): async/await example
Browse files Browse the repository at this point in the history
  • Loading branch information
sjelin authored and cnishina committed Jul 11, 2016
1 parent 0d8c37d commit 2a391bc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions exampleTypescript/asyncAwait/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.js
8 changes: 8 additions & 0 deletions exampleTypescript/asyncAwait/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
`async`/`await` in Protractor
=============================

`async`/`await` is an 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).
15 changes: 15 additions & 0 deletions exampleTypescript/asyncAwait/conf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Because this file imports from protractor, you'll need to have it as a
// project dependency.
//
// To run this example, run 'npm run tsc -t ES2015' to transpile the typescript
// to javascript. run with 'protractor conf.js'
import {Config} from 'protractor';

export let config: Config = {
framework: 'jasmine',
capabilities: {
browserName: 'chrome'
},
specs: [ 'spec.js' ],
seleniumAddress: 'http://localhost:4444/wd/hub'
};
13 changes: 13 additions & 0 deletions exampleTypescript/asyncAwait/spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Same process for importing and compiling at ../spec.ts, except you need to
// pass the `-t ES2015` flag to `tsc`.
import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor/globals';

describe('async function', function() {
it('should wait on async function in conditional', async function() : Promise<any> {
browser.get('http://www.angularjs.org');
let todoList = element.all(by.repeater('todo in todoList.todos'));
if ((await todoList.count()) > 1) {
expect(todoList.get(1).getText()).toEqual('build an angular app');
}
});
});

0 comments on commit 2a391bc

Please sign in to comment.