@@ -134,10 +134,16 @@ function ptorMixin(to: any, from: any, fnName: string, setupFn?: Function) {
134
134
arguments [ i ] = arguments [ i ] . getWebElement ( ) ;
135
135
}
136
136
}
137
+ const run = ( ) => {
138
+ return from [ fnName ] . apply ( from , arguments ) ;
139
+ } ;
137
140
if ( setupFn ) {
138
- setupFn ( ) ;
141
+ const setupResult = setupFn ( ) ;
142
+ if ( setupResult && ( typeof setupResult . then === 'function' ) ) {
143
+ return setupResult . then ( run ) ;
144
+ }
139
145
}
140
- return from [ fnName ] . apply ( from , arguments ) ;
146
+ return run ( ) ;
141
147
} ;
142
148
} ;
143
149
@@ -287,13 +293,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
287
293
* @type {boolean }
288
294
*/
289
295
set ignoreSynchronization ( value ) {
290
- this . driver . controlFlow ( ) . execute ( ( ) => {
291
- if ( this . bpClient ) {
292
- logger . debug ( 'Setting waitForAngular' + value ) ;
293
- return this . bpClient . setWaitEnabled ( ! value ) ;
294
- }
295
- } , `Set proxy synchronization to ${ value } ` ) ;
296
- this . internalIgnoreSynchronization = value ;
296
+ this . waitForAngularEnabled ( ! value ) ;
297
297
}
298
298
299
299
get ignoreSynchronization ( ) {
@@ -484,11 +484,20 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
484
484
* Call waitForAngularEnabled() without passing a value to read the current
485
485
* state without changing it.
486
486
*/
487
- waitForAngularEnabled ( enabled : boolean = null ) : boolean {
487
+ waitForAngularEnabled ( enabled : boolean = null ) : wdpromise . Promise < boolean > {
488
488
if ( enabled != null ) {
489
- this . ignoreSynchronization = ! enabled ;
489
+ const ret = this . driver . controlFlow ( ) . execute ( ( ) => {
490
+ if ( this . bpClient ) {
491
+ logger . debug ( 'Setting waitForAngular' + ! enabled ) ;
492
+ return this . bpClient . setWaitEnabled ( enabled ) . then ( ( ) => {
493
+ return enabled ;
494
+ } ) ;
495
+ }
496
+ } , `Set proxy synchronization enabled to ${ enabled } ` ) ;
497
+ this . internalIgnoreSynchronization = ! enabled ;
498
+ return ret ;
490
499
}
491
- return ! this . ignoreSynchronization ;
500
+ return wdpromise . when ( ! this . ignoreSynchronization ) ;
492
501
}
493
502
494
503
/**
@@ -694,7 +703,9 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
694
703
695
704
let runWaitForAngularScript : ( ) => wdpromise . Promise < any > = ( ) => {
696
705
if ( this . plugins_ . skipAngularStability ( ) || this . bpClient ) {
697
- return wdpromise . when ( null ) ;
706
+ return this . driver . controlFlow ( ) . execute ( ( ) => {
707
+ return wdpromise . when ( null ) ;
708
+ } , 'bpClient or plugin stability override' ) ;
698
709
} else {
699
710
// Need to wrap this so that we read rootEl in the control flow, not synchronously.
700
711
return this . angularAppRoot ( ) . then ( ( rootEl : string ) => {
@@ -1091,15 +1102,15 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
1091
1102
* page has been changed.
1092
1103
*/
1093
1104
setLocation ( url : string ) : wdpromise . Promise < any > {
1094
- this . waitForAngular ( ) ;
1095
- return this
1096
- . executeScriptWithDescription (
1097
- clientSideScripts . setLocation , 'Protractor.setLocation()' , this . rootEl , url )
1098
- . then ( ( browserErr : Error ) => {
1099
- if ( browserErr ) {
1100
- throw 'Error while navigating to \'' + url + '\' : ' + JSON . stringify ( browserErr ) ;
1101
- }
1102
- } ) ;
1105
+ return this . waitForAngular ( ) . then (
1106
+ ( ) => this . executeScriptWithDescription (
1107
+ clientSideScripts . setLocation , 'Protractor.setLocation()' , this . rootEl , url )
1108
+ . then ( ( browserErr : Error ) => {
1109
+ if ( browserErr ) {
1110
+ throw 'Error while navigating to \'' + url + '\' : ' +
1111
+ JSON . stringify ( browserErr ) ;
1112
+ }
1113
+ } ) ) ;
1103
1114
}
1104
1115
1105
1116
/**
@@ -1113,9 +1124,9 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
1113
1124
* AngularJS.
1114
1125
*/
1115
1126
getLocationAbsUrl ( ) : wdpromise . Promise < any > {
1116
- this . waitForAngular ( ) ;
1117
- return this . executeScriptWithDescription (
1118
- clientSideScripts . getLocationAbsUrl , 'Protractor.getLocationAbsUrl()' , this . rootEl ) ;
1127
+ return this . waitForAngular ( ) . then (
1128
+ ( ) => this . executeScriptWithDescription (
1129
+ clientSideScripts . getLocationAbsUrl , 'Protractor.getLocationAbsUrl()' , this . rootEl ) ) ;
1119
1130
}
1120
1131
1121
1132
/**
@@ -1140,10 +1151,10 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
1140
1151
*/
1141
1152
debugger ( ) {
1142
1153
// jshint debug: true
1143
- this . driver . executeScript ( clientSideScripts . installInBrowser ) ;
1144
- wdpromise . controlFlow ( ) . execute ( ( ) => {
1145
- debugger ;
1146
- } , 'add breakpoint to control flow' ) ;
1154
+ return this . driver . executeScript ( clientSideScripts . installInBrowser )
1155
+ . then ( ( ) => wdpromise . controlFlow ( ) . execute ( ( ) => {
1156
+ debugger ;
1157
+ } , 'add breakpoint to control flow' ) ) ;
1147
1158
}
1148
1159
1149
1160
/**
0 commit comments