@fhilton’s answer used to work, but with newer versions of Cypress, it will cause Chrome to not be able to connect to the test runner and not run any tests. Use this instead:
-
If you or any of your co-workers develop in Windows, run
npm i -D cross-env. -
In package.json add a script to start the Cypress test runner (or if you already have a script that says something like
cypress openthen just modify that). You want the script to set theCYPRESS_REMOTE_DEBUGGING_PORTenvironment variable to something like9222before it runscypress open. Since I use Windows, I use thecross-envnpm package to set environment variables. Therefore, the script in my package.json looks like"scripts": { "cypr": "cross-env CYPRESS_REMOTE_DEBUGGING_PORT=9222 cypress open", },I got the idea of doing that from here and here. The rest of this answer is mostly what @fhilton wrote in his answer so most of the credit goes to them.
-
Add the following to the list of
configurationsin your launch.json (note the same port as above){ "type": "chrome", "request": "attach", "name": "Attach to Cypress Chrome", "port": 9222, "urlFilter": "http://localhost*", "webRoot": "${workspaceFolder}", "sourceMaps": true, "skipFiles": [ "cypress_runner.js", ], }, -
Put the word
debuggerin your test. See Cypress Doc on debugging. Or, if you are confident in your source maps, put a breakpoint in your code with vscode. -
Run
npm run cypr(or whatever you called your npm script) -
From the Cypress test runner, start your tests running in Chrome
-
Start the vscode debugger with your new “Attach to Cypress Chrome” configuration
-
Restart the test with breakpoint in it and debug away!