@@ -198,7 +198,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
198198 */
199199 async angularAppRoot ( valuePromise : string | wdpromise . Promise < string > = null ) : Promise < string > {
200200 if ( valuePromise != null ) {
201- const value = await Promise . resolve ( valuePromise ) ;
201+ const value = await valuePromise ;
202202 this . internalRootEl = value ;
203203 if ( this . bpClient ) {
204204 await this . bpClient . setWaitParams ( value ) ;
@@ -414,7 +414,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
414414 async waitForAngularEnabled ( enabledPromise : boolean | wdpromise . Promise < boolean > = null ) :
415415 Promise < boolean > {
416416 if ( enabledPromise != null ) {
417- const enabled = await Promise . resolve ( enabledPromise ) ;
417+ const enabled = await enabledPromise ;
418418 if ( this . bpClient ) {
419419 logger . debug ( 'Setting waitForAngular' + ! enabled ) ;
420420 await this . bpClient . setWaitEnabled ( enabled ) ;
@@ -615,99 +615,88 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
615615 async waitForAngular ( opt_description ?: string ) : Promise < any > {
616616 let description = opt_description ? ' - ' + opt_description : '' ;
617617 if ( this . ignoreSynchronization ) {
618- return Promise . resolve ( true ) ;
618+ return true ;
619619 }
620620
621621 let runWaitForAngularScript = async ( ) : Promise < any > => {
622622 if ( this . plugins_ . skipAngularStability ( ) || this . bpClient ) {
623- return Promise . resolve ( null ) ;
623+ return null ;
624624 } else {
625- // Need to wrap this so that we read rootEl in the control flow, not synchronously.
626625 let rootEl = await this . angularAppRoot ( ) ;
627626 return this . executeAsyncScript_ (
628- clientSideScripts . waitForAngular , ' Protractor.waitForAngular()' + description , rootEl ) ;
627+ clientSideScripts . waitForAngular , ` Protractor.waitForAngular() ${ description } ` , rootEl ) ;
629628 }
630629 } ;
631630
632- return runWaitForAngularScript ( )
633- . then ( ( browserErr : Function ) => {
634- if ( browserErr ) {
635- throw new Error (
636- 'Error while waiting for Protractor to ' +
637- 'sync with the page: ' + JSON . stringify ( browserErr ) ) ;
631+ let browserErr = await runWaitForAngularScript ( ) ;
632+ if ( browserErr ) {
633+ throw new Error (
634+ 'Error while waiting for Protractor to ' +
635+ 'sync with the page: ' + JSON . stringify ( browserErr ) ) ;
636+ }
637+ await this . plugins_ . waitForPromise ( this ) ;
638+ try {
639+ await this . driver . wait ( async ( ) => {
640+ let results = await this . plugins_ . waitForCondition ( this ) ;
641+ return results . reduce ( ( x , y ) => x && y , true ) ;
642+ } , this . allScriptsTimeout , 'Plugins.waitForCondition()' ) ;
643+ } catch ( err ) {
644+ let timeout : RegExpExecArray ;
645+ if ( / a s y n c h r o n o u s s c r i p t t i m e o u t / . test ( err . message ) ) {
646+ // Timeout on Chrome
647+ timeout = / - ? [ \d \. ] * \ s e c o n d s / . exec ( err . message ) ;
648+ } else if ( / T i m e d o u t w a i t i n g f o r a s y n c s c r i p t / . test ( err . message ) ) {
649+ // Timeout on Firefox
650+ timeout = / - ? [ \d \. ] * m s / . exec ( err . message ) ;
651+ } else if ( / T i m e d o u t w a i t i n g f o r a n a s y n c h r o n o u s s c r i p t / . test ( err . message ) ) {
652+ // Timeout on Safari
653+ timeout = / - ? [ \d \. ] * \ m s / . exec ( err . message ) ;
654+ }
655+ if ( timeout ) {
656+ let errMsg = `Timed out waiting for asynchronous Angular tasks to finish after ` +
657+ `${ timeout } . This may be because the current page is not an Angular ` +
658+ `application. Please see the FAQ for more details: ` +
659+ `https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular` ;
660+ if ( description . indexOf ( ' - Locator: ' ) == 0 ) {
661+ errMsg += '\nWhile waiting for element with locator' + description ;
662+ }
663+ let pendingTimeoutsPromise : wdpromise . Promise < any > ;
664+ if ( this . trackOutstandingTimeouts_ ) {
665+ pendingTimeoutsPromise = this . executeScriptWithDescription (
666+ 'return window.NG_PENDING_TIMEOUTS' ,
667+ 'Protractor.waitForAngular() - getting pending timeouts' + description ) ;
668+ } else {
669+ pendingTimeoutsPromise = wdpromise . when ( { } ) ;
670+ }
671+ let pendingHttpsPromise = this . executeScriptWithDescription (
672+ clientSideScripts . getPendingHttpRequests ,
673+ 'Protractor.waitForAngular() - getting pending https' + description ,
674+ this . internalRootEl ) ;
675+
676+ let arr = await Promise . all ( [ pendingTimeoutsPromise , pendingHttpsPromise ] ) ;
677+
678+ let pendingTimeouts = arr [ 0 ] || [ ] ;
679+ let pendingHttps = arr [ 1 ] || [ ] ;
680+
681+ let key : string , pendingTasks : string [ ] = [ ] ;
682+ for ( key in pendingTimeouts ) {
683+ if ( pendingTimeouts . hasOwnProperty ( key ) ) {
684+ pendingTasks . push ( ' - $timeout: ' + pendingTimeouts [ key ] ) ;
638685 }
639- } )
640- . then (
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()' ) ;
647- } ,
648- ( err : Error ) => {
649- let timeout : RegExpExecArray ;
650- if ( / a s y n c h r o n o u s s c r i p t t i m e o u t / . test ( err . message ) ) {
651- // Timeout on Chrome
652- timeout = / - ? [ \d \. ] * \ s e c o n d s / . exec ( err . message ) ;
653- } else if ( / T i m e d o u t w a i t i n g f o r a s y n c s c r i p t / . test ( err . message ) ) {
654- // Timeout on Firefox
655- timeout = / - ? [ \d \. ] * m s / . exec ( err . message ) ;
656- } else if ( / T i m e d o u t w a i t i n g f o r a n a s y n c h r o n o u s s c r i p t / . test ( err . message ) ) {
657- // Timeout on Safari
658- timeout = / - ? [ \d \. ] * \ m s / . exec ( err . message ) ;
659- }
660- if ( timeout ) {
661- let errMsg = `Timed out waiting for asynchronous Angular tasks to finish after ` +
662- `${ timeout } . This may be because the current page is not an Angular ` +
663- `application. Please see the FAQ for more details: ` +
664- `https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular` ;
665- if ( description . indexOf ( ' - Locator: ' ) == 0 ) {
666- errMsg += '\nWhile waiting for element with locator' + description ;
667- }
668- let pendingTimeoutsPromise : wdpromise . Promise < any > ;
669- if ( this . trackOutstandingTimeouts_ ) {
670- pendingTimeoutsPromise = this . executeScriptWithDescription (
671- 'return window.NG_PENDING_TIMEOUTS' ,
672- 'Protractor.waitForAngular() - getting pending timeouts' + description ) ;
673- } else {
674- pendingTimeoutsPromise = wdpromise . when ( { } ) ;
675- }
676- let pendingHttpsPromise = this . executeScriptWithDescription (
677- clientSideScripts . getPendingHttpRequests ,
678- 'Protractor.waitForAngular() - getting pending https' + description ,
679- this . internalRootEl ) ;
680-
681- return wdpromise . all ( [ pendingTimeoutsPromise , pendingHttpsPromise ] )
682- . then (
683- ( arr : any [ ] ) => {
684- let pendingTimeouts = arr [ 0 ] || [ ] ;
685- let pendingHttps = arr [ 1 ] || [ ] ;
686-
687- let key : string , pendingTasks : string [ ] = [ ] ;
688- for ( key in pendingTimeouts ) {
689- if ( pendingTimeouts . hasOwnProperty ( key ) ) {
690- pendingTasks . push ( ' - $timeout: ' + pendingTimeouts [ key ] ) ;
691- }
692- }
693- for ( key in pendingHttps ) {
694- pendingTasks . push ( ' - $http: ' + pendingHttps [ key ] . url ) ;
695- }
696- if ( pendingTasks . length ) {
697- errMsg += '. \nThe following tasks were pending:\n' ;
698- errMsg += pendingTasks . join ( '\n' ) ;
699- }
700- err . message = errMsg ;
701- throw err ;
702- } ,
703- ( ) => {
704- err . message = errMsg ;
705- throw err ;
706- } ) ;
707- } else {
708- throw err ;
709- }
710- } ) ;
686+ }
687+ for ( key in pendingHttps ) {
688+ pendingTasks . push ( ' - $http: ' + pendingHttps [ key ] . url ) ;
689+ }
690+ if ( pendingTasks . length ) {
691+ errMsg += '. \nThe following tasks were pending:\n' ;
692+ errMsg += pendingTasks . join ( '\n' ) ;
693+ }
694+ err . message = errMsg ;
695+ throw err ;
696+ } else {
697+ throw err ;
698+ }
699+ }
711700 }
712701
713702 /**
0 commit comments