@@ -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
@@ -252,13 +258,7 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
252
258
* @type {boolean }
253
259
*/
254
260
set ignoreSynchronization ( value ) {
255
- this . driver . controlFlow ( ) . execute ( ( ) => {
256
- if ( this . bpClient ) {
257
- logger . debug ( 'Setting waitForAngular' + value ) ;
258
- this . bpClient . setSynchronization ( ! value ) ;
259
- }
260
- } , `Set proxy synchronization to ${ value } ` ) ;
261
- this . internalIgnoreSynchronization = value ;
261
+ this . waitForAngularEnabled ( ! value ) ;
262
262
}
263
263
264
264
get ignoreSynchronization ( ) {
@@ -449,11 +449,20 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
449
449
* Call waitForAngularEnabled() without passing a value to read the current
450
450
* state without changing it.
451
451
*/
452
- waitForAngularEnabled ( enabled : boolean = null ) : boolean {
452
+ waitForAngularEnabled ( enabled : boolean = null ) : wdpromise . Promise < boolean > {
453
453
if ( enabled != null ) {
454
- this . ignoreSynchronization = ! enabled ;
454
+ const ret = this . driver . controlFlow ( ) . execute ( ( ) => {
455
+ if ( this . bpClient ) {
456
+ logger . debug ( 'Setting waitForAngular' + ! enabled ) ;
457
+ return this . bpClient . setSynchronization ( enabled ) . then ( ( ) => {
458
+ return enabled ;
459
+ } ) ;
460
+ }
461
+ } , `Set proxy synchronization enabled to ${ enabled } ` ) ;
462
+ this . internalIgnoreSynchronization = ! enabled ;
463
+ return ret ;
455
464
}
456
- return ! this . ignoreSynchronization ;
465
+ return wdpromise . when ( ! this . ignoreSynchronization ) ;
457
466
}
458
467
459
468
/**
@@ -659,7 +668,9 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
659
668
660
669
let runWaitForAngularScript : ( ) => wdpromise . Promise < any > = ( ) => {
661
670
if ( this . plugins_ . skipAngularStability ( ) || this . bpClient ) {
662
- return wdpromise . when ( null ) ;
671
+ return this . driver . controlFlow ( ) . execute ( ( ) => {
672
+ return wdpromise . when ( null ) ;
673
+ } , 'bpClient or plugin stability override' ) ;
663
674
} else {
664
675
return this . executeAsyncScript_ (
665
676
clientSideScripts . waitForAngular , 'Protractor.waitForAngular()' + description ,
@@ -1053,15 +1064,15 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
1053
1064
* page has been changed.
1054
1065
*/
1055
1066
setLocation ( url : string ) : wdpromise . Promise < any > {
1056
- this . waitForAngular ( ) ;
1057
- return this
1058
- . executeScriptWithDescription (
1059
- clientSideScripts . setLocation , 'Protractor.setLocation()' , this . rootEl , url )
1060
- . then ( ( browserErr : Error ) => {
1061
- if ( browserErr ) {
1062
- throw 'Error while navigating to \'' + url + '\' : ' + JSON . stringify ( browserErr ) ;
1063
- }
1064
- } ) ;
1067
+ return this . waitForAngular ( ) . then (
1068
+ ( ) => this . executeScriptWithDescription (
1069
+ clientSideScripts . setLocation , 'Protractor.setLocation()' , this . rootEl , url )
1070
+ . then ( ( browserErr : Error ) => {
1071
+ if ( browserErr ) {
1072
+ throw 'Error while navigating to \'' + url + '\' : ' +
1073
+ JSON . stringify ( browserErr ) ;
1074
+ }
1075
+ } ) ) ;
1065
1076
}
1066
1077
1067
1078
/**
@@ -1075,9 +1086,9 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
1075
1086
* AngularJS.
1076
1087
*/
1077
1088
getLocationAbsUrl ( ) : wdpromise . Promise < any > {
1078
- this . waitForAngular ( ) ;
1079
- return this . executeScriptWithDescription (
1080
- clientSideScripts . getLocationAbsUrl , 'Protractor.getLocationAbsUrl()' , this . rootEl ) ;
1089
+ return this . waitForAngular ( ) . then (
1090
+ ( ) => this . executeScriptWithDescription (
1091
+ clientSideScripts . getLocationAbsUrl , 'Protractor.getLocationAbsUrl()' , this . rootEl ) ) ;
1081
1092
}
1082
1093
1083
1094
/**
@@ -1102,10 +1113,10 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
1102
1113
*/
1103
1114
debugger ( ) {
1104
1115
// jshint debug: true
1105
- this . driver . executeScript ( clientSideScripts . installInBrowser ) ;
1106
- wdpromise . controlFlow ( ) . execute ( ( ) => {
1107
- debugger ;
1108
- } , 'add breakpoint to control flow' ) ;
1116
+ return this . driver . executeScript ( clientSideScripts . installInBrowser )
1117
+ . then ( ( ) => wdpromise . controlFlow ( ) . execute ( ( ) => {
1118
+ debugger ;
1119
+ } , 'add breakpoint to control flow' ) ) ;
1109
1120
}
1110
1121
1111
1122
/**
0 commit comments