How to debug Cucumber in Visual Studio Code (VSCode)?

前端 未结 4 1835
既然无缘
既然无缘 2021-01-02 09:57

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

{
            \"name\": \"e2e\",
              


        
相关标签:
4条回答
  • 2021-01-02 10:28

    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",
            ]
    }
    
    0 讨论(0)
  • 2021-01-02 10:42

    This works

    {
        "name": "DebugMode",
        "type": "node",
        "request": "launch",
        "program": "${workspaceRoot}/node_modules/cucumber/bin/cucumber-js",
        "args": [
            "${workspaceRoot}/features/*.feature",
            "--tags", "@debug"
        ]
    }
    
    0 讨论(0)
  • 2021-01-02 10:50

    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"
        }
    }   
    
    0 讨论(0)
  • 2021-01-02 10:54

    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
    
    0 讨论(0)
提交回复
热议问题