.debug() Suggest edits
This command halts the test execution and provides users with a REPL interface where they can type
any of the available Nightwatch commands or assertions and it will be executed in the running browser
in real-time.
This can be used to debug why a certain command in not working as expected or a certain assertion is
failing by trying out the commands and assertions in different ways (trying an assertion with different
locators until the correct one if found), or just play around with the available Nightwatch commands
and assertions.
You can also expose local variables and helper functions from your test to the REPL by passing
them via the context option; they will then be available in the debug prompt alongside
the browser object.
Usage
Example
// async function is required while using the debug
// command to get the correct result as output.
it('demos debug command', async function (browser) {
const someLocalVariable = 'something random';
function someLocalFunction() {
return 'local function result';
}
// with default options
browser.debug();
// with no auto-complete
browser.debug({preview: false});
// with a timeout of 6000 ms (time for which the interface
// would wait for a result).
browser.debug({timeout: 6000});
// expose local variables/functions to the debug REPL
browser.debug({
// both values below will be directly available in the debug REPL
context: {someLocalVariable, someLocalFunction}
});
});
Parameters
| Name | Type | description |
|---|---|---|
configOptional |
object | Config options for the REPL interface. |
callbackOptional |
function | Optional callback function to be called when the command finishes. |