Enable step-by-step debugging

This section covers how to enable debugging for a Node.js application that is started with the Test Launcher in interactive mode.

The main reason why you would want to enable debugging of your tests is that by setting pauses (breakpoints) you will be able to follow your test execution step-by-step and see how the device reacts to each command.

The Test Launcher supports both --inspect=[port] and --inspect-brk=[port] Node.js debugging options.

Debugging in Chrome developer tools

  1. In Chrome browser open chrome://inspect/#devices page. Make sure that Discover network targets checkbox is checked.

  2. Press Configure... button next to Discover network targets option to set up ports that Chrome Developer Tools should be listening to.

  3. Start your Node.js script with Suitest Test Launcher. Make sure you pass either --inspect=[port] or --inspect-brk=[port] parameter, where [port] is one of the ports, configured in previous step. For example suitest interactive --inspect-brk=9121 ./node_modules/mocha/bin/_mocha --no-timeouts --exit

  4. In Chrome you should now see your Node process under Remote Target section. Click inspect to open Chrome Developer Tools attached to your process.

Debugging in JetBrains IDE (WebStorm, PhpStorm, IntelliJ IDEA etc.)

Create Node.js run configuration. Set the following:

  • Working directory to root folder of your project (where your package.json file is located)

  • JavaScript file to ./node_modules/suitest-js-api/lib/testLauncher/index.js

  • Application parameters to interactive --inspect-brk=[port] [command], where [port] is a port you want debugger to listen to and [command] is a Node.js script you want to debug. For example interactive --inspect-brk=9121 ./node_modules/mocha/bin/_mocha --no-timeouts --exit

You can launch the built-in IDE debugger by selecting Run > Debug in main menu and selecting newly created configuration in the popup.

Debugging in Visual Studio Code

Create Node.js run configuration (configurations array in launch.json debugger configuration file). Fill it in with the following:

{
    "type": "node",
    "request": "launch",
    "name": "Debug e2e tests",
    "program": "${workspaceFolder}/node_modules/suitest-js-api/lib/testLauncher/index.js",
    "args": [
         "interactive",
         "--inspect-brk=[port]",
         "[command]"
    ],
    "cwd": "${workspaceFolder}",
    "autoAttachChildProcesses": true,
    "console": "integratedTerminal"
}

[port] is any port you'd like debugger to listen to and [command] is a Node.js script you want to debug. Then run the newly added configuration

For a more complex [command], such as the commands that require spaces to execute correctly you will have to split the args members individually. Take the following example for instance:

"/node_modules/cucumber/bin/cucumbeer-js features/**/*.feature --require build/step-definitions/**/*.js --require build/cucumber/**/*.js"

The configuration would look like this:

{
    "type": "node",
    "request": "launch",
    "name": "Debug e2e tests",
    "program": "${workspaceFolder}/node_modules/suitest-js-api/lib/testLauncher/index.js",
    "args": [
        "interactive",
        "--inspect-brk=9121",
        "node",
        "node_modules/lolipop/bin/candy-js",
        "features/**/*.feature",
        "--require",
        "build/step-definitions/**/*.js",
        "--require",
        "build/lolipop/**/*.js"
    ],
    "cwd": "${workspaceFolder}",
    "autoAttachChildProcesses": true,
    "console": "integratedTerminal"
}

Passing Node.js script

When debugging, make sure to pass the Node.js script to the Test Launcher and not a wrapper. For example, on Windows NPM would wrap any executables into CMD file, so passing node_modules/.bin/[executable] will cause syntax error.

Instead, reference JavaScript file from the package source. Like so:

suitest interactive --inspect-brk=9121 ./node_modules/[package]/[path-to]/[executable.js]