Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow local context to be passed to browser.debug command. #4299

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading