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

Commit d3e2690

Browse files
committed
chore(example): update the TypeScript example to be async / await
1 parent 20f6a02 commit d3e2690

12 files changed

+50
-140
lines changed

exampleTypescript/.gitignore

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
*.js
1+
plugins.js
2+
spec.js
3+
specPageObjects.js
4+
angularPage.js
5+
*.d.ts
26
node_modules
3-
tmp/
4-
!asyncAwait/*.js
7+
package-lock.json

exampleTypescript/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,21 @@ There are two examples in this directory:
1010

1111
* Simple Protractor example
1212
* Similar to the [github protractor example](https://github.com/angular/protractor/tree/master/example)
13-
* Files `conf.ts` and `spec.ts`
13+
* Files `conf.js` and `spec.ts`
1414
* Page objects example
1515
* Follows the [protractortest.org page objects example](http://www.protractortest.org/#/page-objects)
16-
* Files `confPageObjects.ts`, `specPageObjects.ts`, and `angularPage.ts`
16+
* Files `conf.js`, `specPageObjects.ts`, and `angularPage.ts`
1717

1818
## File organization
1919

2020
```
2121
exampleTypescript/
2222
|- node_modules/ // downloaded node modules
23-
|- tmp/ // compiled javascript output
2423
|
2524
|- .gitignore // since typescript produces javascript, we should not
2625
| // commit javascript to the repo
2726
|- angularPage.ts // page object example
28-
|- confPageObjects.ts // configuration for the page objects example
27+
|- conf.js // configuration file
2928
|- package.json // node dependencies for the project
3029
|- README.md // this file
3130
|- spec.ts // spec for the simple protractor example

exampleTypescript/angularPage.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
// Because this file references protractor, you'll need to have it as a project
2-
// dependency to use 'protractor/globals'. Here is the full list of imports:
2+
// dependency to use 'protractor'. Here is the full list of imports:
33
//
44
// import {browser, element, by, By, $, $$, ExpectedConditions}
5-
// from 'protractor/globals';
5+
// from 'protractor';
66
//
77
import {browser, element, by} from 'protractor';
88

99
export class AngularHomepage {
1010
nameInput = element(by.model('yourName'));
1111
greeting = element(by.binding('yourName'));
1212

13-
get() {
14-
browser.get('http://www.angularjs.org');
13+
async get(): Promise<void> {
14+
await browser.get('http://www.angularjs.org');
1515
}
1616

17-
setName(name: string) {
18-
this.nameInput.sendKeys(name);
17+
async setName(name: string): Promise<void> {
18+
await this.nameInput.sendKeys(name);
1919
}
2020

21-
// getGreeting returns a webdriver.promise.Promise.<string>. For simplicity
22-
// setting the return value to any
23-
getGreeting(): any {
21+
// getGreeting returns a native Promise<string>
22+
async getGreeting(): Promise<string> {
2423
return this.greeting.getText();
2524
}
2625
}

exampleTypescript/asyncAwait/README.md

Lines changed: 0 additions & 34 deletions
This file was deleted.

exampleTypescript/asyncAwait/conf.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

exampleTypescript/asyncAwait/spec.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

exampleTypescript/conf.ts renamed to exampleTypescript/conf.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
// Editors like Microsoft Visual Studio Code will have autocomplete and
77
// description hints.
88
//
9-
// To run this example, first transpile it to javascript with `npm run tsc`,
10-
// then run `protractor conf.js`.
11-
import {Config} from 'protractor';
12-
13-
export let config: Config = {
9+
// To run this example, run `protractor conf.js`.
10+
exports.config = {
1411
framework: 'jasmine',
1512
capabilities: {
1613
browserName: 'chrome'
1714
},
18-
specs: [ 'spec.js' ],
19-
seleniumAddress: 'http://localhost:4444/wd/hub',
15+
specs: [
16+
'spec.js',
17+
'specPageObjects.js'
18+
],
19+
directConnect: true,
2020

2121
// You could set no globals to true to avoid jQuery '$' and protractor '$'
2222
// collisions on the global namespace.

exampleTypescript/confPageObjects.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

exampleTypescript/package.json

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
"author": "",
66
"license": "MIT",
77
"scripts": {
8+
"debug": "node --inspect-brk ./node_modules/.bin/protractor conf.js",
9+
"pretest": "npm run tsc && npm run webdriver-update",
10+
"test": "protractor conf.js",
811
"tsc": "tsc",
9-
"pretest": "npm run tsc",
10-
"test": "protractor tmp/conf.js",
11-
"debug": "node --inspect-brk ./node_modules/.bin/protractor asyncAwait/conf.js"
12+
"webdriver-update": "webdriver-manager update --standalone=false --gecko=false"
1213
},
1314
"dependencies": {
14-
"@types/jasmine": "2.5.41",
15-
"@types/jasminewd2": "^2.0.0",
16-
"jasmine": "^2.4.1",
15+
"@types/jasmine": "^3.3.12",
16+
"jasmine": "^3.3.1",
1717
"protractor": "file:../",
18-
"typescript": "~2.0.0"
18+
"ts-node": "^8.0.3",
19+
"typescript": "^3.4.1"
1920
},
20-
"devDependencies": {
21-
"@types/jasminewd2": "^2.0.0",
22-
"ts-node": "^3.0.2"
23-
}
21+
"devDependencies": {}
2422
}

exampleTypescript/spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
// dependency to use 'protractor/globals'. Here is the full list of imports:
33
//
44
// import {browser, element, by, By, $, $$, ExpectedConditions}
5-
// from 'protractor/globals';
5+
// from 'protractor';
66
//
77
// The jasmine typings are brought in via DefinitelyTyped ambient typings.
88
import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor';
99

1010
describe('protractor with typescript typings', () => {
11-
beforeEach(() => {
12-
browser.get('http://www.angularjs.org');
11+
beforeEach(async () => {
12+
await browser.get('http://www.angularjs.org');
1313
});
1414

15-
it('should greet the named user', () => {
16-
element(by.model('yourName')).sendKeys('Julie');
17-
let greeting = element(by.binding('yourName'));
18-
expect(greeting.getText()).toEqual('Hello Julie!');
15+
it('should greet the named user', async () => {
16+
await element(by.model('yourName')).sendKeys('Julie');
17+
const greeting = element(by.binding('yourName'));
18+
expect(await greeting.getText()).toEqual('Hello Julie!');
1919
});
2020

21-
it('should list todos', function() {
22-
let todoList = element.all(by.repeater('todo in todoList.todos'));
23-
expect(todoList.count()).toEqual(2);
24-
expect(todoList.get(1).getText()).toEqual('build an angular app');
21+
it('should list todos', async () => {
22+
const todoList = element.all(by.repeater('todo in todoList.todos'));
23+
expect(await todoList.count()).toEqual(2);
24+
expect(await todoList.get(1).getText()).toEqual('build an AngularJS app');
2525
});
2626
});

exampleTypescript/specPageObjects.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {AngularHomepage} from './angularPage';
33

44
// The jasmine typings are brought in via DefinitelyTyped ambient typings.
55
describe('angularjs homepage', () => {
6-
it('should greet the named user', () => {
7-
let angularHomepage = new AngularHomepage();
8-
angularHomepage.get();
9-
angularHomepage.setName('Julie');
10-
expect(angularHomepage.getGreeting()).toEqual('Hello Julie!');
6+
it('should greet the named user', async () => {
7+
const angularHomepage = new AngularHomepage();
8+
await angularHomepage.get();
9+
await angularHomepage.setName('Julie');
10+
expect(await angularHomepage.getGreeting()).toEqual('Hello Julie!');
1111
});
1212
});

exampleTypescript/tsconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
"moduleResolution": "node",
66
"inlineSourceMap": true,
77
"declaration": false,
8-
"noImplicitAny": false,
9-
"outDir": "tmp"
8+
"noImplicitAny": false
109
},
1110
"exclude": [
1211
"node_modules",
13-
"asyncAwait",
1412
"plugins.ts"
1513
]
1614
}

0 commit comments

Comments
 (0)