API Testing Using KARATE - Hubino Resources
Home » API Testing Using KARATE

API Testing Using KARATE

by admin

About Karate:

Karate is an open source library used to test the web services based on the plain English in the text file such as feature file. You could automate the web service testing based on the below highlighted points associated with Karate;

  • Support both SOAP and REST
  • Schema validation
  • Assert the response
  • Response data chaining to next request
  • Data elements comparison (Support both JSON and XML)
  • Data driven approach using .js file
  • Test Report generation

Please refer the long list of supported feature sets using the below URL;


http://tinyurl.com/karatera (REST Assured vs Karate)

Karate Setup:

  1. Create a maven specific project in your Eclipse
  2. Please use the below dependencies to download the Karate library in your Eclipse IDE;













How to use Karate:

Create a Runner file (Java class file) based on the below details;

package karate.test;

import com.intuit.karate.junit4.Karate;

import cucumber.api.CucumberOptions;

import org.junit.runner.RunWith;


@CucumberOptions(features = “Features/MockTest.feature”)

public class Runner {


Create a feature file (Example: Test.feature) based on the below details;

Feature: REST API testing using Karate with Mockoon


* url endpoint

Scenario: Test REST request and assert the response

Given path queryName

When method GET

Then status 200

And print response

And match response contains {name:’Gopi’}

And def accountNumber = response.multipleaccounttype[0].savings

And print accountNumber

Calling the data such as URL and path name from karate-config.js file as mentioned below; This file should be added in the project src location;

function () {

var port = 3000;

var baseUrl = ‘https://www.hubino.com/resources

var config = {

endpoint : baseUrl + ‘:’ + port + ‘/accountList’,

queryName: ‘/name’,


karate.configure(‘connectTimeout’, 30000);

karate.configure(‘readTimeout’, 60000);

return config;


About REST Testing using Karate based on the above code snippet:

  • Calling the URL from karate-config.js file using the syntax of ‘* url endpoint’
  • Pass the path name in the ‘Given’ condition
  • Trigger the GET method using ‘When method GET’
  • Assert the status as ‘200’ in the ‘Then’ condition
  • Print the response received from the web server
  • Assert the response contains the name is Gopi in the ‘And’ condition
  • Assign a variable using def and getting the account number using ‘And’ condition
  • Print the fetched account number in the response

 About karate-config.js file:

  • Declare the URL details in a variable to reuse in another feature files
  • Declare the path name in queryName variable to reuse in feature file
  • Return the values

After running the runner file(Runner.java), Karate will start executing the feature file based on the step by step detailed information and publish the test results in HTML format as mentioned below;

I’ve used mockoon to mock the REST API using the below details;


Thank you!!!

Image Credit – https://www.lifehacker.com.au

You may also like