devcontainer.json. Breakpoints not working - vscode-remote

I launch a debug session through the Module option and specifying a folder, the app starts up and responds to requests - and code changes are seen when other services interact with mine by calling into it (print statements show the change in the terminal output of the IDE), however, breakpoints are not hit. How come?
My devcontainer.json file looks like this:
{
"name": "Existing Dockerfile",
"build": {
"dockerfile": "../Dockerfile",
"context": "../.",
"target": "deploy"
},
}
My Dockerfile does the usual stuff and runs our app with python -m app:
FROM python:3.9.3-slim AS deploy
COPIES SOME FILES
CMD ["python", "-m", "app"]

My problem was the version of python that was pulled in.
In my Dockerfile, I had to change:
FROM python:3.9.3-slim AS base
to
FROM python:3.9.4-slim AS base
Then breakpoints started working.

Related

binding.pry not works with command bin/dev

binding.pry not works(console input not available) if i start the server with bin/dev command. It only works with bin/rails s command.
I understand it has something to do with foreman and Procfile.dev, but I don't know how.
Is this a bug or is it supposed to be like this?
A popular approach is to use pry-remote which is useful in some ways I didn't expect: https://github.com/Mon-Ouie/pry-remote.
pry-remote opens a remote terminal, so where you drop your debugger line (binding.remote_pry in the case of pry-remote), you'll open another terminal and enter the debugging session by calling pry-remote in your shell.
I get this is a bit more complicated, I got used to it, and was able to get away from the noise logged by other process with Foreman.
I use rdbg + vscode remote debug and it works fine.
Update Procfile.dev like this to run rdbg with rails server and set a socket file
web: rdbg --command --nonstop --open=vscode --sock_path=tmp/sockets/rdbg.socket -- bundle exec bin/rails server
Install VSCode Ruby rdbg Debugger, configure launch.json like this
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to rdbg Process",
"type": "rdbg",
"request": "attach",
"debugPort": "${workspaceRoot}/tmp/sockets/rdbg.socket",
},
]
}
Now, VSCode will launching with debugger enable while you run bin/dev, or you can run debugger in vscode by F5 anytime

How to access cypress environment variable passed in from command line

Scenario:
I have cypress tests that we run on multiple environments( more than 8), each environment with a separate domain, so we have configured all the domains in cypress.json file under env, now I need to pass the domain dynamically, i.e, from command line and be able to pick it and run the tests on respective domain. but I'm not sure how I can grab that value passed in command line.
Note: I have tried process.env method but did not work.
Code looks like this :
Cypress.json
{
"env": {
"domain1": xyz.com,
"domain2": abc.com,
"domain3": 123.com
}
}
package.json :
{
scripts: {
"test": "npm run cypress open --env domian= $1
}
}
$1 is suppose to get me the command line argument"
From my files under integration folder, Cypress.env(Cypress.env().domain) will/should fetch me the right domain.
However I'm receiving $1 as domain value.
Please help.
Can you share how $1 is supposed to reference the env file? I don't understand that part.
In the meantime, here is an alternative answer to your problem. (just tested it out)
You can write several test scripts which each provide a different domain address.
{
scripts: {
"test1": "npm run cypress open --env domian=xyz.com",
"test2": "npm run cypress open --env domian=abc.com",
"test3": "npm run cypress open --env domian=123.com"
}
}

Setting up Protractor to automatically open and close Selenium

I'm trying to set up E2E testing on one of my windows asp.net (mvc->angular)projects.
We use team city to do our builds so I want my configuration to work on my box and on the build box.
I'm stuck trying to set up the values in conf.js so that protractor will automatically start up and stop when protractor needs it...
I run it via a batch file like this:
call npm install -g
call C:\Users\brown.ericw\AppData\Roaming\npm\protractor conf.js
pause
Everything was working fine when I was running selenium manually.
But I just can't figure out the right conf.js to get selenium started and shut down automatically(Stopping it in the bat file was not always effective, despite several different approaches).
I've tried lots of different combos, but I'm stumped.
Here is the relevant portion of my conf.js:
exports.config = {
seleniumjar: '.\node_modules\protractor\selenium\selenium-server-standalone-2.45.0.jar',
//seleniumArgs: '-Dwebdriver.chrome.driver="\node_modules\protractor\selenium\chromedriver',
//chromeDriver: '.\node_modules\protractor\selenium\chromedriver',
//chromeDriver: '.\node_modules\protractor\bin\webdriver-manager',
chromeDriver: 'C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protractor\selenium\chromedriver',
//seleniumAddress: 'http://localhost:4444/wd/hub',
specs: [
'e2eTests/*.js'
],
I have protractor installed under my project folder, so I run npm install, so I know it's all kosher at the beginning of the run on the build/test server.
Here is the error I'm getting.. Clearly I can't I figure out the setting to get get it pointing towards the chrome driver...
D:\TFS\TACAdmin3G_Test_E2E>call
C:\Users\brown.ericw\AppData\Roaming\npm\protra ctor conf.js
[launcher] Process exited with error code 1
C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protractor\node_modules\q\
q.js:126
throw e;
^ Error: Could not find chromedriver at D:\TFS\TACAdmin3G\node_modules\protractor\ selenium\chromedriver
at LocalDriverProvider.addDefaultBinaryLocs_ (C:\Users\Brown.ericw\AppData\R
oaming\npm\node_modules\protractor\lib\driverProviders\local.js:54:15)
at LocalDriverProvider.setupEnv (C:\Users\Brown.ericw\AppData\Roaming\npm\no
de_modules\protractor\lib\driverProviders\local.js:71:8)
at Runner.run (C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protrac
tor\lib\runner.js:265:31)
at TaskRunner.run (C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\pro
tractor\lib\taskRunner.js:123:19)
at createNextTaskRunner (C:\Users\Brown.ericw\AppData\Roaming\npm\node_modul
es\protractor\lib\launcher.js:220:20)
at C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protractor\lib\laun
cher.js:243:7
at _fulfilled (C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protrac
tor\node_modules\q\q.js:797:54)
at self.promiseDispatch.done (C:\Users\Brown.ericw\AppData\Roaming\npm\node_
modules\protractor\node_modules\q\q.js:826:30)
at Promise.promise.promiseDispatch (C:\Users\Brown.ericw\AppData\Roaming\npm
\node_modules\protractor\node_modules\q\q.js:759:13)
at C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protractor\node_mod
ules\q\q.js:573:44
I tried changing the slashes because of the space in the path up there and it changed back to the normal path:
Error: Could not find chromedriver at D:\TFS\TACAdmin3G\_Test_E2E\..
which doesn't give me the whole path.
chromedriver.exe is in all the locations in the various commented version in the conf.js. but no joy truing each of them.
I need to use relative pathing because the root folder on my box is different than the one on the build server.
Any help is greatly appreciated.
Forgot to say I looked at this one:Protractor does not find chromedriver: The driver executable does not exist:
and this one
how to close selenium webdriver at end of test?
and wasn't able to figure it out
Okay every body, for those who follow ,here is the answer to the problem and why I think this is what works. This answer works in my node.js project in VS(have to add the packages here too) , in a batch file on my dev box, and in team city.
I added NPM INSTALL to my build script, so that once the code is pulled down it immediately puts all the js packages in the code directories.
Then I added the selenium server stand lone package to my project(and package.json so I knew exactly where the jar is. I added it as a --Save(write to config)and as a --Dev (add in the dev section, ie include in node_models in my code folders)
Then I have this in my conf.js
> exports.config = {
> seleniumServerJar: 'node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-2.45.0.jar',
> chromeDriver: './node_modules/protractor/selenium/chromedriver',
> //seleniumAddress: 'http://localhost:4444/wd/hub',
There are several subtle but important changes.
1
seleniumServerJar vs seleniumjar - there are a lot of examples out there using seleniumjar... so I'm guessing the standard tag changed at some point, but seleniumServerJar is what is shown on the documentation pages and it's what works.
2
/ vs \ as the slash in paths.. this one was tricks because when I used backslash, it didn't complain, the only difference was it truncated the path with a ... in the error messages, but when i dug in deeper, backslashes are getting removed from the part of the path you enter... even the part the code uses based on .\ has back slashes... so only use forward slashes in paths in these tags in conf.js
3
Relative pathing with ../node_modules vs .\node_modules vs node_modules..., there are examples out there with all of these used, once I was able to see the full paths being generated I figured out that ../ wasn't what I wanted.. so I played with it and got it working with one ./ and one nothing... why they both didn't work with ./ I don't know.. but it works.(sorry about that)
Just in case it helps you here is my package.json
{
"name": "_Test_e2e",
"version": "0.0.0",
"description": "_Test_e2e",
"main": "app.js",
"author": {
"name": "Brown.EricW",
"email": ""
},
"devDependencies": {
"jasmine-reporters": "^1.0.0",
"protractor": ">=0.14.0-0 <1.0.0",
"selenium-server-standalone-jar": "^2.45.0"
},
"scripts": {
"postinstall": "webdriver-manager update"
},
"dependencies": {
"jasmine": "^2.3.1",
"jasmine-reporters": "^1.0.0",
"protractor": "^2.1.0"
}
}
Running real browsers on build server probably isn't a good solution. If you have a dedicated Teamcity node, then a headless browser implementation like PhantomJS could be an option. You need to make sure that PhantomJS is installed on your dedicated node and its executable is placed somewhere in the PATH. Also make sure to set browser name to be phantomjs instead of chrome.
Secondly you could setup a Selenium grid and setup nodes with different browsers you want to test. From build server you would run tests on the remote selenium grid on the browser of your choice. There are paid, third part options like sauce labs or browser stack if you wish to go that route.
I would tend to go with second option since PhantomJS is not a real browser and you may have requirement of testing your application on different browsers/platforms etc.

Run AngularJS Tutorial with VSCode

I was hoping to try VSCode on the AngularJS tutorial, say step 1, and get debugging and building working.
I was able to get it running, but it's a bit of a hack and VSCode doesn't like it.
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch app.js",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "app\\js\\app.js",
// Automatically stop program after launch.
"stopOnEntry": true,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": "run.bat",
// Environment variables passed to the program.
"env": { }
},
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 5858
}
]
}
I get an "Error Connection failed" even though it is actually running in a separate command prompt window.
Is there a way to for VSCode to debug a simple application like this that only uses package.json start like this:
"start": "http-server -a 0.0.0.0 -p 8000"
Thanks,
Derek
Visual Studio Code supports only Node and Mono debugging, it does not support debugging client JavaScript in the browser.
If you want debug Javascript in the browser, use the browser tools. If you want try out node.js debugging support in VSCode. Start with a sample node.js or express app, then follow the direction in Visual Studio Code website on setting up debugging.
If you would like to see Visual Studio Code supporting debugging, you can vote it up in user voice.

How can I debug a PHP CLI script with xdebug?

I haven't quite figured this out. EVERY piece of documentation I've found covers how to use xdebug to debug scripts running in Apache. I need to debug a php CLI script.
So, for instance, how do I pass the XDEBUG_SESSION_START variable in to get xdebug to kick on?
I'm specifically trying to debug a CakePHP shell. So if anyone has any additional insight into that I'd be very appreciative.
Thanks.
There is a couple of notes about that in Xdebug's manual, like, for instance (quoting) :
export XDEBUG_CONFIG="idekey=session_name"
php myscript.php
If you are using Eclipse PDT to develop and debug your PHP scripts, there is not much difference between Apache or CLI : the configuration lloks quite the same, you just don't have to configure a web server, nor indicate an URL ; instead, you have to indicate the path to the PHP executable.
About the XDEBUG_SESSION_START variable : well, you launch the whole script in "debug-mode", so you don't have any notion of "debugging-session", I'd say.
For instance, here's what Window > Preference > PHP > PHP executables looks like for me right now, and, on the right, what I get when clicking on the Edit button of the first one :
(source: pascal-martin.fr)
(source: pascal-martin.fr)
And the debug configurations window :
(source: pascal-martin.fr)
And launching the debugging: it just works :
(source: pascal-martin.fr)
Hope this helps :-)
Else, what specific problem do you encounter ?
If you're using bash (or similar shell), this little script might come in handy:
alias drush-debug=drd
function drd {
export XDEBUG_CONFIG="idekey=cli_session"
export SERVER_NAME="developer.machine"
export SERVER_PORT="9000"
drush "$#"
unset XDEBUG_CONFIG
unset SERVER_NAME
unset SERVER_PORT
};
or as suggested by the commentators below
alias drd='XDEBUG_CONFIG="idekey=PHPSTORM" drush "$#"'
This way you don't have to manually set and unset the trigger variable each time you want to debug.
simply put the following section to your php.ini
[XDebug]
xdebug.max_nesting_level = 200
xdebug.remote_enable=1
xdebug.remote_port=9000
;xdebug.profiler_enable=1
xdebug.idekey=PHPSTORM
xdebug.remote_autostart=1
and replace PHPSTORM with your ide key
For Windows and Visual Studio Code here's how to proceed:
Download xdebug from https://xdebug.org/download. For example php 7.4 Windows 64bit https://xdebug.org/files/php_xdebug-2.9.5-7.4-vc15-nts-x86_64.dll
Copy the xdebug dll to your php extensions dir (ext).
Add to the end of php.ini
[XDebug]
zend_extension=php_xdebug-2.9.5-7.4-vc15-nts-x86_64.dll
xdebug.remote_enable=1
xdebug.remote_autostart=1
Open VSCode and install https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug
Open the project workspace in VSCode, go to Run tab, click the cogwheel and add these lines
{
"name": "listen CLI",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "run CLI",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
Place a break point in the script you want to debug
Select "run CLI" and click "Start Debugging"
Happy debugging!
PHP configuration:
zend_extension=xdebug.so
xdebug.remote_handler=dbgp
xdebug.mode=debug
On my system it is file /etc/php/conf.d/xdebug.ini. Could be in the main php.ini too.
If I want to run a script with XDebug, I pass an environment variable inline:
XDEBUG_SESSION=1 php arguments

Resources