@@ -59,11 +59,10 @@ export class ProtractorExpectedConditions {
59
59
*
60
60
* @returns {!function } An expected condition that returns the negated value.
61
61
*/
62
- not ( expectedCondition : Function ) : Function {
63
- return ( ) : Function => {
64
- return expectedCondition ( ) . then ( ( bool : boolean ) : boolean => {
65
- return ! bool ;
66
- } ) ;
62
+ not ( expectedCondition : Function ) : ( ( ) => Promise < boolean > ) {
63
+ return async ( ) : Promise < boolean > => {
64
+ const bool = await expectedCondition ( ) ;
65
+ return ! bool ;
67
66
} ;
68
67
}
69
68
@@ -78,20 +77,19 @@ export class ProtractorExpectedConditions {
78
77
* @returns {!function } An expected condition that returns a promise which
79
78
* evaluates to the result of the logical chain.
80
79
*/
81
- logicalChain_ ( defaultRet : boolean , fns : Array < Function > ) : Function {
80
+ logicalChain_ ( defaultRet : boolean , fns : Array < Function > ) : ( ( ) => Promise < boolean > ) {
82
81
let self = this ;
83
- return ( ) : boolean => {
82
+ return async ( ) : Promise < boolean > => {
84
83
if ( fns . length === 0 ) {
85
84
return defaultRet ;
86
85
}
87
- let fn = fns [ 0 ] ;
88
- return fn ( ) . then ( ( bool : boolean ) : boolean => {
89
- if ( bool === defaultRet ) {
90
- return self . logicalChain_ ( defaultRet , fns . slice ( 1 ) ) ( ) ;
91
- } else {
92
- return ! defaultRet ;
93
- }
94
- } ) ;
86
+ const fn = fns [ 0 ] ;
87
+ const bool = await fn ( ) ;
88
+ if ( bool === defaultRet ) {
89
+ return self . logicalChain_ ( defaultRet , fns . slice ( 1 ) ) ( ) ;
90
+ } else {
91
+ return ! defaultRet ;
92
+ }
95
93
} ;
96
94
}
97
95
@@ -113,7 +111,7 @@ export class ProtractorExpectedConditions {
113
111
* @returns {!function } An expected condition that returns a promise which
114
112
* evaluates to the result of the logical and.
115
113
*/
116
- and ( ...args : Function [ ] ) : Function {
114
+ and ( ...args : Function [ ] ) : ( ( ) => Promise < boolean > ) {
117
115
return this . logicalChain_ ( true , args ) ;
118
116
}
119
117
@@ -135,7 +133,7 @@ export class ProtractorExpectedConditions {
135
133
* @returns {!function } An expected condition that returns a promise which
136
134
* evaluates to the result of the logical or.
137
135
*/
138
- or ( ...args : Function [ ] ) : Function {
136
+ or ( ...args : Function [ ] ) : ( ( ) => Promise < boolean > ) {
139
137
return this . logicalChain_ ( false , args ) ;
140
138
}
141
139
@@ -151,20 +149,18 @@ export class ProtractorExpectedConditions {
151
149
* @returns {!function } An expected condition that returns a promise
152
150
* representing whether an alert is present.
153
151
*/
154
- alertIsPresent ( ) : Function {
155
- return ( ) => {
156
- return this . browser . driver . switchTo ( ) . alert ( ) . then (
157
- ( ) :
158
- boolean => {
159
- return true ;
160
- } ,
161
- ( err : any ) => {
162
- if ( err instanceof wderror . NoSuchAlertError ) {
163
- return false ;
164
- } else {
165
- throw err ;
166
- }
167
- } ) ;
152
+ alertIsPresent ( ) : ( ( ) => Promise < boolean > ) {
153
+ return async ( ) : Promise < boolean > => {
154
+ try {
155
+ await this . browser . driver . switchTo ( ) . alert ( ) ;
156
+ return true ;
157
+ } catch ( e ) {
158
+ if ( e instanceof wderror . NoSuchAlertError ) {
159
+ return false ;
160
+ } else {
161
+ throw e ;
162
+ }
163
+ }
168
164
} ;
169
165
}
170
166
@@ -183,7 +179,7 @@ export class ProtractorExpectedConditions {
183
179
* @returns {!function } An expected condition that returns a promise
184
180
* representing whether the element is clickable.
185
181
*/
186
- elementToBeClickable ( elementFinder : ElementFinder ) : Function {
182
+ elementToBeClickable ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
187
183
return this . and ( this . visibilityOf ( elementFinder ) , ( ) => {
188
184
return elementFinder . isEnabled ( ) . then ( passBoolean , falseIfMissing ) ;
189
185
} ) ;
@@ -205,13 +201,16 @@ export class ProtractorExpectedConditions {
205
201
* @returns {!function } An expected condition that returns a promise
206
202
* representing whether the text is present in the element.
207
203
*/
208
- textToBePresentInElement ( elementFinder : ElementFinder , text : string ) : Function {
209
- let hasText = ( ) => {
210
- return elementFinder . getText ( ) . then ( ( actualText : string ) : boolean => {
204
+ textToBePresentInElement ( elementFinder : ElementFinder , text : string ) : ( ( ) => Promise < boolean > ) {
205
+ let hasText = async ( ) => {
206
+ try {
207
+ const actualText = await elementFinder . getText ( ) ;
211
208
// MSEdge does not properly remove newlines, which causes false
212
209
// negatives
213
210
return actualText . replace ( / \r ? \n | \r / g, '' ) . indexOf ( text ) > - 1 ;
214
- } , falseIfMissing ) ;
211
+ } catch ( e ) {
212
+ falseIfMissing ( e ) ;
213
+ }
215
214
} ;
216
215
return this . and ( this . presenceOf ( elementFinder ) , hasText ) ;
217
216
}
@@ -232,11 +231,14 @@ export class ProtractorExpectedConditions {
232
231
* @returns {!function } An expected condition that returns a promise
233
232
* representing whether the text is present in the element's value.
234
233
*/
235
- textToBePresentInElementValue ( elementFinder : ElementFinder , text : string ) : Function {
236
- let hasText = ( ) => {
237
- return elementFinder . getAttribute ( 'value' ) . then ( ( actualText : string ) : boolean => {
234
+ textToBePresentInElementValue ( elementFinder : ElementFinder , text : string ) : ( ( ) => Promise < boolean > ) {
235
+ let hasText = async ( ) => {
236
+ try {
237
+ const actualText = await elementFinder . getAttribute ( 'value' ) ;
238
238
return actualText . indexOf ( text ) > - 1 ;
239
- } , falseIfMissing ) ;
239
+ } catch ( e ) {
240
+ falseIfMissing ( e ) ;
241
+ }
240
242
} ;
241
243
return this . and ( this . presenceOf ( elementFinder ) , hasText ) ;
242
244
}
@@ -256,11 +258,10 @@ export class ProtractorExpectedConditions {
256
258
* @returns {!function } An expected condition that returns a promise
257
259
* representing whether the title contains the string.
258
260
*/
259
- titleContains ( title : string ) : Function {
260
- return ( ) => {
261
- return this . browser . driver . getTitle ( ) . then ( ( actualTitle : string ) : boolean => {
262
- return actualTitle . indexOf ( title ) > - 1 ;
263
- } ) ;
261
+ titleContains ( title : string ) : ( ( ) => Promise < boolean > ) {
262
+ return async ( ) : Promise < boolean > => {
263
+ const actualTitle = await this . browser . driver . getTitle ( ) ;
264
+ return actualTitle . indexOf ( title ) > - 1 ;
264
265
} ;
265
266
}
266
267
@@ -278,12 +279,11 @@ export class ProtractorExpectedConditions {
278
279
* @returns {!function } An expected condition that returns a promise
279
280
* representing whether the title equals the string.
280
281
*/
281
- titleIs ( title : string ) : Function {
282
- return ( ) => {
283
- return this . browser . driver . getTitle ( ) . then ( ( actualTitle : string ) : boolean => {
284
- return actualTitle === title ;
285
- } ) ;
286
- } ;
282
+ titleIs ( title : string ) : ( ( ) => Promise < boolean > ) {
283
+ return async ( ) : Promise < boolean > => {
284
+ const actualTitle = await this . browser . driver . getTitle ( ) ;
285
+ return actualTitle === title ;
286
+ }
287
287
}
288
288
289
289
/**
@@ -301,11 +301,10 @@ export class ProtractorExpectedConditions {
301
301
* @returns {!function } An expected condition that returns a promise
302
302
* representing whether the URL contains the string.
303
303
*/
304
- urlContains ( url : string ) : Function {
305
- return ( ) => {
306
- return this . browser . driver . getCurrentUrl ( ) . then ( ( actualUrl : string ) : boolean => {
307
- return actualUrl . indexOf ( url ) > - 1 ;
308
- } ) ;
304
+ urlContains ( url : string ) : ( ( ) => Promise < boolean > ) {
305
+ return async ( ) : Promise < boolean > => {
306
+ const actualUrl = await this . browser . driver . getCurrentUrl ( ) ;
307
+ return actualUrl . indexOf ( url ) > - 1 ;
309
308
} ;
310
309
}
311
310
@@ -323,11 +322,10 @@ export class ProtractorExpectedConditions {
323
322
* @returns {!function } An expected condition that returns a promise
324
323
* representing whether the url equals the string.
325
324
*/
326
- urlIs ( url : string ) : Function {
327
- return ( ) => {
328
- return this . browser . driver . getCurrentUrl ( ) . then ( ( actualUrl : string ) : boolean => {
329
- return actualUrl === url ;
330
- } ) ;
325
+ urlIs ( url : string ) : ( ( ) => Promise < boolean > ) {
326
+ return async ( ) : Promise < boolean > => {
327
+ const actualUrl = await this . browser . driver . getCurrentUrl ( ) ;
328
+ return actualUrl === url ;
331
329
} ;
332
330
}
333
331
@@ -347,7 +345,7 @@ export class ProtractorExpectedConditions {
347
345
* @returns {!function } An expected condition that returns a promise
348
346
* representing whether the element is present.
349
347
*/
350
- presenceOf ( elementFinder : ElementFinder ) : Function {
348
+ presenceOf ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
351
349
return elementFinder . isPresent . bind ( elementFinder ) ;
352
350
}
353
351
@@ -366,7 +364,7 @@ export class ProtractorExpectedConditions {
366
364
* @returns {!function } An expected condition that returns a promise
367
365
* representing whether the element is stale.
368
366
*/
369
- stalenessOf ( elementFinder : ElementFinder ) : Function {
367
+ stalenessOf ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
370
368
return this . not ( this . presenceOf ( elementFinder ) ) ;
371
369
}
372
370
@@ -388,7 +386,7 @@ export class ProtractorExpectedConditions {
388
386
* @returns {!function } An expected condition that returns a promise
389
387
* representing whether the element is visible.
390
388
*/
391
- visibilityOf ( elementFinder : ElementFinder ) : Function {
389
+ visibilityOf ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
392
390
return this . and ( this . presenceOf ( elementFinder ) , ( ) => {
393
391
return elementFinder . isDisplayed ( ) . then ( passBoolean , falseIfMissing ) ;
394
392
} ) ;
@@ -409,7 +407,7 @@ export class ProtractorExpectedConditions {
409
407
* @returns {!function } An expected condition that returns a promise
410
408
* representing whether the element is invisible.
411
409
*/
412
- invisibilityOf ( elementFinder : ElementFinder ) : Function {
410
+ invisibilityOf ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
413
411
return this . not ( this . visibilityOf ( elementFinder ) ) ;
414
412
}
415
413
@@ -427,7 +425,7 @@ export class ProtractorExpectedConditions {
427
425
* @returns {!function } An expected condition that returns a promise
428
426
* representing whether the element is selected.
429
427
*/
430
- elementToBeSelected ( elementFinder : ElementFinder ) : Function {
428
+ elementToBeSelected ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
431
429
return this . and ( this . presenceOf ( elementFinder ) , ( ) => {
432
430
return elementFinder . isSelected ( ) . then ( passBoolean , falseIfMissing ) ;
433
431
} ) ;
0 commit comments