@@ -241,9 +241,13 @@ export class ProtractorBrowser extends Webdriver {
241
241
*/
242
242
debuggerServerPort_ : number ;
243
243
244
+ /**
245
+ * Set to true when we validate that the debug port is open. Since the debug
246
+ * port is held open forever once the debugger is attached, it's important
247
+ * we only do validation once.
248
+ */
244
249
debuggerValidated_ : boolean ;
245
250
246
-
247
251
/**
248
252
* If true, Protractor will interpret any angular apps it comes across as
249
253
* hybrid angular1/angular2 apps.
@@ -983,10 +987,12 @@ export class ProtractorBrowser extends Webdriver {
983
987
}
984
988
} ) ;
985
989
986
- return doneDeferred . then ( null , ( err : string ) => {
987
- console . error ( err ) ;
988
- process . exit ( 1 ) ;
989
- } ) ;
990
+ return doneDeferred . then (
991
+ ( ) => { this . debuggerValidated_ = true ; } ,
992
+ ( err : string ) => {
993
+ console . error ( err ) ;
994
+ process . exit ( 1 ) ;
995
+ } ) ;
990
996
}
991
997
992
998
private dbgCodeExecutor_ : any ;
@@ -1043,10 +1049,10 @@ export class ProtractorBrowser extends Webdriver {
1043
1049
1044
1050
let browserUnderDebug = this ;
1045
1051
let debuggerReadyPromise = webdriver . promise . defer ( ) ;
1046
- flow . execute ( function ( ) {
1052
+ flow . execute ( ( ) => {
1047
1053
process [ 'debugPort' ] = opt_debugPort || process [ 'debugPort' ] ;
1048
1054
browserUnderDebug . validatePortAvailability_ ( process [ 'debugPort' ] )
1049
- . then ( function ( firstTime : boolean ) {
1055
+ . then ( ( firstTime : boolean ) => {
1050
1056
onStartFn ( firstTime ) ;
1051
1057
1052
1058
let args = [ process . pid , process [ 'debugPort' ] ] ;
@@ -1056,11 +1062,19 @@ export class ProtractorBrowser extends Webdriver {
1056
1062
let nodedebug =
1057
1063
require ( 'child_process' ) . fork ( debuggerClientPath , args ) ;
1058
1064
process . on ( 'exit' , function ( ) { nodedebug . kill ( 'SIGTERM' ) ; } ) ;
1059
- nodedebug . on ( 'message' , function ( m : string ) {
1060
- if ( m === 'ready' ) {
1061
- debuggerReadyPromise . fulfill ( ) ;
1062
- }
1063
- } ) ;
1065
+ nodedebug
1066
+ . on ( 'message' ,
1067
+ ( m : string ) => {
1068
+ if ( m === 'ready' ) {
1069
+ debuggerReadyPromise . fulfill ( ) ;
1070
+ }
1071
+ } )
1072
+ . on ( 'exit' , ( ) => {
1073
+ logger . info ( 'Debugger exiting' ) ;
1074
+ // Clear this so that we know it's ok to attach a debugger
1075
+ // again.
1076
+ this . dbgCodeExecutor_ = null ;
1077
+ } ) ;
1064
1078
} ) ;
1065
1079
} ) ;
1066
1080
@@ -1167,6 +1181,8 @@ export class ProtractorBrowser extends Webdriver {
1167
1181
return this . execPromiseResult_ ;
1168
1182
}
1169
1183
} ;
1184
+
1185
+ return pausePromise ;
1170
1186
}
1171
1187
1172
1188
/**
@@ -1221,7 +1237,12 @@ export class ProtractorBrowser extends Webdriver {
1221
1237
* @param {number= } opt_debugPort Optional port to use for the debugging
1222
1238
* process
1223
1239
*/
1224
- pause ( opt_debugPort ?: number ) {
1240
+ pause ( opt_debugPort ?: number ) : webdriver . promise . Promise < any > {
1241
+ if ( this . dbgCodeExecutor_ ) {
1242
+ logger . info (
1243
+ 'Encountered browser.pause(), but debugger already attached.' ) ;
1244
+ return webdriver . promise . fulfilled ( true ) ;
1245
+ }
1225
1246
let debuggerClientPath = __dirname + '/debugger/clients/wddebugger.js' ;
1226
1247
let onStartFn = ( firstTime : boolean ) => {
1227
1248
logger . info ( ) ;
@@ -1240,7 +1261,7 @@ export class ProtractorBrowser extends Webdriver {
1240
1261
logger . info ( ) ;
1241
1262
}
1242
1263
} ;
1243
- this . initDebugger_ ( debuggerClientPath , onStartFn , opt_debugPort ) ;
1264
+ return this . initDebugger_ ( debuggerClientPath , onStartFn , opt_debugPort ) ;
1244
1265
}
1245
1266
1246
1267
/**
0 commit comments