-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Karate Robot Windows Install Guide
To make this a comprehensive guide, this will take you through the process of installing Karate Robot on a freshly provisioned Windows box from AWS. You may be able to skip some of the steps (e.g. installing Java) depending on what already exists in your environment.
The main pre-requisites are
- a 64-bit Windows OS (32-bit may work, please let us know !)
- a Java Runtime Environment (JRE, 32-bit will work !)
- the Karate binaries (
karate.jar
andkarate-robot.jar
) - Visual Studio Code (with the Karate Runner plugin)
- Tesseract Data Files (optional)
It has to be 64-bit. After we created one on AWS, we installed FireFox because the stock Internet Explorer makes it hard to download files.
![](https://user-images.githubusercontent.com/915480/83351731-2883ba00-a364-11ea-9800-54f87480bff2.png)
Before you do this, check if you already have Java installed by opening a cmd
terminal and typing:
java -version
If it responds with a version that is 1.8.0_112 or greater (Java version 8) you are all set !
Here, clearly Java is not present:
![](https://user-images.githubusercontent.com/915480/83351826-ed35bb00-a364-11ea-8a76-c9c1d2ad6d71.png)
So to get Java, go to https://www.java.com/download in a browser and you should see something like this. Java 8 is preferred, and you can download what is being shown here.
Note that a Java Runtime Environment (JRE) is sufficient and you do not need a JDK (Java Development Kit). But if you already have one and java.exe
is in the PATH
, that should be enough.
![](https://user-images.githubusercontent.com/915480/83351887-764cf200-a365-11ea-8257-e135d7c48349.png)
Once the Java installer EXE is downloaded, run it and go through the install process.
Once done, open a fresh cmd
terminal Window and make sure that Java is installed.
![](https://user-images.githubusercontent.com/915480/83351993-10ad3580-a366-11ea-994e-e3000a995945.png)
Download the Karate ZIP Release and extract it to a folder of your choice.
To test that Karate is working fine you can type this command by opening a cmd
terminal in the "root" of the Karate folder:
karate -h
![](https://user-images.githubusercontent.com/915480/83352546-cb8b0280-a369-11ea-91ae-5436d03007da.png)
This means that Java and Karate are installed correctly.
Note that karate.jar
is already present and it came along with the ZIP Release. For the Windows Desktop Automation we need one more binary. Download karate-robot.jar
from the locations provided here. The file will be suffixed with the version number.
After downloading the file, rename it to karate-robot.jar
for convenience, and place it alongside karate.jar
. There is one more thing we need to do which is edit karate.bat
to "include" the new file we just added. Here below you can see what the folder and the edit should look like.
java -cp karate.jar;karate-robot.jar;. com.intuit.karate.Main %*
![](https://user-images.githubusercontent.com/915480/83352489-5b7c7c80-a369-11ea-8e37-022a7bbb0c82.png)
After this, you should be able to run Karate tests that operate Windows desktop applications. You can try this command:
karate src/demo/robot/calc.feature
Or if it is the "old" version of the Windows Calculator, use this:
karate src/demo/robot/calc-old.feature
Here's what the "old" calculator test in action looks like:
![](https://user-images.githubusercontent.com/915480/83353046-689b6a80-a36d-11ea-9883-085a3591c073.png)
So at this point you can create and run Karate tests for Windows applications ! But to really get productive, we recommend that you use the Visual Studio Code IDE support.
Download it from https://code.visualstudio.com/.
After installing, open Visual Studio Code and go to "Extensions" (the bottom vertical tab on the left). You can type "karate" in the search-box to find the Karate Runner extension.
![](https://user-images.githubusercontent.com/915480/83353145-1d358c00-a36e-11ea-9b1d-22c9c8d268ba.png)
Click on "Install". After that you should see the "gear" icon, click on it to edit some extra settings needed for Karate Robot. Choose the "Extension Settings" option from the menu.
![image](https://user-images.githubusercontent.com/915480/83353369-cfba1e80-a36f-11ea-976f-dc6fdab9c040.png)
Scroll down to find this setting called "Command Line Args"
![](https://user-images.githubusercontent.com/915480/83353431-33444c00-a370-11ea-9472-2c53c877f8a3.png)
Change it to add karate-robot.jar
. The whole line would be:
java -cp karate.jar;karate-robot.jar;. com.intuit.karate.Main
![](https://user-images.githubusercontent.com/915480/83353491-8b7b4e00-a370-11ea-808a-d385c0f57df3.png)
Now the IDE is ready to open Karate projects and files and run and even debug tests. Go to File --> Open Folder
and browse to the Karate / project folder.
Here we have also opened the calc.feature
(or calc-old.feature
).
![](https://user-images.githubusercontent.com/915480/83353542-f75db680-a370-11ea-9316-4fdca9765876.png)
Note how you can click on Karate Run
at the top of the file to run a test. You can try it now, but you will get this error.
![](https://user-images.githubusercontent.com/915480/83353616-60ddc500-a371-11ea-9b08-b60df03cb0a2.png)
This is because Visual Studio Code uses "powershell" by default instead of "cmd.exe" which is what we need. There is an easy way to set this. Click on the "Task" drop-down you see in the bottom "Terminal" tab and you should see an option to "Select Default Shell" like you see above.
If you really need to use PowerShell, you can try by modifying the Command Line Settings to have the
-cp
(classpath) argument within single-quotes: e.g.java -cp 'karate.jar:karate-robot.jar;.' com.intuit.karate.Main
And now you can choose cmd.exe
.
![](https://user-images.githubusercontent.com/915480/83353667-c2059880-a371-11ea-8b84-a19df8b0b4d9.png)
You can change this any time by going to File --> Preferences --> Settings and searching for "terminal windows". For more information on changing the default terminal on Windows, refer to this thread on Stack Overflow.
![](https://user-images.githubusercontent.com/915480/83353721-304a5b00-a372-11ea-9558-479110995fce.png)
Now try clicking again on "Karate Run" in the Feature:
and it should work. Note that you can see reports in the target/surefire-reports
folder - which even includes screenshots if requested as part of the test-script.
![](https://user-images.githubusercontent.com/915480/83353950-a4d1c980-a373-11ea-80de-07993522376e.png)
This is a must for writing and maintaining tests and one of the best things about the IDE support. Try clicking on "Karate Debug". This one-time prompt to select a "Debug Configuration" will come up. You can choose Karate (debug)
.
![](https://user-images.githubusercontent.com/915480/83353992-fed28f00-a373-11ea-932d-c18fac97de45.png)
You don't have to change the default "Launch Configuration" that will be created. You can close this launch.json
tab now and get back to the feature file.
![](https://user-images.githubusercontent.com/915480/83354043-448f5780-a374-11ea-957f-c4f9ecfdb8c0.png)
Now try "Karate Debug" again, but this time before you do anything, set a break-point, see the red-dot on line 12 below.
![](https://user-images.githubusercontent.com/915480/83354119-a94ab200-a374-11ea-8dac-e1e59455e8ff.png)
And as we expect, Karate will stop at the break-point like seen below.
![](https://user-images.githubusercontent.com/915480/83354153-e020c800-a374-11ea-86eb-11bb5d28061c.png)
Now you can do some interesting things. Find the "Debug Console" tab in the bottom pane (click on the "..." icon if needed) and type highlightAll('//button')
![](https://user-images.githubusercontent.com/915480/83354299-663d0e80-a375-11ea-99e6-6c1f1cee8acf.png)
Hit ENTER and you should see this. You can try other commands such as highlight('6')
. Any Karate step should work. You can see how this is extremely useful for building or troubleshooting tests.
![](https://user-images.githubusercontent.com/915480/83354329-9e445180-a375-11ea-83d2-d9ac42782ba6.png)
Note that you can even step back and edit & hot-reload steps. Also see this video.
This is needed when using Karate-Robot for desktop automation and when you use the Karate-Runner in debug mode. Most of the time, Karate-Robot expects a particular application-window to be "in focus" and visible, and on top of all other windows. But when you use the debug actions such as [step-forward], [continue] etc. after hitting a break-point - the Visual Studio Code window would be the one having "focus" instead.
So there needs to be a way to tell Karate to "flip" focus back to the AUT (Application Under Test). This can be easily done - as Karate has a way to execute any arbitrary script before resuming execution when in debug mode. And typically, the most effective way is to trigger an ALT+TAB
input sequence.
The Visual Studio Code Launch Configuration (.vscode/launch.json
) for the Karate Debug Server takes an optional debugPreStep
parameter. For example, this is the configuration that can switch focus to the previously most recently focused window:
{
"type": "karate",
"name": "Karate (debug): Standalone",
"request": "launch",
"feature": "${command:karateRunner.getDebugFile}",
"karateOptions": "",
"karateCli": "${config:karateRunner.karateJar.commandLineArgs} -d",
"debugPreStep": "input(Key.ALT + Key.TAB)"
}
Note that the step-prefix (e.g. *
, Given
, When
then etc. can be omitted). Only a single step can be configured, but the good thing is that you can call
any valid feature if you have a need to run a sequence of pre-step operations:
"debugPreStep": "call read('some.feature')"
The "Inspect.exe" tool can be used to figure out how to select UI elements. One way to acquire this is to install the Windows SDK (selecting "Windows SDK for Desktop C++ x86" should be sufficient).
It seems that there may be better options such as Accessibility Insights for Windows so you could try that - or any other similar tool instead.
Besides image-driven navigation, Karate Robot has experimental support for OCR (Optical Character Recognition) that can be useful in case there is no other way you could find to "select" an element or control, possibly because it is a UI framework that Windows has limited support for.
For the OCR support to work, you need to separately download some data files. You can read the documentation for details, but for now we will just use the defaults for "English" and just add a single data-file in a pre-defined (default) directory.
-
Download
eng.traineddata
from the tessdata_fast data-set. -
Place this in a
tessdata
folder in the root of your Karate project folder. This is how it should look.
![](https://user-images.githubusercontent.com/915480/83354733-317e8680-a378-11ea-9cb4-e75f8b4b9f65.png)
Now you can enter this command in the Debug Console (when a debug / breakpoint session is in progress) and hit ENTER.
robot.active.debugExtract()
![](https://user-images.githubusercontent.com/915480/83354772-79051280-a378-11ea-836e-937aabef7f37.png)
You should see Karate attempt to OCR-scan the "active" window for text:
![](https://user-images.githubusercontent.com/915480/83354992-2298d380-a37a-11ea-858a-6902ba99a6dc.png)
For convenience an additional Window will appear with details so that you can study it at leisure.
![](https://user-images.githubusercontent.com/915480/83355103-c1253480-a37a-11ea-9128-2c28bdba6e4c.png)
There may be some more work needed to make the OCR capabilities more accurate and robust, please do contribute if you can !
Note that when using an RC release, the latest documentation would be in the develop
branch:
https://github.com/intuit/karate/tree/develop/karate-robot