Skip to content

Commit

Permalink
Pass local context to browser.debug() command. (#4299)
Browse files Browse the repository at this point in the history
* Allow local context to be passed to browser.debug command.

* Improve debug experience.
  • Loading branch information
garg3133 authored Jan 16, 2025
1 parent e4e259d commit 991f79d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions lib/api/client-commands/debug.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(() => {
Expand Down
2 changes: 1 addition & 1 deletion lib/testsuite/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 991f79d

Please sign in to comment.