@@ -13,6 +13,17 @@ var WEB_ELEMENT_FUNCTIONS = [
13
13
'getSize' , 'getLocation' , 'isEnabled' , 'isSelected' , 'submit' , 'clear' ,
14
14
'isDisplayed' , 'getOuterHtml' , 'getInnerHtml' ] ;
15
15
16
+ var STACK_SUBSTRINGS_TO_FILTER = [
17
+ 'node_modules/minijasminenode/lib/' ,
18
+ 'node_modules/selenium-webdriver' ,
19
+ 'at Module.' ,
20
+ 'at Object.Module.' ,
21
+ 'at Function.Module' ,
22
+ '(timers.js:' ,
23
+ 'jasminewd/index.js' ,
24
+ 'protractor/lib/'
25
+ ] ;
26
+
16
27
/*
17
28
* Mix in other webdriver functionality to be accessible via protractor.
18
29
*/
@@ -933,6 +944,78 @@ Protractor.prototype.debugger = function() {
933
944
} , 'add breakpoint to control flow' ) ;
934
945
} ;
935
946
947
+ /**
948
+ * Beta (unstable) pause function for debugging webdriver tests. Use
949
+ * browser.pause() in your test to enter the protractor debugger from that
950
+ * point in the control flow.
951
+ * Does not require changes to the command line (no need to add 'debug').
952
+ */
953
+ Protractor . prototype . pause = function ( ) {
954
+ // Patch in a function to help us visualize what's going on in the control
955
+ // flow.
956
+ webdriver . promise . ControlFlow . prototype . getControlFlowText = function ( ) {
957
+ var descriptions = [ ] ;
958
+
959
+ var getDescriptions = function ( frameOrTask , descriptions ) {
960
+ if ( frameOrTask . getDescription ) {
961
+ var getRelevantStack = function ( stack ) {
962
+ return stack . filter ( function ( line ) {
963
+ var include = true ;
964
+ for ( var i = 0 ; i < STACK_SUBSTRINGS_TO_FILTER . length ; ++ i ) {
965
+ if ( line . toString ( ) . indexOf ( STACK_SUBSTRINGS_TO_FILTER [ i ] ) !==
966
+ - 1 ) {
967
+ include = false ;
968
+ }
969
+ }
970
+ return include ;
971
+ } ) ;
972
+ } ;
973
+ descriptions . push ( {
974
+ description : frameOrTask . getDescription ( ) ,
975
+ stack : getRelevantStack ( frameOrTask . snapshot_ . getStacktrace ( ) )
976
+ } ) ;
977
+ } else {
978
+ for ( var i = 0 ; i < frameOrTask . children_ . length ; ++ i ) {
979
+ getDescriptions ( frameOrTask . children_ [ i ] , descriptions ) ;
980
+ }
981
+ }
982
+ } ;
983
+ if ( this . history_ . length ) {
984
+ getDescriptions ( this . history_ [ this . history_ . length - 1 ] , descriptions ) ;
985
+ }
986
+ if ( this . activeFrame_ . getPendingTask ( ) ) {
987
+ getDescriptions ( this . activeFrame_ . getPendingTask ( ) , descriptions ) ;
988
+ }
989
+ getDescriptions ( this . activeFrame_ . getRoot ( ) , descriptions ) ;
990
+ var asString = '-- WebDriver control flow schedule \n' ;
991
+ for ( var i = 0 ; i < descriptions . length ; ++ i ) {
992
+ asString += ' |- ' + descriptions [ i ] . description ;
993
+ if ( descriptions [ i ] . stack . length ) {
994
+ asString += '\n |---' + descriptions [ i ] . stack . join ( '\n |---' ) ;
995
+ }
996
+ if ( ! ( i == descriptions . length - 1 ) ) {
997
+ asString += '\n' ;
998
+ }
999
+ }
1000
+ return asString ;
1001
+ } ;
1002
+
1003
+ // Call this private function instead of sending SIGUSR1 because Windows.
1004
+ process . _debugProcess ( process . pid ) ;
1005
+ var flow = webdriver . promise . controlFlow ( ) ;
1006
+
1007
+ flow . execute ( function ( ) {
1008
+ console . log ( 'Starting WebDriver debugger in a child process. Pause is ' +
1009
+ 'still beta, please report issues at github.com/angular/protractor' ) ;
1010
+ var nodedebug = require ( 'child_process' ) .
1011
+ fork ( __dirname + '/wddebugger.js' , [ 'localhost:5858' ] ) ;
1012
+ process . on ( 'exit' , function ( ) {
1013
+ nodedebug . kill ( 'SIGTERM' ) ;
1014
+ } )
1015
+ } ) ;
1016
+ flow . timeout ( 1000 , 'waiting for debugger to attach' ) ;
1017
+ } ;
1018
+
936
1019
/**
937
1020
* Builds a single web element from a locator with a findElementsOverride.
938
1021
* Throws an error if an element is not found, and issues a warning
@@ -1004,20 +1087,11 @@ exports.filterStackTrace = function(text) {
1004
1087
if ( ! text ) {
1005
1088
return text ;
1006
1089
}
1007
- var substringsToFilter = [
1008
- 'node_modules/minijasminenode/lib/' ,
1009
- 'node_modules/selenium-webdriver' ,
1010
- 'at Module.' ,
1011
- 'at Object.Module.' ,
1012
- 'at Function.Module' ,
1013
- '(timers.js:' ,
1014
- 'jasminewd/index.js'
1015
- ] ;
1016
1090
var lines = [ ] ;
1017
1091
text . split ( / \n / ) . forEach ( function ( line ) {
1018
1092
var include = true ;
1019
- for ( var i = 0 ; i < substringsToFilter . length ; ++ i ) {
1020
- if ( line . indexOf ( substringsToFilter [ i ] ) !== - 1 ) {
1093
+ for ( var i = 0 ; i < STACK_SUBSTRINGS_TO_FILTER . length ; ++ i ) {
1094
+ if ( line . indexOf ( STACK_SUBSTRINGS_TO_FILTER [ i ] ) !== - 1 ) {
1021
1095
include = false ;
1022
1096
}
1023
1097
}
0 commit comments