@@ -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,15 @@ 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 ) :
235
+ ( ( ) => Promise < boolean > ) {
236
+ let hasText = async ( ) => {
237
+ try {
238
+ const actualText = await elementFinder . getAttribute ( 'value' ) ;
238
239
return actualText . indexOf ( text ) > - 1 ;
239
- } , falseIfMissing ) ;
240
+ } catch ( e ) {
241
+ falseIfMissing ( e ) ;
242
+ }
240
243
} ;
241
244
return this . and ( this . presenceOf ( elementFinder ) , hasText ) ;
242
245
}
@@ -256,11 +259,10 @@ export class ProtractorExpectedConditions {
256
259
* @returns {!function } An expected condition that returns a promise
257
260
* representing whether the title contains the string.
258
261
*/
259
- titleContains ( title : string ) : Function {
260
- return ( ) => {
261
- return this . browser . driver . getTitle ( ) . then ( ( actualTitle : string ) : boolean => {
262
- return actualTitle . indexOf ( title ) > - 1 ;
263
- } ) ;
262
+ titleContains ( title : string ) : ( ( ) => Promise < boolean > ) {
263
+ return async ( ) : Promise < boolean > => {
264
+ const actualTitle = await this . browser . driver . getTitle ( ) ;
265
+ return actualTitle . indexOf ( title ) > - 1 ;
264
266
} ;
265
267
}
266
268
@@ -278,12 +280,11 @@ export class ProtractorExpectedConditions {
278
280
* @returns {!function } An expected condition that returns a promise
279
281
* representing whether the title equals the string.
280
282
*/
281
- titleIs ( title : string ) : Function {
282
- return ( ) => {
283
- return this . browser . driver . getTitle ( ) . then ( ( actualTitle : string ) : boolean => {
284
- return actualTitle === title ;
285
- } ) ;
286
- } ;
283
+ titleIs ( title : string ) : ( ( ) => Promise < boolean > ) {
284
+ return async ( ) : Promise < boolean > => {
285
+ const actualTitle = await this . browser . driver . getTitle ( ) ;
286
+ return actualTitle === title ;
287
+ }
287
288
}
288
289
289
290
/**
@@ -301,11 +302,10 @@ export class ProtractorExpectedConditions {
301
302
* @returns {!function } An expected condition that returns a promise
302
303
* representing whether the URL contains the string.
303
304
*/
304
- urlContains ( url : string ) : Function {
305
- return ( ) => {
306
- return this . browser . driver . getCurrentUrl ( ) . then ( ( actualUrl : string ) : boolean => {
307
- return actualUrl . indexOf ( url ) > - 1 ;
308
- } ) ;
305
+ urlContains ( url : string ) : ( ( ) => Promise < boolean > ) {
306
+ return async ( ) : Promise < boolean > => {
307
+ const actualUrl = await this . browser . driver . getCurrentUrl ( ) ;
308
+ return actualUrl . indexOf ( url ) > - 1 ;
309
309
} ;
310
310
}
311
311
@@ -323,11 +323,10 @@ export class ProtractorExpectedConditions {
323
323
* @returns {!function } An expected condition that returns a promise
324
324
* representing whether the url equals the string.
325
325
*/
326
- urlIs ( url : string ) : Function {
327
- return ( ) => {
328
- return this . browser . driver . getCurrentUrl ( ) . then ( ( actualUrl : string ) : boolean => {
329
- return actualUrl === url ;
330
- } ) ;
326
+ urlIs ( url : string ) : ( ( ) => Promise < boolean > ) {
327
+ return async ( ) : Promise < boolean > => {
328
+ const actualUrl = await this . browser . driver . getCurrentUrl ( ) ;
329
+ return actualUrl === url ;
331
330
} ;
332
331
}
333
332
@@ -347,7 +346,7 @@ export class ProtractorExpectedConditions {
347
346
* @returns {!function } An expected condition that returns a promise
348
347
* representing whether the element is present.
349
348
*/
350
- presenceOf ( elementFinder : ElementFinder ) : Function {
349
+ presenceOf ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
351
350
return elementFinder . isPresent . bind ( elementFinder ) ;
352
351
}
353
352
@@ -366,7 +365,7 @@ export class ProtractorExpectedConditions {
366
365
* @returns {!function } An expected condition that returns a promise
367
366
* representing whether the element is stale.
368
367
*/
369
- stalenessOf ( elementFinder : ElementFinder ) : Function {
368
+ stalenessOf ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
370
369
return this . not ( this . presenceOf ( elementFinder ) ) ;
371
370
}
372
371
@@ -388,7 +387,7 @@ export class ProtractorExpectedConditions {
388
387
* @returns {!function } An expected condition that returns a promise
389
388
* representing whether the element is visible.
390
389
*/
391
- visibilityOf ( elementFinder : ElementFinder ) : Function {
390
+ visibilityOf ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
392
391
return this . and ( this . presenceOf ( elementFinder ) , ( ) => {
393
392
return elementFinder . isDisplayed ( ) . then ( passBoolean , falseIfMissing ) ;
394
393
} ) ;
@@ -409,7 +408,7 @@ export class ProtractorExpectedConditions {
409
408
* @returns {!function } An expected condition that returns a promise
410
409
* representing whether the element is invisible.
411
410
*/
412
- invisibilityOf ( elementFinder : ElementFinder ) : Function {
411
+ invisibilityOf ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
413
412
return this . not ( this . visibilityOf ( elementFinder ) ) ;
414
413
}
415
414
@@ -427,7 +426,7 @@ export class ProtractorExpectedConditions {
427
426
* @returns {!function } An expected condition that returns a promise
428
427
* representing whether the element is selected.
429
428
*/
430
- elementToBeSelected ( elementFinder : ElementFinder ) : Function {
429
+ elementToBeSelected ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
431
430
return this . and ( this . presenceOf ( elementFinder ) , ( ) => {
432
431
return elementFinder . isSelected ( ) . then ( passBoolean , falseIfMissing ) ;
433
432
} ) ;
0 commit comments