|
PLUS | PRO | Enterprise |
---|---|---|
|
    (includes all in PLUS)
|
|
By using this plugin, you agree to the Karate Labs EULA. Data on a few user actions is collected and subject to our Privacy Policy. HTML reports generated by the Karate open-source library has additional analytics.
License activation and status is available via a command. Go to View -> Command Palette
, type Karate
and you should see something like this.
Â
Choose the option to Sign In / Manage License
and you will be shown a dialog. Click Sign In
to be taken through the usual flow linked to your existing subscription details.
Once you have authenticated successfully, copy the session ID from the browser and paste it into the input-box now showing in VS Code. Hit ENTER
to complete the sign-in.
Â
Once signed-in you can work offline. You can always run the Sign In / Manage License
command to see how many days are left in your session.
If you need an offline license because of strict security or similar restrictions in your environment, please contact us. Please note that this option is available only for enterprise customers of Karate Labs.
You can access the extension settings by clicking on the "gear" icon after going to "Extensions" on the nav-bar.
Â
Especially if you are working with Java Maven or Gradle projects, it is recommended that you have the Language Support for Java VS Code extension installed.
Then keep the karatelabs.karate.run.mode
setting as vscode-java
(the default).
You can change the karatelabs.karate.run.mode
setting to standalone
if you want to use the Karate standalone JAR. Download it and choose a local folder to keep JAR files in. Change the karatelabs.karate.run.modeJars
setting to point to that folder, and for convenience, all JARs within that folder will be included in the runtime classpath.
Note that the Mode Jars
setting should be a folder name. Do not include the .jar
part. Note that the default of .
will work fine for the common practice of keeping the Karate JAR in the "root" of your project folder.
The karatelabs.karate.run.classpathPrefix
setting defaults to .
which should suffice for picking up karate-config.js
from the workspace root. You can add more classpath entries (comma-delimited) and even JAR files if you wish. For example .,src/test/java
would also search in src/test/java
for karate-config.js
.
Note that VS Code has a mechanism to customize settings per Workspace (or project folder) which can ensure your whole team uses the same settings. Here is an example of how the values of the run.mode
and classpathPrefix
can be written to a file in .vscode/settings.json
. Now this file can be added to your Git repository or version control.
You can also opt to run commands such as java
or mvn
directly with karatelabs.karate.run.mode
set to custom
. In this case java
or mvn
is expected to be installed and in the system PATH
.
For convenience the string ${karateArgs}
will be replaced with command-line arguments generated by the extension when performing actions such as Run
etc.
If the Language Support for Java extension is not installed, you will need a Java runtime installed and JAVA_HOME
set in your environment. Having the java
command in your system PATH
should also be sufficient. Java 11 or higher is needed for Karate 1.4.X and Java 17 is needed for Karate 1.5.0 and above.
There is a Karate Log
within the "Output" tab (next to "Terminal") typically at the bottom of your VS Code window. You can look at it to find the reasons for failure.
Â
To change the log level you can use the VS Code Command Developer: Set Log Level
(View --> Command Palette
and type "Log") and then select Karate Log
. Changing the log level to Debug
gives you more information.
You can run a feature file open in the editor by using the CodeLens. The keyboard shortcut [CTRL]
[F5]
also works.
Â
You can run a single Scenario
by using the CodeLens that appears above it.
You can even run a single "example" in a Scenario Outline
by right-clicking on one of the data-rows within an Examples
table.
VS Code launch-configurations are useful for being able to re-run tests with specific parameters. All the typical Karate options you need are supported, including control over the JVM parameters and working directory. The feature file (or path to search for feature files) should be the last argument.
Here is an example .vscode/launch.json
file:
{
"version": "0.2.0",
"configurations": [
{
"type": "karate",
"name": "env-test",
"request": "launch",
"karateArgs": [
"-e",
"test",
"${file}"
]
}
]
}
The advantage is that you can set up any combination of Karate runtime options via karateArgs
. For example you can:
- run tests in parallel
- set the environment
- or choose tags to include or exclude.
Now you can run tests from the Run and Debug view in VS Code and keyboard short-cuts such as F5
will work for the currently focused file in the editor. Note that you can even Run without Debugging: Ctrl + F5
.
Â
You can have multiple configurations and easily switch between them.
You can add "noDebug": true
to the run-configuration JSON to force "Run without Debugging" for convenience.
Instead of ${file}
as the value for feature
, you can use any valid folder path or even multiple feature files.
The VS Code outline view is supported so you can navigate large files with ease.
VS Code code-formatting shortcuts work to format indenting of feature file elements.
The HTML report is one-click away.
Besides the syntax validation, you have auto-complete for the most commonly used keywords.
You can collapse sections to make it easier to deal with long tests.
Coming Soon.
Place the cursor within JSON to see options to re-format it, you will see a "bulb" icon.
Â
The following options are possible (depending on context):
- Lenient - just like JS, where single-quotes are used and no quotes are needed for property keys
- Strict - Strict JSON, using double-quotes
- Make single Line - convert multi-line JSON to a single line
- Make multi-line - convert a single line of JSON to multi-line, including triple-quotes
As a convenience, you can right-click and run a folder from the explorer view.
You can set break-points on Karate feature files in debug mode. The Karate debugger can even step-back and hot-reload simple edits to your test.
A Karate debug session will even stop at Java breakpoints.
You can also start a normal Java debug session that uses the Karate Runner
Java API but still stop at Karate breakpoints. This requires you to be using Karate version 1.5.0.RC3 or greater.
Important
The Offline License is a paid feature for enterprises. Please make sure you know who your designated admin is before you perform this step.
The dialog you see when you invoke the Sign In / Manage License
command looks like this.
Â
Click the Offline License
button. A unique code for your system will be shown which you can cut and paste. In the example below, it is: DhHOFKHvd7XYTi+rQnNTJQ==
Â
Send that unique code to your designated admin. You will be issued a license that is tied to this unique code. To apply the license, copy all the text from the license file (which should start with: -----BEGIN LICENSE FILE-----
) and paste it into the text-field shown above. Make sure you clear the text-box before pasting the license file text or just replace the initial contents. Now you should see something like this.
Â
Click [ENTER] and should see a confirmation message with your license details.