|
1 | 1 | // Based off of spec/basic/elements_spec.js
|
2 | 2 | import * as q from 'q';
|
3 | 3 |
|
4 |
| -import {$, $$, browser, by, By, element, ElementArrayFinder, ElementFinder, ExpectedConditions, promise as ppromise, WebElement} from '../../..'; |
| 4 | +import {$, browser, by, element, ElementArrayFinder, ElementFinder, promise as ppromise, WebElement} from '../../..'; |
5 | 5 |
|
6 |
| -describe('ElementFinder', function() { |
7 |
| - it('should return the same result as browser.findElement', async function() { |
| 6 | +describe('ElementFinder', () => { |
| 7 | + it('should return the same result as browser.findElement', async() => { |
8 | 8 | await browser.get('index.html#/form');
|
9 | 9 | const nameByElement = element(by.binding('username'));
|
10 | 10 |
|
11 |
| - await expect(nameByElement.getText()) |
12 |
| - .toEqual(browser.findElement(by.binding('username')).getText()); |
| 11 | + expect(await nameByElement.getText()) |
| 12 | + .toEqual(await browser.findElement(by.binding('username')).getText()); |
13 | 13 | });
|
14 | 14 |
|
15 |
| - it('should wait to grab the WebElement until a method is called', async function() { |
| 15 | + it('should wait to grab the WebElement until a method is called', async() => { |
16 | 16 | // These should throw no error before a page is loaded.
|
17 | 17 | const usernameInput = element(by.model('username'));
|
18 | 18 | const name = element(by.binding('username'));
|
19 | 19 |
|
20 | 20 | await browser.get('index.html#/form');
|
21 | 21 |
|
22 |
| - await expect(name.getText()).toEqual('Anon'); |
| 22 | + expect(await name.getText()).toEqual('Anon'); |
23 | 23 |
|
24 | 24 | await usernameInput.clear();
|
25 | 25 | await usernameInput.sendKeys('Jane');
|
26 |
| - await expect(name.getText()).toEqual('Jane'); |
| 26 | + expect(await name.getText()).toEqual('Jane'); |
27 | 27 | });
|
28 | 28 |
|
29 |
| - it('should chain element actions', async function() { |
| 29 | + it('should chain element actions', async() => { |
30 | 30 | await browser.get('index.html#/form');
|
31 | 31 |
|
32 | 32 | const usernameInput = element(by.model('username'));
|
33 | 33 | const name = element(by.binding('username'));
|
34 | 34 |
|
35 |
| - await expect(name.getText()).toEqual('Anon'); |
| 35 | + expect(await name.getText()).toEqual('Anon'); |
36 | 36 |
|
37 | 37 | await((usernameInput.clear() as any) as ElementFinder).sendKeys('Jane');
|
38 |
| - await expect(name.getText()).toEqual('Jane'); |
| 38 | + expect(await name.getText()).toEqual('Jane'); |
39 | 39 | });
|
40 | 40 |
|
41 |
| - it('should run chained element actions in sequence', function(done: any) { |
| 41 | + it('should run chained element actions in sequence', async(done: any) => { |
42 | 42 | // Testing private methods is bad :(
|
43 | 43 | let els = new ElementArrayFinder(browser, () => {
|
44 |
| - return ppromise.when([null as WebElement]); |
| 44 | + return Promise.resolve([null as WebElement]); |
45 | 45 | });
|
46 | 46 | let applyAction_: (actionFn: (value: WebElement, index: number, array: WebElement[]) => any) =>
|
47 | 47 | ElementArrayFinder = (ElementArrayFinder as any).prototype.applyAction_;
|
48 | 48 | let order: string[] = [];
|
49 | 49 |
|
50 |
| - let deferredA = q.defer<void>(); |
| 50 | + let deferredA: Promise<void>; |
51 | 51 | els = applyAction_.call(els, () => {
|
52 |
| - return deferredA.promise.then(() => { |
| 52 | + deferredA = new Promise<void>(resolve => { |
53 | 53 | order.push('a');
|
| 54 | + resolve(); |
54 | 55 | });
|
55 | 56 | });
|
56 |
| - let deferredB = q.defer<void>(); |
| 57 | + let deferredB: Promise<void>; |
57 | 58 | els = applyAction_.call(els, () => {
|
58 |
| - return deferredB.promise.then(() => { |
| 59 | + deferredB = new Promise<void>(resolve => { |
59 | 60 | order.push('b');
|
| 61 | + resolve(); |
60 | 62 | });
|
61 | 63 | });
|
62 | 64 |
|
63 |
| - deferredB.resolve(); |
| 65 | + await deferredB; |
64 | 66 | setTimeout(async function() {
|
65 |
| - deferredA.resolve(); |
| 67 | + await deferredA; |
66 | 68 | await els;
|
67 | 69 | expect(order).toEqual(['a', 'b']);
|
68 | 70 | done();
|
69 | 71 | }, 100);
|
70 | 72 | });
|
71 | 73 |
|
72 |
| - it('chained call should wait to grab the WebElement until a method is called', async function() { |
| 74 | + it('chained call should wait to grab the WebElement until a method is called', |
| 75 | + async() => { |
73 | 76 | // These should throw no error before a page is loaded.
|
74 |
| - const reused = element(by.id('baz')).element(by.binding('item.reusedBinding')); |
| 77 | + const reused = element(by.id('baz')) |
| 78 | + .element(by.binding('item.reusedBinding')); |
75 | 79 |
|
76 | 80 | await browser.get('index.html#/conflict');
|
77 | 81 |
|
78 |
| - await expect(reused.getText()).toEqual('Inner: inner'); |
79 |
| - await expect(reused.isPresent()).toBe(true); |
| 82 | + expect(await reused.getText()).toEqual('Inner: inner'); |
| 83 | + expect(await reused.isPresent()).toBe(true); |
80 | 84 | });
|
81 | 85 |
|
82 |
| - it('should differentiate elements with the same binding by chaining', async function() { |
| 86 | + it('should differentiate elements with the same binding by chaining', |
| 87 | + async() => { |
83 | 88 | await browser.get('index.html#/conflict');
|
84 | 89 |
|
85 | 90 | const outerReused = element(by.binding('item.reusedBinding'));
|
86 | 91 | const innerReused = element(by.id('baz')).element(by.binding('item.reusedBinding'));
|
87 | 92 |
|
88 |
| - await expect(outerReused.getText()).toEqual('Outer: outer'); |
89 |
| - await expect(innerReused.getText()).toEqual('Inner: inner'); |
| 93 | + expect(await outerReused.getText()).toEqual('Outer: outer'); |
| 94 | + expect(await innerReused.getText()).toEqual('Inner: inner'); |
90 | 95 | });
|
91 | 96 |
|
92 |
| - it('should chain deeper than 2', async function() { |
| 97 | + it('should chain deeper than 2', async() => { |
93 | 98 | // These should throw no error before a page is loaded.
|
94 |
| - const reused = |
95 |
| - element(by.css('body')).element(by.id('baz')).element(by.binding('item.reusedBinding')); |
| 99 | + const reused = element(by.css('body')).element(by.id('baz')) |
| 100 | + .element(by.binding('item.reusedBinding')); |
96 | 101 |
|
97 | 102 | await browser.get('index.html#/conflict');
|
98 | 103 |
|
99 |
| - await expect(reused.getText()).toEqual('Inner: inner'); |
| 104 | + expect(await reused.getText()).toEqual('Inner: inner'); |
100 | 105 | });
|
101 | 106 |
|
102 |
| - it('should allow handling errors', async function() { |
| 107 | + it('should allow handling errors', async() => { |
103 | 108 | await browser.get('index.html#/form');
|
104 | 109 | try {
|
105 | 110 | await $('.nopenopenope').getText();
|
106 | 111 |
|
107 | 112 | // The above line should have throw an error. Fail.
|
108 |
| - await expect(true).toEqual(false); |
| 113 | + expect(true).toEqual(false); |
109 | 114 | } catch (e) {
|
110 |
| - await expect(true).toEqual(true); |
| 115 | + expect(true).toEqual(true); |
111 | 116 | }
|
112 | 117 | });
|
113 | 118 |
|
114 |
| - it('should allow handling chained errors', async function() { |
| 119 | + it('should allow handling chained errors', async() => { |
115 | 120 | await browser.get('index.html#/form');
|
116 | 121 | try {
|
117 | 122 | await $('.nopenopenope').$('furthernope').getText();
|
118 | 123 |
|
119 | 124 | // The above line should have throw an error. Fail.
|
120 |
| - await expect(true).toEqual(false); |
| 125 | + expect(true).toEqual(false); |
121 | 126 | } catch (e) {
|
122 |
| - await expect(true).toEqual(true); |
| 127 | + expect(true).toEqual(true); |
123 | 128 | }
|
124 | 129 | });
|
125 | 130 |
|
126 |
| - it('should keep a reference to the original locator', async function() { |
| 131 | + it('should keep a reference to the original locator', async() => { |
127 | 132 | await browser.get('index.html#/form');
|
128 | 133 |
|
129 | 134 | const byCss = by.css('body');
|
130 | 135 | const byBinding = by.binding('greet');
|
131 | 136 |
|
132 |
| - await expect(element(byCss).locator()).toEqual(byCss); |
133 |
| - await expect(element(byBinding).locator()).toEqual(byBinding); |
| 137 | + expect(await element(byCss).locator()).toEqual(byCss); |
| 138 | + expect(await element(byBinding).locator()).toEqual(byBinding); |
134 | 139 | });
|
135 | 140 |
|
136 |
| - it('should propagate exceptions', async function() { |
| 141 | + it('should propagate exceptions', async() => { |
137 | 142 | await browser.get('index.html#/form');
|
138 | 143 |
|
139 | 144 | const invalidElement = element(by.binding('INVALID'));
|
140 | 145 | const successful = invalidElement.getText().then(
|
141 | 146 | function() {
|
142 | 147 | return true;
|
143 |
| - } as any as (() => ppromise.Promise<void>), |
| 148 | + } as any as (() => Promise<boolean>), |
144 | 149 | function() {
|
145 | 150 | return false;
|
146 |
| - } as any as (() => ppromise.Promise<void>)); |
147 |
| - await expect(successful).toEqual(false); |
| 151 | + } as any as (() => Promise<boolean>)); |
| 152 | + expect(await successful).toEqual(false); |
148 | 153 | });
|
149 | 154 |
|
150 |
| - it('should be returned from a helper without infinite loops', async function() { |
| 155 | + it('should be returned from a helper without infinite loops', async() => { |
151 | 156 | await browser.get('index.html#/form');
|
152 |
| - const helperPromise = ppromise.when(true).then(function() { |
| 157 | + const helperPromise = Promise.resolve(true).then(() => { |
153 | 158 | return element(by.binding('greeting'));
|
154 | 159 | });
|
155 | 160 |
|
156 |
| - await helperPromise.then(async function(finalResult: ElementFinder) { |
157 |
| - await expect(finalResult.getText()).toEqual('Hiya'); |
158 |
| - } as any as (() => ppromise.Promise<void>)); |
| 161 | + await helperPromise.then(async(finalResult: ElementFinder) => { |
| 162 | + expect(await finalResult.getText()).toEqual('Hiya'); |
| 163 | + }); |
159 | 164 | });
|
160 | 165 |
|
161 |
| - it('should be usable in WebDriver functions', async function() { |
| 166 | + it('should be usable in WebDriver functions', async() => { |
162 | 167 | await browser.get('index.html#/form');
|
163 | 168 | const greeting = element(by.binding('greeting'));
|
164 | 169 | await browser.executeScript('arguments[0].scrollIntoView', greeting);
|
165 | 170 | });
|
166 | 171 |
|
167 |
| - it('should allow null as success handler', async function() { |
| 172 | + it('should allow null as success handler', async() => { |
168 | 173 | await browser.get('index.html#/form');
|
169 | 174 |
|
170 | 175 | const name = element(by.binding('username'));
|
171 | 176 |
|
172 |
| - await expect(name.getText()).toEqual('Anon'); |
173 |
| - await expect(name.getText().then(null, function() {})).toEqual('Anon'); |
| 177 | + expect(await name.getText()).toEqual('Anon'); |
| 178 | + expect(await name.getText().then(null, function() {})).toEqual('Anon'); |
174 | 179 |
|
175 | 180 | });
|
176 | 181 |
|
177 |
| - it('should check equality correctly', async function() { |
| 182 | + it('should check equality correctly', async() => { |
178 | 183 | await browser.get('index.html#/form');
|
179 | 184 |
|
180 | 185 | const usernameInput = element(by.model('username'));
|
181 | 186 | const name = element(by.binding('username'));
|
182 | 187 |
|
183 |
| - await expect(usernameInput.equals(usernameInput)).toEqual(true); |
184 |
| - await expect(usernameInput.equals(name)).toEqual(false); |
| 188 | + expect(await usernameInput.equals(usernameInput)).toEqual(true); |
| 189 | + expect(await usernameInput.equals(name)).toEqual(false); |
185 | 190 | });
|
186 | 191 | });
|
0 commit comments