Skip to main content

Performance testing with Karate Gatling

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...

Getting started with karate-config.js

In this post we will see how to add an configuration file (karate-config.js) to our sample karate project. This configuration file is similar to the properties file that you would have used for other automation projects.  I'll be using the Karate-Zip release version for this post too. Still unaware about it, check out my last post.

When using the config file we need to understand a few basics about it:

  • When Karate starts-up it expects a file called karate-config.js in the classpath
    • This config file should be a Javascript function.
    • The function is expected to return a json object
    • All Keys and values in the json object will be made available as script variable
So what is classpath when using the Karate Standalone Jar or the Zip release version of Karate?
To understand this lets open the karate.bat file and try to see what it contains, it has this command
java -cp karate.jar;. com.intuit.karate.Main %*

So com.intuit.karate.Main is the entry point for the Karate command line app

And . (period) indicates the current directory

Here we see that the current directory is also added to the classpath.

Karate-config.js, how and where - Steps?

Lets address the where part first.

Create config here

In the root of your project, create a new file and name it as karate-config.js

Config Location

Now open the file and add below code


What does the code do? How to use karate-config.js?

We have added a Key called myName with value Kalimoh, we will use this in our API sample feature file and try to print it. This will help check if the configuration file is setup correctly.

So, lets open file users.feature and modify it to add it as shown here

We have added the print statement in the Background section which utilizes the variable created previously.

Now while being in the root of your project, run your test with command karate D:\karate\karate-0.9.6\src\demo\api

 Below report is generated and we can see that the correct value got printed in both scenarios.

Report Showing the printed name

Now that we know that the configuration is setup correctly, lets try to get the URL used in the Background section of the feature file from the config file.

Anything used in the background would be run for each of the scenarios in the feature file. So we should be able to use the variable from Config file for both scenarios. 

Lets modify the karate-configuration.js file and add the URL to it as shown below

Now once again lets modify the users.feature file to use the usersUrl variable (created in the config file) in the Background section and second Scenario as shown below

Run your test with command karate D:\karate\karate-0.9.6\src\demo\api

In the report we see that everything has passed. All 3 steps where URL was required for the test it was setup correctly.

URL from Config

Next Steps:

Try to use the config for the sample UI automation test and let me know how that worked out.

References:

Custom classpath

Comments

Popular posts from this blog

Performance testing with Karate Gatling

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...

Karate - Quick Start with Maven Archetype

 What is Karate? Karate enables you to script a sequence of calls to any kind of web-service and assert that the responses are as expected.  Karate provides an easy to use DSL which natively supports json and xml. Karate is not just limited to API automation. After the initial releases which supported API automation, now the capabilities include Performance testing, UI  automation, Desktop automation (a release candidate was made available just a few weeks ago with this capability). Why Karate?  Is based on the popular Cucumber / Gherkin standard, and IDE support and syntax-coloring options exist  You can run tests and generate reports like any standard Java project. But instead of Java - you write tests in a language ( DSL ) designed to make dealing with HTTP, JSON or XML Java knowledge is not required and even non-programmers can write tests Embedded JavaScript engine that allows you to build a library of re-usable functions  Gherki...