@@ -589,22 +589,16 @@ Protractor.prototype.debugger = function() {
589
589
} ;
590
590
591
591
/**
592
- * Beta (unstable) pause function for debugging webdriver tests. Use
593
- * browser.pause() in your test to enter the protractor debugger from that
594
- * point in the control flow.
595
- * Does not require changes to the command line (no need to add 'debug').
596
- * Note, if you are wrapping your own instance of Protractor, you must
597
- * expose globals 'browser' and 'protractor' for pause to work.
598
- *
599
- * @example
600
- * element(by.id('foo')).click();
601
- * browser.pause();
602
- * // Execution will stop before the next click action.
603
- * element(by.id('bar')).click();
592
+ * Helper function to:
593
+ * 1) Set up helper functions for debugger clients to call on (e.g.
594
+ * getControlFlowText, execute code, get autocompletion).
595
+ * 2) Enter process into debugger mode. (i.e. process._debugProcess).
596
+ * 3) Invoke the debugger client specified by debuggerClientPath.
604
597
*
598
+ * @param {string= } debuggerClientPath Absolute path of debugger client to use
605
599
* @param {number= } opt_debugPort Optional port to use for the debugging process
606
600
*/
607
- Protractor . prototype . pause = function ( opt_debugPort ) {
601
+ Protractor . prototype . initDebugger_ = function ( debuggerClientPath , opt_debugPort ) {
608
602
// Patch in a function to help us visualize what's going on in the control
609
603
// flow.
610
604
webdriver . promise . ControlFlow . prototype . getControlFlowText = function ( ) {
@@ -654,9 +648,9 @@ Protractor.prototype.pause = function(opt_debugPort) {
654
648
var flow = webdriver . promise . controlFlow ( ) ;
655
649
var pausePromise = flow . execute ( function ( ) {
656
650
log . puts ( 'Starting WebDriver debugger in a child process. Pause is ' +
657
- 'still beta, please report issues at github.com/angular/protractor' ) ;
651
+ 'still beta, please report issues at github.com/angular/protractor\n ' ) ;
658
652
var nodedebug = require ( 'child_process' ) .
659
- fork ( __dirname + '/debugger/wddebugger.js' , [ process . debugPort ] ) ;
653
+ fork ( debuggerClientPath , [ process . debugPort ] ) ;
660
654
process . on ( 'exit' , function ( ) {
661
655
nodedebug . kill ( 'SIGTERM' ) ;
662
656
} ) ;
@@ -665,8 +659,8 @@ Protractor.prototype.pause = function(opt_debugPort) {
665
659
var vm_ = require ( 'vm' ) ;
666
660
var browserUnderDebug = this ;
667
661
668
- // Helper used only by './debugger/wddebugger .js' to insert code into the
669
- // control flow.
662
+ // Helper used only by debuggers at './debugger/modes/* .js' to insert code
663
+ // into the control flow.
670
664
// In order to achieve this, we maintain a promise at the top of the control
671
665
// flow, so that we can insert frames into it.
672
666
// To be able to simulate callback/asynchronous code, we poll this object
@@ -689,8 +683,14 @@ Protractor.prototype.pause = function(opt_debugPort) {
689
683
self . execPromiseResult_ = self . execPromiseError_ = undefined ;
690
684
691
685
self . execPromise_ = self . execPromise_ .
692
- then ( execFn_ ) .
693
- then ( function ( result ) {
686
+ then ( function ( ) {
687
+ var result = execFn_ ( ) ;
688
+ if ( webdriver . promise . isPromise ( result ) ) {
689
+ return result . then ( function ( val ) { return val } ) ;
690
+ } else {
691
+ return result ;
692
+ }
693
+ } ) . then ( function ( result ) {
694
694
self . execPromiseResult_ = result ;
695
695
} , function ( err ) {
696
696
self . execPromiseError_ = err ;
@@ -746,9 +746,62 @@ Protractor.prototype.pause = function(opt_debugPort) {
746
746
}
747
747
} ;
748
748
749
+ global . list = function ( locator ) {
750
+ return browser . findElements ( locator ) . then ( function ( arr ) {
751
+ var found = [ ] ;
752
+ for ( var i = 0 ; i < arr . length ; ++ i ) {
753
+ arr [ i ] . getText ( ) . then ( function ( text ) {
754
+ found . push ( text ) ;
755
+ } ) ;
756
+ }
757
+ return found ;
758
+ } ) ;
759
+ } ;
760
+
749
761
flow . timeout ( 1000 , 'waiting for debugger to attach' ) ;
750
762
} ;
751
763
764
+ /**
765
+ * Beta (unstable) enterRepl function for entering the repl loop from
766
+ * any point in the control flow. Use browser.enterRepl() in your test.
767
+ * Does not require changes to the command line (no need to add 'debug').
768
+ * Note, if you are wrapping your own instance of Protractor, you must
769
+ * expose globals 'browser' and 'protractor' for pause to work.
770
+ *
771
+ * @example
772
+ * element(by.id('foo')).click();
773
+ * browser.enterRepl();
774
+ * // Execution will stop before the next click action.
775
+ * element(by.id('bar')).click();
776
+ *
777
+ * @param {number= } opt_debugPort Optional port to use for the debugging process
778
+ */
779
+ Protractor . prototype . enterRepl = function ( opt_debugPort ) {
780
+ var debuggerClientPath = __dirname + '/debugger/clients/wdrepl.js' ;
781
+ this . initDebugger_ ( debuggerClientPath , opt_debugPort ) ;
782
+ } ;
783
+
784
+ /**
785
+ * Beta (unstable) pause function for debugging webdriver tests. Use
786
+ * browser.pause() in your test to enter the protractor debugger from that
787
+ * point in the control flow.
788
+ * Does not require changes to the command line (no need to add 'debug').
789
+ * Note, if you are wrapping your own instance of Protractor, you must
790
+ * expose globals 'browser' and 'protractor' for pause to work.
791
+ *
792
+ * @example
793
+ * element(by.id('foo')).click();
794
+ * browser.pause();
795
+ * // Execution will stop before the next click action.
796
+ * element(by.id('bar')).click();
797
+ *
798
+ * @param {number= } opt_debugPort Optional port to use for the debugging process
799
+ */
800
+ Protractor . prototype . pause = function ( opt_debugPort ) {
801
+ var debuggerClientPath = __dirname + '/debugger/clients/wddebugger.js' ;
802
+ this . initDebugger_ ( debuggerClientPath , opt_debugPort ) ;
803
+ } ;
804
+
752
805
/**
753
806
* Create a new instance of Protractor by wrapping a webdriver instance.
754
807
*
0 commit comments