Skip to content

Karate UI

Peter Thomas edited this page May 19, 2019 · 22 revisions

Introduction

The "Karate UI" is very useful to step-through and debug tests, even when call-ed features are involved.

You can easily get this as a stand-alone binary / executable JAR

Usage

Refer to the Karate-Netty documentation for details.

Here are previews of what it can do:

Maven

For those who use Maven or Gradle, the Karate UI used to be part of the core framework (karate-core), but was split out into an optional dependency from version 0.9.3 onwards - to avoid complicating your classpath dependencies.

<dependency>
    <groupId>com.intuit.karate</groupId>
    <artifactId>karate-ui</artifactId>
    <version>${karate.version}</version>
    <scope>test</scope>
</dependency>

Java API

While you can choose a file from the 'File' menu, things are designed so that you can 'script' it to open the feature file you are working on, and save significant time - not needing to fiddle with browsing around and selecting files via the UI.

import com.intuit.karate.ui.App;
import org.junit.Test;

public class CatsUiRunner {
    
    @Test
    public void testApp() {
        App.run("src/test/java/demo/cats/cats.feature", "dev");
    }    
    
}

So just running the above 'as a JUnit test' would load the specified feature file with the karate.env set to dev.

You can also do this to just bring up the UI after which you can use the File-->Open menu to manually choose a file.

App.main(new String[]{});

The advantage of doing this from within your project is that in case you are using Java interop or depending on any JAR-s in the maven classpath (dependencies) - Karate would work correctly even while running in "UI" mode.

Troubleshooting

You may face problems on Ubuntu - since JavaFX may not be installed. Refer to this comment for how to solve this.

Postman Import

This is experimental, but can load most Postman collections. Use the Import-->Open menu for this.

Notes

Since the Postman Import functionality is experimental, there are some limitations. For example:

  • If in a POST request the body is just raw text (Content-Type = 'text/plain') the generated feature file will fail on execution.

  • If the Postman request has query-string parameters instead of form-fields, the URL inside the postman_collection file is not a string but a JSON object, which is not handled by the converter.

  • Postman tests are not converted and they are completely ignored. Since the postman tests are written in javascript with a some special variables and objects like "postman" object, "responseBody", etc., they can be used as it is in the feature files. The only difficulty lies in configuring the Postman object properly.