0

Adding the necessary config in my vscode launch.json file by adding breakpoint to my stepdef and debugging the test throws error and doesn't open up the debugger.

my launch.js file looks like this

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "protocol": "legacy",
            "address": "localhost",
            "port": 5859,
            "timeout": 20000,
            "name": "WebdriverIO",
            "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/wdio",
            "runtimeArgs": [
                "--debug=5859"
            ],
            "windows": {
                "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/wdio.cmd"
            },
            "restart": true,
            "cwd": "${workspaceRoot}",
            "console": "integratedTerminal",
            // This args config runs only the file that's open and displayed
            // (e.g., a file in test/spec/):
            "args":[
                "${workspaceRoot}/features/wdio-local.conf.js"
            ]
        }
    ]
}

i then added the following to the top of my wdio-local.conf.js file

exports.config = {
   debug: true,
   execArgv: ['--debug=127.0.0.1:5859'],

I then went ahead and added a couple of breakpoints to the step definition that hooks up to my feature file that navigates to a page. in theory, this should when the method 'open' is called.

I am using webdriverio v4 as test needed to be written in cucumber

I got my reference from the following sites:

http://blog.likewise.org/2017/02/debugging-a-javascript-webdriverio-project-in-vscode/

and

https://liesbeek.com/2018/08/03/debug-wdio-vscode/

both don't work.

We run our tests in terminal using npm run command and also pass in a couple of parameters i.e running testing with tags.

NODE_ENV=development T_ENV=staging npm run e2e-test-local -- --cucumberOpts.tagExpression='@404_error'

This all works fine. NOTE we also use a couple of variables.

help required on how to configure the vscode launch.json so that i can debug tests please. many thanks

1 Answers1

1

You wdio conf file looks good. Just update launch.json.

FYI it has limitation of using REPL the way you would use it in browser.debug();

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "WDIO",
            "program": "${workspaceFolder}/node_modules/.bin/wdio",
            "port": 5859,
            "protocol": "inspector",
            "args": [
                "wdio.conf.js",
                "--spec",
                "spec/some-folder/some-test-spec.js" // File which you would like to debug
            ],
            "internalConsoleOptions": "openOnSessionStart",
            "cwd": "${workspaceRoot}",
            "env": {
                "DEBUG": "1" 
                // use an environment variable to be able
                // to toggle debug mode on and off
            }
        }
    ]
}

Still trying to figure out how wdio 5 could be fully integrated with VS CODE Debugger.

Although this guy had it working with WDIO 4. And I feel like his article should help us to get WDIO 5 working with it as well.

Sergio13
  • 67
  • 9