Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit f534964

Browse files
committed
remove sendKeys workaround
1 parent d65eeff commit f534964

File tree

17 files changed

+70
-121
lines changed

17 files changed

+70
-121
lines changed

public/docs/_examples/architecture/e2e-spec.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict'; // necessary for es6 output in node
22

3-
import { browser, element, by } from 'protractor/globals';
3+
import { protractor, browser, element, by } from 'protractor/globals';
44
import { ElementFinder } from 'protractor';
5-
import { sendKeys } from '../protractor-helpers';
65

76
const nameSuffix = 'X';
87

@@ -55,7 +54,7 @@ function heroTests() {
5554

5655
it(`shows updated hero name in details`, async () => {
5756
let input = element.all(by.css('input')).first();
58-
await sendKeys(input, nameSuffix);
57+
input.sendKeys(nameSuffix);
5958
let page = getPageElts();
6059
let hero = await heroFromDetail(page.heroDetail);
6160
let newName = targetHero.name + nameSuffix;
@@ -72,7 +71,7 @@ function salesTaxTests() {
7271

7372
it('shows sales tax', async function () {
7473
let page = getPageElts();
75-
await sendKeys(page.salesTaxAmountInput, '10');
74+
page.salesTaxAmountInput.sendKeys('10', protractor.Key.ENTER);
7675
// Note: due to Dart bug USD is shown instead of $
7776
let re = /The sales tax is (\$|USD)1.00/;
7877
expect(page.salesTaxDetail.getText()).toMatch(re);

public/docs/_examples/cb-a1-a2-quick-reference/e2e-spec.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'; // necessary for es6 output in node
22

33
import { browser, element, by } from 'protractor/globals';
4-
import { sendKeys } from '../protractor-helpers';
54

65
describe('Angular 1 to 2 Quick Reference Tests', function () {
76

@@ -103,15 +102,14 @@ describe('Angular 1 to 2 Quick Reference Tests', function () {
103102
let resultLabel = movieListComp.element(by.css('span > p'));
104103

105104
heroInput.clear().then(function () {
106-
sendKeys(heroInput, heroName || '').then(function () {
107-
expect(resultLabel.getText()).toBe(expectedLabel);
108-
if (heroName) {
109-
expect(favoriteHeroLabel.isDisplayed()).toBe(true);
110-
expect(favoriteHeroLabel.getText()).toContain(heroName);
111-
} else {
112-
expect(favoriteHeroLabel.isDisplayed()).toBe(false);
113-
}
114-
});
105+
heroInput.sendKeys(heroName || '');
106+
expect(resultLabel.getText()).toBe(expectedLabel);
107+
if (heroName) {
108+
expect(favoriteHeroLabel.isDisplayed()).toBe(true);
109+
expect(favoriteHeroLabel.getText()).toContain(heroName);
110+
} else {
111+
expect(favoriteHeroLabel.isDisplayed()).toBe(false);
112+
}
115113
});
116114
}
117115
});

public/docs/_examples/forms/e2e-spec.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { browser, element, by } from 'protractor/globals';
2-
import { appLang, describeIf, sendKeys } from '../protractor-helpers';
2+
import { appLang, describeIf } from '../protractor-helpers';
33

44
describeIf(appLang.appIsTs || appLang.appIsJs, 'Forms Tests', function () {
55

@@ -47,8 +47,7 @@ describeIf(appLang.appIsTs || appLang.appIsJs, 'Forms Tests', function () {
4747
let newValue: string;
4848
let alterEgoEle = element.all(by.css('input[name=alterEgo]')).get(0);
4949
alterEgoEle.getAttribute('value').then(function(value: string) {
50-
// alterEgoEle.sendKeys(test);
51-
sendKeys(alterEgoEle, test);
50+
alterEgoEle.sendKeys(test);
5251
newValue = value + test;
5352
expect(alterEgoEle.getAttribute('value')).toEqual(newValue);
5453
}).then(function() {

public/docs/_examples/hierarchical-dependency-injection/e2e-spec.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { browser, element, by } from 'protractor/globals';
2-
import { sendKeys } from '../protractor-helpers';
32

43
describe('Hierarchical dependency injection', function () {
54

@@ -39,8 +38,7 @@ describe('Hierarchical dependency injection', function () {
3938
let editButtonEle = heroEle.element(by.cssContainingText('button', 'edit'));
4039
editButtonEle.click().then(function() {
4140
let inputEle = heroEle.element(by.css('hero-editor input'));
42-
// return inputEle.sendKeys("foo");
43-
return sendKeys(inputEle, 'foo');
41+
return inputEle.sendKeys('foo');
4442
}).then(function() {
4543
let buttonName = shouldSave ? 'save' : 'cancel';
4644
let buttonEle = heroEle.element(by.cssContainingText('button', buttonName));

public/docs/_examples/homepage-hello-world/e2e-spec.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'; // necessary for es6 output in node
22

33
import { browser, element, by } from 'protractor/globals';
4-
import { sendKeys } from '../protractor-helpers';
54

65
describe('Homepage Hello World', function () {
76

@@ -19,8 +18,7 @@ describe('Homepage Hello World', function () {
1918
let testName = 'Bobby Joe';
2019
let nameEle = element.all(by.css('input')).get(0);
2120
nameEle.getAttribute('value').then(function(value: string) {
22-
// nameEle.sendKeys(testName); // should work but doesn't
23-
sendKeys(nameEle, testName); // utility that does work
21+
nameEle.sendKeys(testName);
2422
let newValue = value + testName; // old input box value + new name
2523
expect(nameEle.getAttribute('value')).toEqual(newValue);
2624
}).then(function() {

public/docs/_examples/lifecycle-hooks/e2e-spec.ts

+13-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'; // necessary for es6 output in node
22

33
import { browser, element, by } from 'protractor/globals';
4-
import { sendKeys } from '../protractor-helpers';
54

65
describe('Lifecycle hooks', function () {
76

@@ -44,18 +43,13 @@ describe('Lifecycle hooks', function () {
4443

4544
expect(titleEle.getText()).toContain('Windstorm can sing');
4645
expect(changeLogEles.count()).toEqual(2, 'should start with 2 messages');
47-
// heroNameInputEle.sendKeys('-foo-').then(function () {
48-
sendKeys(heroNameInputEle, '-foo-').then(function () {
49-
expect(titleEle.getText()).toContain('Windstorm-foo- can sing');
50-
expect(changeLogEles.count()).toEqual(2, 'should still have 2 messages');
51-
// protractor bug with sendKeys means that line below does not work.
52-
// return powerInputEle.sendKeys('-bar-');
53-
return sendKeys(powerInputEle, '-bar-');
54-
}).then(function () {
55-
expect(titleEle.getText()).toContain('Windstorm-foo- can sing-bar-');
56-
// 7 == 2 previously + length of '-bar-'
57-
expect(changeLogEles.count()).toEqual(7, 'should have 7 messages now');
58-
});
46+
heroNameInputEle.sendKeys('-foo-');
47+
expect(titleEle.getText()).toContain('Windstorm-foo- can sing');
48+
expect(changeLogEles.count()).toEqual(2, 'should still have 2 messages');
49+
powerInputEle.sendKeys('-bar-');
50+
expect(titleEle.getText()).toContain('Windstorm-foo- can sing-bar-');
51+
// 7 == 2 previously + length of '-bar-'
52+
expect(changeLogEles.count()).toEqual(7, 'should have 7 messages now');
5953
});
6054

6155
it('should support DoCheck hook', function () {
@@ -72,17 +66,15 @@ describe('Lifecycle hooks', function () {
7266
// 3 messages to start
7367
expect(count).toEqual(3, 'should start with 3 messages');
7468
logCount = count;
75-
// heroNameInputEle.sendKeys('-foo-').then(function () {
76-
return sendKeys(heroNameInputEle, '-foo-');
69+
return heroNameInputEle.sendKeys('-foo-');
7770
}).then(function () {
7871
expect(titleEle.getText()).toContain('Windstorm-foo- can sing');
7972
return changeLogEles.count();
8073
}).then(function(count: number) {
8174
// one more for each keystroke
8275
expect(count).toEqual(logCount + 5, 'should add 5 more messages');
8376
logCount = count;
84-
// return powerInputEle.sendKeys('-bar-');
85-
return sendKeys(powerInputEle, '-bar-');
77+
return powerInputEle.sendKeys('-bar-');
8678
}).then(function () {
8779
expect(titleEle.getText()).toContain('Windstorm-foo- can sing-bar-');
8880
expect(changeLogEles.count()).toEqual(logCount + 6, 'should add 6 more messages');
@@ -102,14 +94,14 @@ describe('Lifecycle hooks', function () {
10294

10395
logEles.count().then(function(count: number) {
10496
logCount = count;
105-
return sendKeys(childViewInputEle, '-test-');
97+
return childViewInputEle.sendKeys('-test-');
10698
}).then(function() {
10799
expect(childViewInputEle.getAttribute('value')).toContain('-test-');
108100
expect(commentEle.isPresent()).toBe(true, 'should have comment because >10 chars');
109101
expect(commentEle.getText()).toContain('long name');
110102
return logEles.count();
111103
}).then(function(count: number) {
112-
expect(logCount + 6).toEqual(count, '6 additional log messages should have been added');
104+
expect(logCount + 5).toEqual(count, '5 additional log messages should have been added');
113105
logCount = count;
114106
return buttonEle.click();
115107
}).then(function() {
@@ -131,7 +123,7 @@ describe('Lifecycle hooks', function () {
131123

132124
logEles.count().then(function(count: number) {
133125
logCount = count;
134-
return sendKeys(childViewInputEle, '-test-');
126+
return childViewInputEle.sendKeys('-test-');
135127
}).then(function() {
136128
expect(childViewInputEle.getAttribute('value')).toContain('-test-');
137129
expect(commentEle.isPresent()).toBe(true, 'should have comment because >10 chars');
@@ -154,7 +146,7 @@ describe('Lifecycle hooks', function () {
154146
let logEles = element.all(by.css('spy-parent h4 ~ div'));
155147
expect(heroEles.count()).toBe(2, 'should have two heroes displayed');
156148
expect(logEles.count()).toBe(2, 'should have two log entries');
157-
sendKeys(inputEle, '-test-').then(function() {
149+
inputEle.sendKeys('-test-').then(function() {
158150
return addHeroButtonEle.click();
159151
}).then(function() {
160152
expect(heroEles.count()).toBe(3, 'should have added one hero');

public/docs/_examples/pipes/e2e-spec.ts

+8-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'; // necessary for es6 output in node
22

33
import { browser, element, by } from 'protractor/globals';
4-
import { sendKeys } from '../protractor-helpers';
54

65
describe('Pipes', function () {
76

@@ -56,12 +55,10 @@ describe('Pipes', function () {
5655
let factorInputEle = eles.get(1);
5756
let outputEle = element(by.css('power-boost-calculator p'));
5857
baseInputEle.clear().then(function() {
59-
return sendKeys(baseInputEle, '7');
60-
}).then(function() {
58+
baseInputEle.sendKeys('7');
6159
return factorInputEle.clear();
6260
}).then(function() {
63-
return sendKeys(factorInputEle, '3');
64-
}).then(function() {
61+
factorInputEle.sendKeys('3');
6562
expect(outputEle.getText()).toContain('343');
6663
});
6764
});
@@ -78,15 +75,10 @@ describe('Pipes', function () {
7875
expect(mutateCheckEle.getAttribute('checked')).toEqual('true', 'should default to mutating array');
7976
expect(flyingHeroesEle.count()).toEqual(2, 'only two of the original heroes can fly');
8077

81-
return sendKeys(nameEle, 'test1\n')
82-
.then(function(){
83-
expect(flyingHeroesEle.count()).toEqual(2, 'no change while mutating array');
84-
return mutateCheckEle.click();
85-
})
86-
.then(function() {
87-
return sendKeys(nameEle, 'test2\n');
88-
})
89-
.then(function() {
78+
nameEle.sendKeys('test1\n');
79+
expect(flyingHeroesEle.count()).toEqual(2, 'no change while mutating array');
80+
mutateCheckEle.click().then(function() {
81+
nameEle.sendKeys('test2\n');
9082
expect(flyingHeroesEle.count()).toEqual(4, 'not mutating; should see both adds');
9183
expect(flyingHeroesEle.get(2).getText()).toContain('test1');
9284
expect(flyingHeroesEle.get(3).getText()).toContain('test2');
@@ -108,10 +100,8 @@ describe('Pipes', function () {
108100
expect(mutateCheckEle.getAttribute('checked')).toEqual('true', 'should default to mutating array');
109101
expect(flyingHeroesEle.count()).toEqual(2, 'only two of the original heroes can fly');
110102

111-
return sendKeys(nameEle, 'test1\n')
112-
.then(function(){
113-
expect(flyingHeroesEle.count()).toEqual(3, 'new flying hero should show in mutating array');
114-
});
103+
nameEle.sendKeys('test1\n');
104+
expect(flyingHeroesEle.count()).toEqual(3, 'new flying hero should show in mutating array');
115105
});
116106

117107
it('should show an async hero message', function () {

public/docs/_examples/protractor-helpers.ts

-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { browser } from 'protractor/globals';
2-
import { ElementFinder } from 'protractor';
32

43
// Hack - remove when protractor4 exports webdriver typings
54
export namespace webdriver {
@@ -33,23 +32,8 @@ export function itIf(cond: boolean, name: string, func: (done: DoneFn) => void):
3332
}
3433
}
3534

36-
// Hack - because of bug with protractor send keys
37-
// Hack - because of bug with send keys
38-
// TODO figure out where webdriver.promise.Promise<void> is
39-
// export function sendKeys(element: ElementFinder, str: string): webdriver.promise.Promise<void> {
40-
export function sendKeys(element: ElementFinder, str: string): any {
41-
return str.split('').reduce(function (promise, char) {
42-
return promise.then(function () {
43-
return element.sendKeys(char);
44-
});
45-
}, element.getAttribute('value'));
46-
// better to create a resolved promise here but ... don't know how with protractor;
47-
}
48-
4935
// Allow changing bootstrap mode to NG1 for upgrade tests
5036
export function setProtractorToNg1Mode(): void {
51-
// TODO ask julie if this is possible/needed in protractor4
52-
// browser.useAllAngular2AppRoots = false;
5337
browser.rootEl = 'body';
5438

5539
let disableNgAnimate = function() {

public/docs/_examples/router/e2e-spec.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { browser, element, by } from 'protractor/globals';
44
import { ElementFinder } from 'protractor';
5-
import { sendKeys } from '../protractor-helpers';
65

76
describe('Router', function () {
87

@@ -98,8 +97,7 @@ describe('Router', function () {
9897
expect(page.heroDetail.isPresent()).toBe(true, 'should be able to see crisis detail');
9998
expect(page.heroDetailTitle.getText()).toContain(heroText);
10099
let inputEle = page.heroDetail.element(by.css('input'));
101-
return sendKeys(inputEle, '-foo');
102-
}).then(function() {
100+
inputEle.sendKeys('-foo');
103101
expect(page.heroDetailTitle.getText()).toContain(heroText + '-foo');
104102
let buttonEle = page.heroDetail.element(by.css('button'));
105103
return buttonEle.click();
@@ -126,8 +124,7 @@ describe('Router', function () {
126124
expect(page.crisisDetail.isPresent()).toBe(true, 'should be able to see crisis detail');
127125
expect(page.crisisDetailTitle.getText()).toContain(crisisText);
128126
let inputEle = page.crisisDetail.element(by.css('input'));
129-
return sendKeys(inputEle, '-foo');
130-
}).then(function () {
127+
inputEle.sendKeys('-foo');
131128
expect(page.crisisDetailTitle.getText()).toContain(crisisText + '-foo');
132129
let buttonEle = page.crisisDetail.element(by.cssContainingText('button', shouldSave ? 'Save' : 'Cancel'));
133130
return buttonEle.click();

public/docs/_examples/server-communication/e2e-spec.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'; // necessary for es6 output in node
22

33
import { browser, element, by } from 'protractor/globals';
4-
import { sendKeys } from '../protractor-helpers';
54

65
describe('Server Communication', function () {
76

@@ -38,7 +37,7 @@ describe('Server Communication', function () {
3837
it('should add a new hero to the list', function () {
3938
expect(heroNameInput).toBeDefined('<input> for hero name must exist');
4039
expect(addButton).toBeDefined('"Add Hero" button must be defined');
41-
sendKeys(heroNameInput, newHeroName);
40+
heroNameInput.sendKeys(newHeroName);
4241
addButton.click().then(function() {
4342
expect(heroTags.count()).toBe(heroCountAfterAdd, 'A new hero should be added');
4443
let newHeroInList = heroTags.get(heroCountAfterAdd - 1).getText();

public/docs/_examples/toh-1/e2e-spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { browser, element, by } from 'protractor/globals';
44
import { ElementFinder } from 'protractor';
5-
import { sendKeys, WPromise } from '../protractor-helpers';
5+
import { WPromise } from '../protractor-helpers';
66

77
const expectedH1 = 'Tour of Heroes';
88
const expectedTitle = `Angular 2 ${expectedH1}`;
@@ -28,7 +28,7 @@ class Hero {
2828
const nameSuffix = 'X';
2929
function addToHeroName(text: string): WPromise<void> {
3030
let input = element(by.css('input'));
31-
return sendKeys(input, text);
31+
input.sendKeys(text);
3232
}
3333

3434
describe('Tutorial part 1', () => {

public/docs/_examples/toh-2/e2e-spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { browser, element, by } from 'protractor/globals';
44
import { ElementFinder } from 'protractor';
5-
import { sendKeys, WPromise } from '../protractor-helpers';
5+
import { WPromise } from '../protractor-helpers';
66

77
const expectedH1 = 'Tour of Heroes';
88
const expectedTitle = `Angular 2 ${expectedH1}`;
@@ -116,7 +116,7 @@ function updateHeroTests() {
116116

117117
function addToHeroName(text: string): WPromise<void> {
118118
let input = element(by.css('input'));
119-
return sendKeys(input, text);
119+
input.sendKeys(text);
120120
}
121121

122122
function expectHeading(hLevel: number, expectedText: string): void {

public/docs/_examples/toh-3/e2e-spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { browser, element, by } from 'protractor/globals';
44
import { ElementFinder } from 'protractor';
5-
import { sendKeys, WPromise } from '../protractor-helpers';
5+
import { WPromise } from '../protractor-helpers';
66

77
const expectedH1 = 'Tour of Heroes';
88
const expectedTitle = `Angular 2 ${expectedH1}`;
@@ -116,7 +116,7 @@ function updateHeroTests() {
116116

117117
function addToHeroName(text: string): WPromise<void> {
118118
let input = element(by.css('input'));
119-
return sendKeys(input, text);
119+
input.sendKeys(text);
120120
}
121121

122122
function expectHeading(hLevel: number, expectedText: string): void {

0 commit comments

Comments
 (0)