@@ -193,24 +193,18 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
193
193
* this method is called use the new app root. Pass nothing to get a promise that
194
194
* resolves to the value of the selector.
195
195
*
196
- * @param {string|webdriver.promise.Promise<string> } value The new selector.
196
+ * @param {string|webdriver.promise.Promise<string> } valuePromise The new selector.
197
197
* @returns A promise that resolves with the value of the selector.
198
198
*/
199
- angularAppRoot ( value : string | wdpromise . Promise < string > = null ) : wdpromise . Promise < string > {
200
- return this . driver . controlFlow ( ) . execute ( ( ) => {
201
- if ( value != null ) {
202
- return wdpromise . when ( value ) . then ( ( value : string ) => {
203
- this . internalRootEl = value ;
204
- if ( this . bpClient ) {
205
- const bpCommandPromise = this . bpClient . setWaitParams ( value ) ;
206
- // Convert to webdriver promise as best as possible
207
- return wdpromise . when ( bpCommandPromise as any ) . then ( ( ) => this . internalRootEl ) ;
208
- }
209
- return this . internalRootEl ;
210
- } ) ;
199
+ async angularAppRoot ( valuePromise : string | wdpromise . Promise < string > = null ) : Promise < string > {
200
+ if ( valuePromise != null ) {
201
+ const value = await Promise . resolve ( valuePromise ) ;
202
+ this . internalRootEl = value ;
203
+ if ( this . bpClient ) {
204
+ await this . bpClient . setWaitParams ( value ) ;
211
205
}
212
- return wdpromise . when ( this . internalRootEl ) ;
213
- } , `Set angular root selector to ${ value } ` ) ;
206
+ }
207
+ return this . internalRootEl ;
214
208
}
215
209
216
210
/**
@@ -417,23 +411,17 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
417
411
* Call waitForAngularEnabled() without passing a value to read the current
418
412
* state without changing it.
419
413
*/
420
- waitForAngularEnabled ( enabled : boolean | wdpromise . Promise < boolean > = null ) :
421
- wdpromise . Promise < boolean > {
422
- if ( enabled != null ) {
423
- const ret = this . driver . controlFlow ( ) . execute ( ( ) => {
424
- return wdpromise . when ( enabled ) . then ( ( enabled : boolean ) => {
425
- if ( this . bpClient ) {
426
- logger . debug ( 'Setting waitForAngular' + ! enabled ) ;
427
- const bpCommandPromise = this . bpClient . setWaitEnabled ( enabled ) ;
428
- // Convert to webdriver promise as best as possible
429
- return wdpromise . when ( bpCommandPromise as any ) . then ( ( ) => enabled ) ;
430
- }
431
- } ) ;
432
- } , `Set proxy synchronization enabled to ${ enabled } ` ) ;
414
+ async waitForAngularEnabled ( enabledPromise : boolean | wdpromise . Promise < boolean > = null ) :
415
+ Promise < boolean > {
416
+ if ( enabledPromise != null ) {
417
+ const enabled = await Promise . resolve ( enabledPromise ) ;
418
+ if ( this . bpClient ) {
419
+ logger . debug ( 'Setting waitForAngular' + ! enabled ) ;
420
+ await this . bpClient . setWaitEnabled ( enabled ) ;
421
+ }
433
422
this . internalIgnoreSynchronization = ! enabled ;
434
- return ret ;
435
423
}
436
- return wdpromise . when ( ! this . ignoreSynchronization ) ;
424
+ return ! this . ignoreSynchronization ;
437
425
}
438
426
439
427
/**
@@ -602,15 +590,15 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
602
590
* @template T
603
591
*/
604
592
private executeAsyncScript_ ( script : string | Function , description : string , ...scriptArgs : any [ ] ) :
605
- wdpromise . Promise < any > {
593
+ Promise < any > {
606
594
if ( typeof script === 'function' ) {
607
595
script = 'return (' + script + ').apply(null, arguments);' ;
608
596
}
609
597
return this . driver . schedule (
610
- new Command ( CommandName . EXECUTE_ASYNC_SCRIPT )
611
- . setParameter ( 'script' , script )
612
- . setParameter ( 'args' , scriptArgs ) ,
613
- description ) ;
598
+ new Command ( CommandName . EXECUTE_ASYNC_SCRIPT )
599
+ . setParameter ( 'script' , script )
600
+ . setParameter ( 'args' , scriptArgs ) ,
601
+ description ) as Promise < any > ;
614
602
}
615
603
616
604
/**
@@ -624,26 +612,20 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
624
612
* @returns {!webdriver.promise.Promise } A promise that will resolve to the
625
613
* scripts return value.
626
614
*/
627
- waitForAngular ( opt_description ?: string ) : wdpromise . Promise < any > {
615
+ async waitForAngular ( opt_description ?: string ) : Promise < any > {
628
616
let description = opt_description ? ' - ' + opt_description : '' ;
629
617
if ( this . ignoreSynchronization ) {
630
- return this . driver . controlFlow ( ) . execute ( ( ) => {
631
- return true ;
632
- } , 'Ignore Synchronization Protractor.waitForAngular()' ) ;
618
+ return Promise . resolve ( true ) ;
633
619
}
634
620
635
- let runWaitForAngularScript : ( ) => wdpromise . Promise < any > = ( ) => {
621
+ let runWaitForAngularScript = async ( ) : Promise < any > => {
636
622
if ( this . plugins_ . skipAngularStability ( ) || this . bpClient ) {
637
- return this . driver . controlFlow ( ) . execute ( ( ) => {
638
- return wdpromise . when ( null ) ;
639
- } , 'bpClient or plugin stability override' ) ;
623
+ return Promise . resolve ( null ) ;
640
624
} else {
641
625
// Need to wrap this so that we read rootEl in the control flow, not synchronously.
642
- return this . angularAppRoot ( ) . then ( ( rootEl : string ) => {
643
- return this . executeAsyncScript_ (
644
- clientSideScripts . waitForAngular , 'Protractor.waitForAngular()' + description ,
645
- rootEl ) ;
646
- } ) ;
626
+ let rootEl = await this . angularAppRoot ( ) ;
627
+ return this . executeAsyncScript_ (
628
+ clientSideScripts . waitForAngular , 'Protractor.waitForAngular()' + description , rootEl ) ;
647
629
}
648
630
} ;
649
631
@@ -656,20 +638,12 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
656
638
}
657
639
} )
658
640
. then (
659
- ( ) => {
660
- return this . driver . controlFlow ( )
661
- . execute (
662
- ( ) => {
663
- return this . plugins_ . waitForPromise ( this ) ;
664
- } ,
665
- 'Plugins.waitForPromise()' )
666
- . then ( ( ) => {
667
- return this . driver . wait ( ( ) => {
668
- return this . plugins_ . waitForCondition ( this ) . then ( ( results : boolean [ ] ) => {
669
- return results . reduce ( ( x , y ) => x && y , true ) ;
670
- } ) ;
671
- } , this . allScriptsTimeout , 'Plugins.waitForCondition()' ) ;
672
- } ) ;
641
+ async ( ) => {
642
+ await this . plugins_ . waitForPromise ( this ) ;
643
+ return this . driver . wait ( async ( ) => {
644
+ let results = await this . plugins_ . waitForCondition ( this ) ;
645
+ return results . reduce ( ( x , y ) => x && y , true ) ;
646
+ } , this . allScriptsTimeout , 'Plugins.waitForCondition()' ) ;
673
647
} ,
674
648
( err : Error ) => {
675
649
let timeout : RegExpExecArray ;
@@ -978,16 +952,14 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
978
952
. then ( ( ) => {
979
953
// Reset bpClient sync
980
954
if ( this . bpClient ) {
981
- return this . driver . controlFlow ( ) . execute ( ( ) => {
982
- return this . bpClient . setWaitEnabled ( ! this . internalIgnoreSynchronization ) ;
983
- } ) ;
955
+ return this . bpClient . setWaitEnabled ( ! this . internalIgnoreSynchronization ) ;
984
956
}
985
957
} )
986
958
. then ( ( ) => {
987
959
// Run Plugins
988
- return this . driver . controlFlow ( ) . execute ( ( ) => {
960
+ if ( ! this . ignoreSynchronization ) {
989
961
return this . plugins_ . onPageStable ( this ) ;
990
- } ) ;
962
+ }
991
963
} )
992
964
. then ( ( ) => null ) ;
993
965
}
0 commit comments