Skip to content

Karate UI

Peter Thomas edited this page Nov 30, 2018 · 22 revisions

Introduction

Karate includes a UI in the 'karate-core' JAR itself - that can be used 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 (download). Refer to the Karate-Netty documentation.

Here are previews of what it can do:

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 difficuly lies in configuring the Postman object properly.