how to configure debugging in grunt-protractor-runner v5, protractor v4.0.14, and node v8.13 - protractor

i have recently transitioned on to a project to re-architect our entire enterprise protractor code base. we use node v8.13, protractor v4.0.14, and grunt-protractor-runner v5. i would be open to debugging in vscode or chrome.
here is how i am configuring...
vscode launch.json
{
"type": "node",
"request": "launch",
"name": "Pro Debug",
"program": "${workspaceRoot}/node_modules/protractor/bin/protractor",
"args": ["${workspaceRoot}/ConvertedJSFiles/tests/config/conf.js"],
}
grunt.js
default: {
options: {
keepAlive: true,
debug: true
}
},
exampleTest.ts
it( '2#Click in Sign in to your account', async function () {
browser.pause();
debugger;
await commonMethods.beforeAll();
landingPage.logIn();
expect( browser.getCurrentUrl() ).toContain( 'login' );
} );
when attempting to debug in chrome, i execute with the command 'grunt'. the test seems to fail at the point where i have entered the 'debugger' statement. i am not positive, but i think this error is caused by protractor as protractor is what spawns a node process.
>> (node:13476) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
>> Debugger listening on ws://127.0.0.1:9229/ff1f9827-a76b-4400-9d0e-b0cec6912508
>> For help see https://nodejs.org/en/docs/inspector
>> (node:13477) [DEP0068] DeprecationWarning: `node debug` is deprecated. Please use `node inspect` instead.
>> Port 9229 is already in use. Please specify another port to debug.
when attempting to debug with vscode i receive the following error. i think this might be due to vscode executing the conf.js without having started protractor.
[16:57:06] E/runner - Unable to start a WebDriver session.
logger.js:170
[16:57:06] E/launcher - Error: UnsupportedOperationError: unknown command: Cannot call non W3C standard command while in W3C mode
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'US8525RT.local', ip: 'fe80:0:0:0:cdc:1e02:9f9f:9858%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.4', java.version: '1.8.0_241'
Driver info: driver.version: unknown
at Object.checkLegacyResponse (/Users/jayce.tan/Code/ui-automation-ts/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:639:15)
any help would be much appreciated. thanks!

Try like this
Note: if you are using outfolder for builded ts file to js, correct the path.
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"stopOnEntry": false,
"program": "${workspaceRoot}/node_modules/protractor/bin/protractor", // path the protractor node modules.
"args": [
"${workspaceRoot}/build/config/config.js" // path to compiled protractor configuration file.
],
"preLaunchTask": null,
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/build/**/*.js" ]
}
]
}
After that set breakpoints in the visual studio code and debug the program.
If you still have issues with W3C just disable it
Proractor
config.js
Note: adapt it to your needs this is just example how to disable w3c
capabilities: {
browserName: 'chrome',
'goog:chromeOptions': {
w3c: false,
args: [] // args if required.
}
}

Related

Can I run and debug deno project in VSCode?

I'm new to both typescript and deno, also vscode.
Firstly, I tried it with vscode and failed, and then tried with IntelliJ.
I can run and debug simple .ts file in Intellij with deno plugin.
But I want to know how to do this in vscode(also installed deno plugin, https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno).
My settings are...
.vscode/settings.json
{
"deno.enable": true,
"deno.lint": true,
"deno.unstable": true
}
.vscode/launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"request": "launch",
"name": "Launch Program",
"type": "pwa-node",
"program": "${workspaceFolder}/main.ts",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": [
"run",
"--unstable",
"--inspect",
"--allow-all"
],
"attachSimplePort": 9229
}
]
}
Example code
console.log("Hello, World!");
When I run this using by Run without Debugging
just shows like below image but expected to output Hello, World!.
and also seems debugging is not working.
Please help.
Debugging with --inspect does not work for relatively short programs, because it does not wait for the debugger to connect. So when running short programs the execution finishes before VS Code connects to the inspector. On larger programs this won't be an issue.
For debugging Deno programs that are only a couple of lines long, two options are given in this thread:
Use --inspect-brk instead of --inspect, this should allow enough time for the debugger to connect and hit breakpoints
Add some time delay to the code when debugging, for example:
const _sleep = async () => {
await new Promise(resolve => setTimeout(resolve, 2000));
}
await _sleep();
console.log("Hello World!"); <-- Here, you could add a breakpoint
To Run without Debugging, you can also either add --inspect-brk, but you will have to press F5 or click 'Continue' once the session has started. Or, you can use --inspect and add the sleep function

How to load symbol while debugging with GDB in VSCODE

Environment: WSL Ubuntu20.04 on Windows 10
GDB: gdb-multiarch (GNU gdb 9.2)
VSCODE version: 1.67.0
I'm trying to debug with GDB on VSCODE.
If I use command-line in Ubuntu to connect with GDB server and load symboal to my target device. It works normally.
$gdb-multiarch main
$(gdb)target remote:2331
$(gdb)load
$(gdb)c
Screenshot on Ubuntu command-line (Works normally)
However, I wanna do the same thing on VSCODE.
After modifying my launch.json file, the GDB debugger in VSCODE can only "attach" to my target device. There is no any symbol loaded. Here is my launch.json.
"configurations": [
{
"name": "GDB Launch",
"type": "cppdbg",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/main",
"stopAtEntry": true,
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb-multiarch",
"miDebuggerServerAddress": "localhost:2331"
},
}
]
Did I miss any propertey which needs to be filled in the configurations?
Thanks for any comments and helping:)
You can open logs to see what happened:
"logging": {
"moduleLoad": true,
"engineLogging": true,
"trace": true
},
There may be some configurations that affect the symbol load, such as solib-search-path, sysroot, you can check and add the configs in setupCommands
"setupCommands": [
{
"description": "Set sysroot ",
"text": "set sysroot <path_to_sysroot>"
},
{
"description": "Set solib",
"text": "set solib-search-path <path_to_solib_search_path>"
}
]

Debug FastAPI application in VSCode

i'm trying to debug an application (a web api) that use FastAPI (uvicorn)
I'm also using poetry and set the projev virtual environment in vscode.
i read this tutorial to setup uvicorn and this one to setup vscode but i think i'm doing something wrong in set it up.
I tried to setup the launch.json both as python: module and python: current file
The problem seems that it doesn't recognize the project structure cause when i run the debug it stopped in an import statement with this error:
Exception has occurred: ImportError
attempted relative import with no known parent package
This is my current launch.json configuration:
"configurations": [
{
"name": "Python: local debug",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/src/topic_service/service/__init__.py",
"args" : ["--port", "8000"]
},
]
I also tried to add a .env file setting PYTHONPATH:
PYTHONPATH=.:${PYTHONPATH}
Locally i run the application as follow:
poetry run uvicorn src.main:app --port 8080 --reload
Does anyone know how to correctly setup vscode to debug an uvicorn application?
Thank you
UPDATE:
I also tried what this article says. the debugger seems to start but nothing happen (no breakpoint is triggered)
Try this configuration.
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "uvicorn",
"args": ["src.main:app","--reload"]
}
Likewise you provide uvicorn module with necessary args during development of FastAPI application, you need to configure your launch.json located in .vscode directory with respective values.
I did a write up for custom project configurations to debug FastAPI in VS Code here
Suppose you issue the following command to run FastAPI on uvicorn server with args mentioned as below
uvicorn main:app --reload --port 8000
then your launch.json should have module with value of uvicorn and each of the args separated by space as items of the args array.
"module": "uvicorn",
"type": "python",
"request": "launch",
"args": [
"main:app",
"--reload",
"--port",
"8000"
],
"env": {
"usersecret": "some$Ecret",
}
You can have this launch.json file in .vscode and then modify the args array in the JSON configuration as per your project structure.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: FastAPI",
"type": "python",
"request": "launch",
"module": "uvicorn",
"env": {
"db_username": "postgres",
"db_password": "secret",
"host_server": "localhost",
"database_name": "fastapi",
"ssl_mode": "prefer",
"db_server_port": "5432"
},
"args": [
"main:app",
"--reload",
"--port",
"8000"
]
}
]
}
For me worked with this configurations:
On Debug section on VSCode, choose create launch.json option. Probally it will open launch.json on .vscode folder in your root folder explorer
like this, inside of launch.json put this:
"version": "0.2.0",
"configurations": [
{
"name": "Python: FastAPI",
"type": "python",
"request": "launch",
"module": "uvicorn",
"cwd": "${workspaceFolder}/<folder to your main.py>",
"args": [
"main:app",
"--reload",
"--port", //these arg are optional
"3003"
]
}
]
}
Now , just run your debugger and have a nice day!
Edit: The cwd ensure that your debbuger will find the right path to your main.py file. So, for whos use multiple debuggers or uses outside vsCode with launch.json it's a nice choice use it.
The quick and easy way: launch debugger F5 and then select FastAPI Debug Configuration:
(p.s. this works on the VSCode Insiders; haven't tried it on a regular version)
The way i debug is quite basic, hope it helps
i have .py file with this config:
import uvicorn
from app.main import api
if __name__ == "__main__":
dev = 1
if dev==0:
#use this one
uvicorn.run(api, host="127.0.0.1", port=5000, log_level="info")
if dev == 1:
#or this one
uvicorn.run('app.main:api', host="127.0.0.1", port=5000, log_level="info", reload=True, debug=True)
if dev == 2:
uvicorn.run('app.main:api', host="127.0.0.1", port=5000, log_level="info", workers=2)
and run the file with the vscode debugger, the important thing is to run the app with the debug flag because otherwise the debugger skips the breakpoints (at least in my case)

Debugging in VS Code using Jasmine framework (for Protractor)

I'm trying to debug in VS Code.
I've created the launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/conf/conf.js",
}
]
}
I'm using Jasmine and in my conf.js file (I'm using the file from the example when I installed Protractor), it starts with exports.config = { but it has 3 dots showing under it. When I click on the light bulb, it says "Convert to ES6 Module"
When I debug, it doesn't step into the code and just jumps to the end, even if I put breakdowns.
My conf.js file:
exports.config = {
directConnect: true,
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine',
specs: ['../specs/horses.js'],
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
},
};
When I run: protractor .\conf\conf.js in the Terminal, it works fine.
I have a non-angular page.
Update
I misunderstood your original question so here is a config that should work. Basically the program property needs to point to protractor and you pass your conf.js using the args property
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/node_modules/protractor/bin/protractor",
"args": ["${workspaceRoot}/conf/conf.js"],
"outFiles": [ "${workspaceRoot}/out/*.js" ]
}
]
}
See this article and this previous question for more information.
Original Incorrect Ans
The config file is exporting an object and therefore only has one action that can be debugged and that is export of the config object itself. The properties you are exporting, like specs, jasmineNodeOptions are called at different times during the setup process when protractor launches and not actually doing anything at the time they are exported. If you introduced some executable code in a lifecycle hook, like a beforeLaunch or onPrepare and tried to debug that it would likely work as you are expecting

How to start both Angular app and WebApi service from VSCode on F5 or Ctrl+F5

I have top-level folder Homepage with the following structure:
--Homepage
----Client <- Angular app, created with `ng new` command
----Server <- .NET Core WebApi, created with `dotnet new webapi` command
I open VSCode at Homepage level:
I have these extensions installed:
Question
If I want to use single VSCode environment to work on both projects, Client and Server, is it possible to bind F5 (or Ctrl+F5) to start both projects together?
Client app I start using ng serve (it will run on http port 4200)
Server app I start using dotnet run (it will run on https port 5001)
I have just one common .vscode folder on Homepage (root level):
By default, when first created, the content of launch.json was this:
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/Server/bin/Debug/netcoreapp2.1/Server.dll",
"args": [],
"cwd": "${workspaceFolder}/Server",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
,]
}
So, when I press F5 it builds and start the Server app, the page opens at https://localhost:5001, from there I can navigate to https://localhost:5001/api/values and see WebApi works.
But the Client app doesn't start at all.
So, I thought if I add Debugger for Chrome extension's settings to launch.json, it should work, so I clicked on Add Configuration and added corresponding section:
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}"
},
I changed port from 8080 to 4200, since ng serve hosts on port 4200
But it does not start the Client app.
Please advice. Thanks
I have similar (node.js for API) and spent quite some times couldn't resolved, for example use && or &. Result is either API up or Angular up, never the both.
Anyway I finally realized have both Api and UI in the same folder/project/solution is not practical. An API is not specific to an UI, it's a universal DLL/service, should be siting somewhere by itself. So I separated them into two diff folders and have 2 VSC instances to run them:
start the API in debug mode
in 2nd VSC, run ng serve and let it take time to build
when ng says "Compiled successfully" go to launch.json to start the debug entry associated with Chrome
they work perfectly.