What is Karate Gatling? Github page of this project has the tag line API performance testing made simple . Simply put this should help in performance testing of the api test written using Karate by leveraging performance testing capabilities of karate. On reviewing the documentation available on GitHub following capabilities are listed: Re-use karate tests as performance tests executed by Gatling Gatling and scala required only for defining the load model Everything else can be defined in Karate Karate assertion failure also appear in the Gatling report Anything that can be written in Java can be performance tested. Option to scale out over multiple hardware nodes or Docker containers In this post we will see how to reuse Karate tests for execution using Gatling We will see step by step on how to setup Karate Gatling performance tests. There are a few prerequisites for setting up your karate Gatling tests. Prerequisites: JDK should be installed and availabl...
In the last post we saw what is Karate? and Why to use Karate. In this post we will see one of the simplest way of setting up and getting started with Karate framework.
Usually when someone is starting their journey towards learning automation, then one of the most difficult things is doing the various setups before they can even get started.
Karate although a recent entry as compared to some of the other automation tools already out there for a long time, has taken a clever approach that adresses these issues that are faced during busy schedules .
I'm listing down few of the statements that have come up during my discussions with various people of the Testing community. These are the pain points that they encounter on a regular basis and in some extreme cases have pushed them away from even starting their automation journey.
Problem statements
- Lots of time is wasted in setup of tools or the framework, when your target is to complete only a small POC
- In most places there are many restrictions on what can and cannot be installed, hence we cannot implement / learn new thing
- Setting up a demo of a new tool is a very time consuming
In this post we'll see how Karate addresses these concerns. So, lets dive right in
What is ZIP release?
Within the ZIP file is present the Karate executable jar file which contains all of the important features. It also contains sample for -
- Api automation
- Mocks
- Web / UI automation
- Desktop automation
Where to Get the ZIP release?
I prefer downloading from the Bintray as it is easier to find the latest release at this location. From here you can either download the
- Latest stable Karate Zip release
- Or just the Karate jar file
- Or the latest rc version (with rc in the version number) that have experimental features of Karate
- Or the Karate-robot for desktop automation
![]() | |
Bintray |
Download the Karate-<latest version available>.zip file
![]() |
Folder structure |
![]() |
Tree structure |
As seen here samples for API / Mock / Web / Robot (desktop) automation are already included in the ZIP release.
There's just one more thing and we would be ready to explore Karate
For getting started there are only a couple of things required
D: \karate\karate-0.9.6> java -version
- Zip file
- This step is already completed
- Jre
- Verify that Jre is installed in your PC and is available in the Path variable
openjdk version "11.0.9" 2020-10-20
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9+3-202008212340)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9+3-202008212340, mixed mode)
That's it and now we are ready to explore Karate
- At this stage having an IDE is entirely optional
- Although IDE's are very helpful, but it is not a necessity and shouldn't stop you from learning new things.
- Samples available can be run from the command line
Before we begin a bit of History:
During the initial releases of the zip release version of Karate, for ease of use there were a few changes that were required to be made before we could start using the terminal. But now no changes are required and using it even via command line is very straight forward.
Open the command prompt in the root of the project and type
karate -h to get a list of commands
So what next? How do I run the included samples?
It's pretty simple. Type Karate followed by the path of the file that you need to run.
E.g For windows OS if I need to run the API sample I'll run the command karate src/demo/api and hit the Enter key:
You should now see the the test getting executed and at the end of the run you would see something like this
Results for the API test |
At the End we can see the summary for the test and also the url to the new HTML report.
Just copy the path and open it in a web browser of your choice.
![]() |
Summary report |
By default the report opens in Summary view. To view the detailed report click on the link under the feature column (displaying the path and name of the feature file)
Detailed Report |
The Number and characters in blue are clickable, and when you click on them these show more details related to the step. By default in the report the Background details are hidden. If you wish to see it then click on the >> and then the number under it to view the details.
All this is great, but wouldn't I need any more libraries for running the web / UI automation tests?
Answer is both Yes and No.
If your aim is to just get started with Karate or just demo the features of Karate then you do not need anything else.
Karate implements the Chrome dev tools protocol for UI automation. So what it means is that if you have chrome installed in the default location of your system then you don't need any additional things. Just type in the command and run the test. Once you have got hang of things then you can tryout cross-browser tests with W3C WebDriver implementations including Microsoft Edge on Windows and Safari on Mac
Lets see how to do it, once again open the command prompt in the root of the project and type the command karate src/demo/web/google.feature and hit the Enter key
Summary UI test run |
![]() |
HTML Report - UI Automation Details |
Why does the mock directory contain 3 files? and how to run mocks?
cats-mock.feature - This is your mock server
cats.html - This is the HTML client
cats-test.feature - Contains test which can be run against the mock.
First we need to start the server, for this use the command karate -p 8080 -m src/demo/mock/cats-mock.feature
Now open the cats.html file in your favorite browser
HTML client - Default State |
Now if I click on Create Cat button, a cat named Billie would be added to the mock and the entry would be displayed on the page
To view the raw json response click on GET /catsRaw json |
To run the cats-test.feature type the command karate src\demo\mock\cats-test.feature
Raw json response |
![]() |
Mock Test HTML Report |
P.S. ZIP release also contains sample tests for Desktop automation, which we will explore in another post.
Outro:
So if you see getting started shouldn't take much time and also there are not many dependencies that you need to run the sample tests for a quick demo.
In case if you feel the need for IDE, any open source IDE or community edition with support for Java should do fine.
Use this post for - Quick Start with Maven Archetype which has information on getting started with Karate using Maven+Java with IntelliJ IDE.
Here's a video on how to use VsCode for ZIP Release.
Here's a Video on how to write your first test
Comments
Post a Comment