diff --git a/lib/api/client-commands/debug.js b/lib/api/client-commands/debug.js index e5632223d7..bde1049cc3 100644 --- a/lib/api/client-commands/debug.js +++ b/lib/api/client-commands/debug.js @@ -1,6 +1,7 @@ const EventEmitter = require('events'); const NightwatchRepl = require('../../testsuite/repl'); const Debuggability = require('../../utils/debuggability.js'); +const {By} = require('selenium-webdriver'); /** * This command halts the test execution and provides users with a REPL interface where they can type @@ -37,24 +38,37 @@ class Debug extends EventEmitter { } command(config, callback) { + // Create context for vm + const context = { + browser: this.api, + app: this.api, + by: By, + By: By + }; + + // set the user provided context + if (config.context) { + Object.assign(context, config.context); + delete config.context; + } + const repl = new NightwatchRepl(config); // eslint-disable-next-line console.log(NightwatchRepl.introMessage()); - // Create context for vm - const context = { - browser: this.api, - app: this.api - }; + // TODO: what's the use of this `if` block? if (config?.selector) { this.api.executeScript('console.log("Element ' + config.selector + ':", document.querySelector("' + config.selector + '"))'); } + // Before starting REPL server, Set debugMode to true Debuggability.debugMode = true; + // Set isES6AsyncTestcase to true in debugmode const isES6AsyncTestcase = this.client.isES6AsyncTestcase; this.client.isES6AsyncTestcase = true; + repl.startServer(context); repl.onExit(() => { diff --git a/lib/testsuite/repl.js b/lib/testsuite/repl.js index 3acc45f4fd..cf0566917d 100644 --- a/lib/testsuite/repl.js +++ b/lib/testsuite/repl.js @@ -62,7 +62,7 @@ module.exports = class NightwatchRepl { } async _handleResult(result, callback) { - const resultIsPromise = result instanceof Promise; + const resultIsPromise = result instanceof Promise || (result && typeof result.then === 'function'); if (!resultIsPromise) { return callback(null, result);