@@ -59,11 +59,10 @@ export class ProtractorExpectedConditions {
5959 *
6060 * @returns {!function } An expected condition that returns the negated value.
6161 */
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 ;
6766 } ;
6867 }
6968
@@ -78,20 +77,19 @@ export class ProtractorExpectedConditions {
7877 * @returns {!function } An expected condition that returns a promise which
7978 * evaluates to the result of the logical chain.
8079 */
81- logicalChain_ ( defaultRet : boolean , fns : Array < Function > ) : Function {
80+ logicalChain_ ( defaultRet : boolean , fns : Array < Function > ) : ( ( ) => Promise < boolean > ) {
8281 let self = this ;
83- return ( ) : boolean => {
82+ return async ( ) : Promise < boolean > => {
8483 if ( fns . length === 0 ) {
8584 return defaultRet ;
8685 }
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+ }
9593 } ;
9694 }
9795
@@ -113,7 +111,7 @@ export class ProtractorExpectedConditions {
113111 * @returns {!function } An expected condition that returns a promise which
114112 * evaluates to the result of the logical and.
115113 */
116- and ( ...args : Function [ ] ) : Function {
114+ and ( ...args : Function [ ] ) : ( ( ) => Promise < boolean > ) {
117115 return this . logicalChain_ ( true , args ) ;
118116 }
119117
@@ -135,7 +133,7 @@ export class ProtractorExpectedConditions {
135133 * @returns {!function } An expected condition that returns a promise which
136134 * evaluates to the result of the logical or.
137135 */
138- or ( ...args : Function [ ] ) : Function {
136+ or ( ...args : Function [ ] ) : ( ( ) => Promise < boolean > ) {
139137 return this . logicalChain_ ( false , args ) ;
140138 }
141139
@@ -151,20 +149,18 @@ export class ProtractorExpectedConditions {
151149 * @returns {!function } An expected condition that returns a promise
152150 * representing whether an alert is present.
153151 */
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+ }
168164 } ;
169165 }
170166
@@ -183,7 +179,7 @@ export class ProtractorExpectedConditions {
183179 * @returns {!function } An expected condition that returns a promise
184180 * representing whether the element is clickable.
185181 */
186- elementToBeClickable ( elementFinder : ElementFinder ) : Function {
182+ elementToBeClickable ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
187183 return this . and ( this . visibilityOf ( elementFinder ) , ( ) => {
188184 return elementFinder . isEnabled ( ) . then ( passBoolean , falseIfMissing ) ;
189185 } ) ;
@@ -205,13 +201,16 @@ export class ProtractorExpectedConditions {
205201 * @returns {!function } An expected condition that returns a promise
206202 * representing whether the text is present in the element.
207203 */
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 ( ) ;
211208 // MSEdge does not properly remove newlines, which causes false
212209 // negatives
213210 return actualText . replace ( / \r ? \n | \r / g, '' ) . indexOf ( text ) > - 1 ;
214- } , falseIfMissing ) ;
211+ } catch ( e ) {
212+ return falseIfMissing ( e ) ;
213+ }
215214 } ;
216215 return this . and ( this . presenceOf ( elementFinder ) , hasText ) ;
217216 }
@@ -232,11 +231,15 @@ export class ProtractorExpectedConditions {
232231 * @returns {!function } An expected condition that returns a promise
233232 * representing whether the text is present in the element's value.
234233 */
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' ) ;
238239 return actualText . indexOf ( text ) > - 1 ;
239- } , falseIfMissing ) ;
240+ } catch ( e ) {
241+ return falseIfMissing ( e ) ;
242+ }
240243 } ;
241244 return this . and ( this . presenceOf ( elementFinder ) , hasText ) ;
242245 }
@@ -256,11 +259,10 @@ export class ProtractorExpectedConditions {
256259 * @returns {!function } An expected condition that returns a promise
257260 * representing whether the title contains the string.
258261 */
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 ;
264266 } ;
265267 }
266268
@@ -278,11 +280,10 @@ export class ProtractorExpectedConditions {
278280 * @returns {!function } An expected condition that returns a promise
279281 * representing whether the title equals the string.
280282 */
281- titleIs ( title : string ) : Function {
282- return ( ) => {
283- return this . browser . driver . getTitle ( ) . then ( ( actualTitle : string ) : boolean => {
284- return actualTitle === title ;
285- } ) ;
283+ titleIs ( title : string ) : ( ( ) => Promise < boolean > ) {
284+ return async ( ) : Promise < boolean > => {
285+ const actualTitle = await this . browser . driver . getTitle ( ) ;
286+ return actualTitle === title ;
286287 } ;
287288 }
288289
@@ -301,11 +302,10 @@ export class ProtractorExpectedConditions {
301302 * @returns {!function } An expected condition that returns a promise
302303 * representing whether the URL contains the string.
303304 */
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 ;
309309 } ;
310310 }
311311
@@ -323,11 +323,10 @@ export class ProtractorExpectedConditions {
323323 * @returns {!function } An expected condition that returns a promise
324324 * representing whether the url equals the string.
325325 */
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 ;
331330 } ;
332331 }
333332
@@ -347,7 +346,7 @@ export class ProtractorExpectedConditions {
347346 * @returns {!function } An expected condition that returns a promise
348347 * representing whether the element is present.
349348 */
350- presenceOf ( elementFinder : ElementFinder ) : Function {
349+ presenceOf ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
351350 return elementFinder . isPresent . bind ( elementFinder ) ;
352351 }
353352
@@ -366,7 +365,7 @@ export class ProtractorExpectedConditions {
366365 * @returns {!function } An expected condition that returns a promise
367366 * representing whether the element is stale.
368367 */
369- stalenessOf ( elementFinder : ElementFinder ) : Function {
368+ stalenessOf ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
370369 return this . not ( this . presenceOf ( elementFinder ) ) ;
371370 }
372371
@@ -388,7 +387,7 @@ export class ProtractorExpectedConditions {
388387 * @returns {!function } An expected condition that returns a promise
389388 * representing whether the element is visible.
390389 */
391- visibilityOf ( elementFinder : ElementFinder ) : Function {
390+ visibilityOf ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
392391 return this . and ( this . presenceOf ( elementFinder ) , ( ) => {
393392 return elementFinder . isDisplayed ( ) . then ( passBoolean , falseIfMissing ) ;
394393 } ) ;
@@ -409,7 +408,7 @@ export class ProtractorExpectedConditions {
409408 * @returns {!function } An expected condition that returns a promise
410409 * representing whether the element is invisible.
411410 */
412- invisibilityOf ( elementFinder : ElementFinder ) : Function {
411+ invisibilityOf ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
413412 return this . not ( this . visibilityOf ( elementFinder ) ) ;
414413 }
415414
@@ -427,7 +426,7 @@ export class ProtractorExpectedConditions {
427426 * @returns {!function } An expected condition that returns a promise
428427 * representing whether the element is selected.
429428 */
430- elementToBeSelected ( elementFinder : ElementFinder ) : Function {
429+ elementToBeSelected ( elementFinder : ElementFinder ) : ( ( ) => Promise < boolean > ) {
431430 return this . and ( this . presenceOf ( elementFinder ) , ( ) => {
432431 return elementFinder . isSelected ( ) . then ( passBoolean , falseIfMissing ) ;
433432 } ) ;
0 commit comments