The following document describes how to debug the step-implementations, server-side (CDS Node.js Runtime) and browser code (SAP UI5 and the steps browser extension: browser.js) using VSCode.
Debugging the step-implementations with VSCode is possible in two ways.
Use the following command to start javascript debug terminal: Keyboard-shortcut: Ctrl+Shift+P Command: Debug: JavaScript Debug Treminal
Now you can add breakpoints in the steps code and start the tests in the new terminal tab.
File: ./.vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "SFlight Features",
"type": "node",
"request": "launch",
"program": "npx",
"args": ["cucumber-js","test/features/sflight"],
"env": {
"CWD": "${workspaceFolder}",
"CDS_USERNAME": "alice",
"CDS_PASSWORD": "admin",
"CDS_SERVICE_DIR": "tmp/cap-sflight"
},
"skipFiles": [
"<node_internals>/**"
],
"outputCapture": "console",
"console": "integratedTerminal"
}
]
}
Add breakpoints in the steps code and run the new target in the “Run and Debug” tab of VSCode. You can add additional cucumber-js arguments as you wish, and also change the environment variables to values applicable for your project.
This section describes the possibilities to debug the CDS Node.js Runtime. The CDS Server will be started as a new process via the provided steps. In order to debug the code, you can follow the same procedure as for the Steps then you can add breakpoints in the CDS Nodejs Runtime code.
VSCode offers attaching to and debugging of browser sessions. Add a new launch configuration as follows:
File: ./.vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"name": "Bookshop: Attach to browser",
"request": "attach",
"port": 9222,
"webRoot": "${workspaceFolder}/tmp/cloud-cap-samples/fiori/app",
"urlFilter": "http://localhost:4004/*"
}
]
}
Description of the parameters:
When the tests are started with debugging enabled via CDS_CUCUMBER_DEBUG, the CDS server is running, selenuim is initialized and the step-library is loaded into the browser, the execution of the steps will wait until the VSCode Debugger is attached to the browser session but only in case the environment variable CDS_CUCUMBER_WAIT_DEBUGGER is set.