13

I was trying to debug Cucumber scenarios in Visual Studio code and made below changes in the launch.json.

{
            "name": "e2e",
            "type": "node",
            "request": "launch",
            "program": "${workspaceRoot}\\node_modules\\.bin\\cucumber-js",
            "stopOnEntry": false,
            "args": ["--no-timeouts", "--colors"],
            "cwd": "${workspaceRoot}",
            "runtimeExecutable": null,
            "outFiles": [
                "${workspaceRoot}\\features\\step_definitions\\*.js"
            ]
},

However, I am not able run a debug session using the above configuration. The step def. files I created in JavaScript. So, just need a help on the script above if that looks fine?

  • What breakpoint? Where? – ifconfig Oct 19 '17 at 16:14
  • Breakpoint somewhere in the code! The question above is to validate my config. script in `launch.json` for cucumber. Hope it is clear to you now.. –  Oct 19 '17 at 16:18

6 Answers6

15

You could try below configuration to make your debug working in VS Code. In the outFiles give your feature file path.

{
    "name": "e2e",
    "type": "node",
    "request": "launch",
    "program": "${workspaceRoot}/node_modules/cucumber/bin/cucumber.js",
    "outFiles": [
        "${workspaceRoot}/features/*.feature"
    ]
}

============================================
UPDATE AS OF cucumber ^5.0.2:

{
    "name": "NPM Cukes",
    "type": "node",
    "request": "launch",
    "console": "integratedTerminal",
    "program": "${workspaceRoot}/node_modules/cucumber/bin/cucumber-js",
    "args": [
        "path/to/features/**/*.feature",
        "-r",
        "path/to/steps/**/*",
        "--tags",
        "@your-tags"
    ]
}

If you want to debug only CURRENT feature, add this to launch.json

{
    "type": "node",
    "request": "launch",
    "program": "${workspaceFolder}/node_modules/.bin/cucumber-js",
    "args": ["${relativeFile}"],
    "name": "Cukes current",
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen",
    "windows": {
        "program": "${workspaceFolder}/node_modules/cucumber/bin/cucumber"
    }
}   
vilkg
  • 625
  • 6
  • 7
Mukesh Rawat
  • 2,047
  • 16
  • 30
4

Tweaking the answer from Mukesh Rawat plus ensuring additional file paths were correct, got it working for me, :

Launch.json

{
    "name": "DebugMode",
    "type": "node",
    "request": "launch",
    "program": "${workspaceRoot}/node_modules/cucumber/bin/cucumber-js",
    "args": [
        "${workspaceRoot}/features/*.feature",
        "--tags", "@debug"
    ]
}

Workspace.json

{
    "cucumberautocomplete.steps": [
        "features/steps/*.js"
    ],
    "cucumberautocomplete.syncfeatures": "features/*.feature",
    "cucumberautocomplete.strictGherkinCompletion": true,
    "settings": {},
    "folders": [
        {
            "path": "/Users/{me}/Documents/{project folder}/{project name}"
        }
    ]
}

Package.json

"scripts": {
    "debug": "node --inspect=1337 --debug-brk --nolazy node_modules/cucumber/bin/cucumber-js --tags @debug --format json:./reports/report.json",

CucumberTest.feature

@debug
Scenario: Validate I can get debug working
Benny Meade
  • 602
  • 10
  • 25
3

When working with Ruby, it could be used on this way to run specific feature files:

{
    "name": "Cucumber",
    "type": "Ruby",
    "request": "launch",
    "cwd": "${workspaceRoot}",
    "program": "${workspaceRoot}/bin/cucumber",
    "args": [
        "--tags", "@Mytags",
        ]
}
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
0

This works

{
    "name": "DebugMode",
    "type": "node",
    "request": "launch",
    "program": "${workspaceRoot}/node_modules/cucumber/bin/cucumber-js",
    "args": [
        "${workspaceRoot}/features/*.feature",
        "--tags", "@debug"
    ]
}
General Grievance
  • 4,555
  • 31
  • 31
  • 45
Jagadeesh
  • 41
  • 1
  • 8
0

Here's the simplest way I've found to run Cucumber.js in the VS Code debugger:

  1. Set JavaScript debugger auto attach to "onlyWithFlag" (Ctrl+Shift+P, type "Toggle Auto Attach")
  2. Run Cucumber.js as follows: node --inspect ./node_modules/.bin/cucumber-js <args...>
  3. For convenience, set an NPM run script in your test project for "debug" so you can run this as npm run debug -- <args...>
Steven Hunt
  • 2,321
  • 19
  • 18
0

with the latest Cucumber, Playwright, typescript as of January 2023 - F5 (run in VSCode) - set debugger in ts step files and use .vscode/launch.json (you might tweak your reports location)

{
  "version": "0.1.0",
  "configurations": [
    {
      "name": "debugMode",
      "type": "node",
      "request": "launch",      
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen", 
      "program": "node_modules/@cucumber/cucumber/bin/cucumber-js",
      "args": [
        "./features/*.feature",
        "--require-module",
        "ts-node/register",
        "--require", 
        "./steps/*.steps.ts",        
        "--tags",
        "@demoX",       
        "--format", "progress",
        "--format", "json:./Reports/cucumber_report.json"    
      ]
    }
  ]
}
Sasha Bond
  • 984
  • 10
  • 13