How do I set up Cypress debugging in WebStorm? I can get a debugger statement in my code to pause execution in Chrome and debug using devtools, but nothing happens in WebStorm.
This is true whether I am running or debugging my configuration, which is simply npm run cypress (with my cypress open script). When debugging the run configuration, I don't get checkmarks on my breakpoints in WebStorm.
The WebStorm docs refer to selecting your configuration type from the menu but there's no Cypress in the menu.
Is this possible to do?
it is a bit of a process but when you are done it is worth it.
Just a couple notes:
I use it on Mac, Version: 2019.3.2, however it should be very similar.
And (at this time) you have to be running the Chrome browser, you cannot attach to electron.
First, in your package.json file you need to have some npm launch script (not technically necessary, but makes everything else stupid simple) here is a sample of mine:
"scripts": {
"start:ci": "serve --no-clipboard --listen ${PORT:-8080}",
"cypress:open:localhost": "ENV=localhost npm run cypress:open",
"cypress:open:dev": "ENV=dev npm run cypress:open",
"cypress:open:qa": "ENV=qa npm run cypress:open",
"cypress:open:staging": "ENV=staging npm run cypress:open",
"cypress:open:production": "ENV=production npm run cypress:open",
"cypress:open": "cypress open"
},
Next you need to setup a debug configuration for npm. On Mac that is under run->Edit Configurations...
Add a new configuration using the npm template (click the plus and choose npm)
The template will have a drop down for scripts, select your npm script (mine is set for cypress:open:qa) Then click apply.
Now when you launch the debuger it will open your cypress instance with debugging attached to cypress. However, you want to attach to the browser so you can debug your JS.
Start any test in chrome, then open a new tab (in cypress chrome instance) go to the chrome extensions site and add the Jet Brains chrome extension, here is the link:
https://chrome.google.com/webstore/detail/jetbrains-ide-support/hmhgeddbohgjknpmjagkdomcpobmllji?hl=en
This will apply it to the chrome version that cypress runs. When you are running your test you right click the JB icon and inspect in WebStorm.
This opens a new tab in your debug dialog box (default bottom left). Open the tab that says scripts in your https://yourproj... tab. Navigate in that dialog to integration file you want to debug, double click it. Slap in a break point and away you go.
There are two plugins that let your run cypress tests from Webstorm. Both let you select a single test and run it then see the result directly in webstorm.
The Pro version allow to debug tests in the cypress runner.
https://plugins.jetbrains.com/plugin/13819-cypress-support (free)
https://plugins.jetbrains.com/plugin/13987-cypress-support-pro (paid)
The pro version debugging capabilities:
You can run cypress as node job in webstorm.
For this:
Set the path to the cypress executable file
Select your folder as working directory
Add run options run --spec cypress/integration/Filters.feature
I am using cucumber so am giving a feature, if you use mocha use your run parameters the same as in the console.
Settings
Related
Since the WebStorm debugging extension for Chrome is deprecated, how would I debug a Cypress instance? How do I select the correct Chrome instance (the Cypress one) to attach to in the "JavaScript Debug" config?
You can try attaching via the Attach to Node.js/Chrome run configuration (similar to VSCode recipes in Debugging Cypress tests in Visual Studio Code), but, as I mentioned in my comment at Debug Cypress in WebStorm, it worked for me neither in Webstorm nor in VSCode...
Did you try the Cypress Support Pro plugin? According to https://docs.cypress.io/guides/tooling/IDE-integration#IntelliJ-Platform, it supports debugging from the IDE
I have a project build in TypeScript and I would like to use cypress run to run my unit test. Everything works when I trigger command line from terminal, but how can I set up cypress run with WebStorm IDE under Run/Debug Configuration? The only possibility is to set up npm command but my project is using pnpm not npm.
So how can I set up cypress run under Run/Debug configuration?
WebStorm doesn't provide any special support for Cypress (feel free to upvote and comment WEB-32819 to increase its priority and to be notified on updates). But you can still use Node.js run configurations to start your scripts.
I'd also suggest trying a third-party Cypress-Pro plugin
I can't debug my react native / expo app in WebStorm, but I can in Visual Studio Code.
I have a react native app that I can successfully run using expo. I set up the configuration according to the info on this site:
https://blog.jetbrains.com/webstorm/2018/02/webstorm-2018-1-eap-181-3263/#debugging-expo
When I click "run" or "debug" and "Debug JS Remotely" is turned off, the bundler builds a JS bundle and the app starts on my devices.
But once I turn on "Debug JS Remotely", the bundler only says:
Starting custom debugger by executing: : [my working directory] [my working directory again]
and never goes on to build the JS bundle.
After a short while, a red screen appears on the device, and it says:
Unable to connect with remote debugger
Timeout while connecting to remote debugger
onFailure
DevSupportManagerImpl.java:851
onFailure
WebsocketJavaScriptExecutor.java:83
run
WebsocketJavaScriptExecutor.java:142
handleCallback
Handler.java:790
dispatchMessage
Handler.java:99
...
The bundler doesn't say anything more than the message above.
As soon as I turn off remote debugging, the the bundler starts building again and finishes with
"Building JavaScript bundle: finished in ...ms"
as usual, but the device, again, shows the red screen with aforementioned messages, or doesn't show anything but the regular white screen with a message at the bottom saying "Downlading JavaScript bundle 100,00%". I either have to stop and restart within WebStorm or I have to close the expo app and re-open it. Either way will make the app start again on my device.
This is my first time working with javascript, react native, expo, so I am not sure, but it should be possible to debug in WebStorm directly, right? As mentioned, in Visual Studio Code everything including debugging works fine, so I don't think it's anything in the code. Maybe someone here has an idea where the problem lies?
node -v: v11.6.0
react-native -v: react-native-cli: 2.0.1, react-native: 0.57.1
Any help will be greatly appreciated! Thanks in advance!
PROOF
HOWTO
Looks like there's been an update to how you can setup Configurations since you tried.
Try changing the Bundler host to 127.0.0.1 and try again.
I just setup Webstorm v2020.2 yesterday to debug my Expo application and it is working as expected.
These instructions were all that I required: https://www.jetbrains.com/help/webstorm/react-native.html#ws_react_native_create_run_config
On the main menu, go to Run | Edit Configurations, click icons.general.add.svg and select React Native from the list. The Run/Debug Configuration: React Native opens.
Choose whether you want WebStorm to build and launch the application for you:
Select the Build and launch checkbox if you are launching your application for the first time or if you have updated its native code since the last run.
If your application uses Expo, clear the checkbox because this bundler takes care of the process itself.
If you selected the Build and launch checkbox, choose the target platform, Android or iOS. Depending on your choice, WebStorm will run the bundler with react-native run-ios or with react-native run-android.
Optionally, type the arguments to be passed to React Native, for example, specify the simulator type through the ‑‑simulator flag: ‑‑simulator="iPhone 4s".
In the Bundler host field, specify the host where the React Native bundler runs, the default value is localhost.
If you are using Expo, change the default bundler host to ensure successful connection with the debugger. This connection may fail because WebStorm by default uses localhost to start debugging while Expo expects 127.0.0.1 or an external IP address depending on what is selected in Connection field of the Metro bundler configuration. See Debugging a React Native application that uses Expo for details.
In the Bundler port field, specify the port on which the React Native bundler runs, by default 8081 is chosen, learn more from the React Native official website.
Choose the Node.js interpreter to use. This can be a local Node.js interpreter or a Node.js on Windows Subsystem for Linux.
Specify the path to react-native-cli and the working directory of the application. Optionally, type the environment variables for react-native run-android or react-native run-ios.
By default, WebStorm starts the React Native bundler automatically when you invoke the run/debug configuration. If you have already started the bundler from outside WebStorm, for example, from the command line, you can re-use it without stopping and restarting. Select your bundler in the Before Launch area and click Remove.
The issue is tracked at WEB-35719, please follow it for updates
I would like to add a configuration inside IntelliJ so that I can run it from the Run context menu (there is included Node.JS launcher but I couldn't find a "Command Line configuration launcher")
Also, is it possible to run the command line terminal as Administrator if ran from Windows ?
The command I would like to run is ember serve
Thanks for the help.
These are the steps:
Go to Run/Edit Configurations...
Add a new one for "Javascript Debug"
Fill Name with the name you want for the configuration, fill the URL with http://localhost:4200 and pick the browser you prefer
Then, in the second white box, add an external tool by clicking in the green plus button and selecting the option Run External tool
Add a new one clicking on the green plus button and fill the following fields: in Name the name you want for the external tool, in Program write ember (it's the command you are going to run), in Parameters write server or s as the options for the command and in Working directory write $ProjectFileDir$ if it's not written already to run it in the folder in which you are working with.
With all this, you should only need to press the play button and it should run and open the browser automatically with a tab directing to localhost:4200, where your ember server is running.
EDIT: I'm not using it on windows so I'm not sure if it will run the command as administrator. Probably running Intellij using "Run as Administrator" will do the job.
I have inherited a legacy project with 100s of tests, and dependencies defined within the pom.
All of the tests run when I execute a mvn clean install from the command line, but when I try to execute one of these tests in debug mode from within Intellij i get the following error.
java.lang.NoClassDefFoundError: Could not initialize class
How can I get intellij to recognise these dependencies when trying to run a test in debug mode from the ide?
I managed to solve this by simply changing the working directory location in the Run configuration to point to the correct classpath location. The default location had been taken from a parent project.
It would be very convenient if one was able to debug tests from within IntelliJ. I have run into similar issues with my massive project and have found a workaround for it.
When wishing to debug a test, I have often found it useful to use a remote debugging session like so:
mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE" -Dtest=com.autofunk.TheFunkImplTest test -DfailIfNoTests=false
You can then attach to the above using a remote debug session from within IntelliJ on port 8000.
Therefore, when debugging tests I first check to see whether a simple debug from within Intellij works. If not, I run the above and then attach to it using a debug configuration like so:
IntelliJ execute unit tests without mvn command.
a IntelliJ plugin: MvnRunner
You can run tests using the maven project window in IntelliJ
View - Tool Windows - Maven Projects
Then under the project or module you wish to test open the lifecycle goals and click test.
This will run the currently configured test goal. Now the report is logged into the target directory
I use
https://github.com/destin/maven-test-support-plugin
to view the test results.
You can access this screen once the plugin is installed from the Project window again right click on the projects root and select "Show Test Results" (should be below the maven icon)
Good luck