Skip to content

Debug Server

Peter Thomas edited this page Jan 13, 2024 · 44 revisions

Karate has first-class debug support based on the Debug Adapter Protocol (DAP) standard. The Karate Labs Pro IDE plugins take care of starting a debug session automatically and passing the details of feature files and break-points to the debug server.

karate-debugserver

⚠️ This extra dependency is optional - but required for IDE debugging support in Karate 1.4.1 onwards. Debugging is supported only in the Pro version of the Karate Labs IDE plugins for IntelliJ and VS Code.

The karate-debugserver artifact is available via Maven or Gradle.

All runtime approaches documented below (except "VS Code Bundled") require this extra dependency on the classpath.

Here is the snippet you need for Maven:

        <dependency>
            <groupId>io.karatelabs</groupId>
            <artifactId>karate-debugserver</artifactId>
            <version>{karate.debugserver.version}</version>
            <scope>test</scope>
        </dependency>

IntelliJ

With the above extra dependency in place for a Maven or Gradle project, you can debug a Karate test if you are on the Karate Labs Pro version of the IntelliJ plugin.

VS Code

Using the debug server in VS Code depends on how you are using Karate. Choose from the 4 options below.

VS Code Bundled

If using the bundled Karate runtime in the Pro version of the Karate Labs extension, debugging of feature files should work without any extra setup.

VS Code and Standalone JAR

If you are using a version of Karate that is 1.4.1 or greater, you should add the karate-debugserver JAR to the custom classpath. You can download the latest JAR from here.

VS Code and Maven

If you are on the Karate Labs Pro version of the VS Code extension switching the "Run Mode" to Maven should be sufficient to be able to debug a Karate feature file from the Debug codelens. You will need to add the karate-debugserver dependency to your pom.xml.

VS Code and Gradle

If using VS Code and Gradle, you will need to add the karate-debugserver dependency to your build.gradle. Then, you can define a task to do this in your build.gradle:

task karate(type: JavaExec) {
    classpath = sourceSets.test.runtimeClasspath
    main = 'com.intuit.karate.Main'
}

This sets up things so that gradle karate --args=-d on the command-line will start a debug session. In VS Code, use the "Run Mode Custom" to start debugging from VS Code.