123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- var baseDebugger;
- try {
- baseDebugger = require('_debugger');
- } catch (e) {
- if (e.code == 'MODULE_NOT_FOUND') {
- console.log('***********************************************************');
- console.log('* WARNING: _debugger module not available on Node.js 8 *');
- console.log('* and higher. *');
- console.log('* *');
- console.log('* Use \'debugger\' keyword instead: *');
- console.log('* https://goo.gl/MvWqFh *');
- console.log('***********************************************************');
- }
- throw e;
- }
- var path = require('path');
- /**
- * Create a debugger client and attach to a running protractor process.
- * @param {number} pid Pid of the process to attach the debugger to.
- * @param {number=} opt_port Port to set up the debugger connection over.
- * @return {!baseDebugger.Client} The connected debugger client.
- */
- exports.attachDebugger = function(pid, opt_port) {
- var client = new baseDebugger.Client();
- var port = opt_port || process.debugPort;
- // Call this private function instead of sending SIGUSR1 because Windows.
- process._debugProcess(pid);
- // Connect to debugger on port with retry 200ms apart.
- var connectWithRetry = function(attempts) {
- client.connect(port, 'localhost')
- .on('error', function(e) {
- if (attempts === 1) {
- throw e;
- } else {
- setTimeout(function() {
- connectWithRetry(attempts - 1);
- }, 200);
- }
- });
- };
- connectWithRetry(10);
- return client;
- };
- /**
- * Set a breakpoint for evaluating REPL statements.
- * This sets a breakpoint in Protractor's breakpointhook.js, so that we'll
- * break after executing a command from the REPL.
- */
- exports.setEvaluateBreakpoint = function(client, cb) {
- client.setBreakpoint({
- type: 'scriptRegExp',
- target: prepareDebuggerPath('built', 'breakpointhook.js'),
- line: 2
- }, function(err, response) {
- if (err) {
- throw new Error(err);
- }
- cb(response.breakpoint);
- });
- };
- /**
- * Set a breakpoint for moving forward by one webdriver command.
- * This sets a breakpoint in selenium-webdriver/lib/http.js, and is
- * extremely sensitive to the selenium version. It works for
- * selenium-webdriver 3.0.1
- * This breaks on the following line in http.js:
- * let request = buildRequest(this.customCommands_, this.w3c, command);
- * And will need to break at a similar point in future selenium-webdriver
- * versions.
- */
- exports.setWebDriverCommandBreakpoint = function(client, cb) {
- client.setBreakpoint({
- type: 'scriptRegExp',
- target: prepareDebuggerPath('lib', 'http.js'),
- line: 433
- }, function(err, response) {
- if (err) {
- throw new Error(err);
- }
- cb(response.breakpoint);
- });
- };
- /**
- * Create a cross-platform friendly path for setting scriptRegExp breakpoints.
- */
- function prepareDebuggerPath(...parts) {
- return path.join(...parts)
- .replace('\\', '\\\\')
- .replace('.', '\\.');
- }
- /**
- * Trim excess symbols from the repl command so that it is consistent with
- * the user input.
- * @param {string} cmd Cmd provided by the repl server.
- * @return {string} The trimmed cmd.
- */
- exports.trimReplCmd = function(cmd) {
- // Given user input 'foobar', some versions of node provide '(foobar\n)',
- // while other versions of node provide 'foobar\n'.
- if (cmd.length >= 2 && cmd[0] === '(' && cmd[cmd.length - 1] === ')') {
- cmd = cmd.substring(1, cmd.length - 1);
- }
- return cmd.slice(0, cmd.length - 1);
- };
|