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

Commit 1c97c9f

Browse files
authored
chore(example): update example to be async / await (#5202)
1 parent 8e25ef9 commit 1c97c9f

File tree

7 files changed

+1255
-47
lines changed

7 files changed

+1255
-47
lines changed

example/angular_material/conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exports.config = {
1616
'input_spec.js',
1717
'mat_paginator_spec.js'
1818
],
19-
19+
2020
// Disable promise manager because we are going to use async/await
2121
SELENIUM_PROMISE_MANAGER: false,
2222

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
describe('angular-material input component page', function() {
1+
describe('angular-material input component page', () => {
22
const EC = protractor.ExpectedConditions;
33

4-
it('Should change input component value', async() => {
4+
it('Should change input component value', async () => {
55
await browser.get('https://material.angular.io/components/input/examples');
6-
7-
await browser.wait(EC.elementToBeClickable($('.mat-button-wrapper>.mat-icon')), 5000);
8-
6+
7+
await browser.wait(
8+
EC.elementToBeClickable($('.mat-button-wrapper>.mat-icon')), 5000);
9+
910
const emailInputField = $$('.mat-form-field-infix>input').get(1);
10-
1111
await emailInputField.sendKeys('invalid');
12-
13-
expect($('mat-error').isPresent()).toBe(true);
12+
expect(await $('mat-error').isPresent()).toBe(true);
1413
});
1514
});
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
describe('angular-material paginator component page', () => {
22
const EC = protractor.ExpectedConditions;
33

4-
beforeAll(async() => {
5-
await browser.get('https://material.angular.io/components/paginator/examples');
4+
beforeAll(async () => {
5+
await browser.get(
6+
'https://material.angular.io/components/paginator/examples');
67

7-
await browser.wait(EC.elementToBeClickable($('.mat-button-wrapper>.mat-icon')), 5000);
8+
await browser.wait(
9+
EC.elementToBeClickable($('.mat-button-wrapper>.mat-icon')), 5000);
810
});
911

10-
it('Should navigate to next page', async() => {
12+
it('Should navigate to next page', async () => {
1113
await $('button[aria-label=\'Next page\']').click();
12-
13-
await expect($('.mat-paginator-range-label').getAttribute('innerText')).toEqual('11 - 20 of 100');
14+
console.log(await $('.mat-paginator-range-label').getAttribute('innerText'));
15+
expect(await $('.mat-paginator-range-label').getAttribute('innerText'))
16+
.toEqual('11 - 20 of 100');
1417
});
1518

16-
it('Should navigate to previous page', async() => {
19+
it('Should navigate to previous page', async () => {
1720
await $('button[aria-label=\'Previous page\']').click();
18-
19-
await expect($('.mat-paginator-range-label').getAttribute('innerText')).toEqual('1 - 10 of 100');
21+
expect(await $('.mat-paginator-range-label').getAttribute('innerText'))
22+
.toEqual('1 - 10 of 100');
2023
});
2124

22-
it('Should change list length to 5 items per page', async() => {
25+
it('Should change list length to 5 items per page', async () => {
2326
await $('mat-select>div').click();
24-
2527
const fiveItemsOption = $$('mat-option>.mat-option-text').first();
26-
2728
await fiveItemsOption.click();
28-
29-
await expect($('.mat-paginator-range-label').getAttribute('innerText')).toEqual('1 - 5 of 100');
29+
expect(await $('.mat-paginator-range-label').getAttribute('innerText'))
30+
.toEqual('1 - 5 of 100');
3031
});
3132
});

example/conf.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ exports.config = {
1212

1313
// Spec patterns are relative to the current working directory when
1414
// protractor is called.
15-
specs: ['example_spec.js'],
15+
specs: [
16+
'example_spec.js',
17+
'angular_material/input_spec.js',
18+
'angular_material/mat_paginator_spec.js'
19+
20+
],
1621

1722
// Options to be passed to Jasmine.
1823
jasmineNodeOpts: {

example/example_spec.js

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
1-
describe('angularjs homepage', function() {
2-
it('should greet the named user', function() {
3-
browser.get('http://www.angularjs.org');
1+
describe('angularjs homepage', () => {
2+
it('should greet the named user', async () => {
3+
await browser.get('http://www.angularjs.org');
44

5-
element(by.model('yourName')).sendKeys('Julie');
6-
7-
var greeting = element(by.binding('yourName'));
8-
9-
expect(greeting.getText()).toEqual('Hello Julie!');
5+
await element(by.model('yourName')).sendKeys('Julie');
6+
const greeting = element(by.binding('yourName'));
7+
expect(await greeting.getText()).toEqual('Hello Julie!');
108
});
119

12-
describe('todo list', function() {
13-
var todoList;
14-
15-
beforeEach(function() {
16-
browser.get('http://www.angularjs.org');
10+
describe('todo list', () => {
11+
let todoList;
1712

13+
beforeEach(async () => {
14+
await browser.get('http://www.angularjs.org');
1815
todoList = element.all(by.repeater('todo in todoList.todos'));
1916
});
2017

21-
it('should list todos', function() {
22-
expect(todoList.count()).toEqual(2);
23-
expect(todoList.get(1).getText()).toEqual('build an AngularJS app');
18+
it('should list todos', async () => {
19+
expect(await todoList.count()).toEqual(2);
20+
expect(await todoList.get(1).getText()).toEqual('build an AngularJS app');
2421
});
2522

26-
it('should add a todo', function() {
27-
var addTodo = element(by.model('todoList.todoText'));
28-
var addButton = element(by.css('[value="add"]'));
23+
it('should add a todo', async () => {
24+
const addTodo = element(by.model('todoList.todoText'));
25+
const addButton = element(by.css('[value="add"]'));
2926

30-
addTodo.sendKeys('write a protractor test');
31-
addButton.click();
27+
await addTodo.sendKeys('write a protractor test');
28+
await addButton.click();
3229

33-
expect(todoList.count()).toEqual(3);
34-
expect(todoList.get(2).getText()).toEqual('write a protractor test');
30+
expect(await todoList.count()).toEqual(3);
31+
expect(await todoList.get(2).getText())
32+
.toEqual('write a protractor test');
3533
});
3634
});
3735
});

0 commit comments

Comments
 (0)