Karate API framework Cheat-sheet

About Karate API

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 and customize the automation requirement using javascript. 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
  • Test Report generation

How to Assert – Expected vs Actual

Option 1:

And match response contains {mobId:’cce3e90273f5′}

Option 2:

* def banks =



    <bank department=”Accounts”>




    <bank department=”loans”>






* match banks //bank[@department=’loans’]/name == [‘home’, ‘mortgage’]

* match banks //bank[@department=’Accounts’]/name == [‘current’, ‘savings’]

Option 3:

When def responseCode =  response.responseStatus.responseCode

And assert responseCode == ‘RESPONSE_100’

Option 4: (Should be Scenario Outline) – If condition also included

And def endDate = response.responseInfoList[0].endDateStamp

When assert endDate == <endCompareDate>

When eval if(endDate == <endCompareDate>) karate.log(‘pass’)

Then print endDate





How to read test data from CSV file?

And request {firstname:<firstname>, lastname:<lastname>, status:<status>}


       | read(‘Testdata.csv’) |

How to feed test data directly from JSON without utilising test tables?

Then request read(‘data.json’)

When method post

How to search based on parameters in GET method?

And params {“q”:[“aura”]}

When method GET

How to handle data driven using test tables?

And request {firstname: <firstname>, lastname: <lastname>, status: <status>}

And method POST





How to handle Header?


* def req_headers = {Content-Type: ‘text/xml’, Connection: ‘Keep-Alive’, User-Agent: ‘Mozilla/4.0(compatible;IE;GACv7\. 1\. 5192\. 22378)’}


                Given headers req_headers

How to call another feature?

Given call read(‘Billpayment.feature’)    

Maven Surefire plugin for Report in multiple formats – HTML, JSON, XML










How to handle Runner class? (Call multiple feature in main.feature)


@CucumberOptions(features = “Feature/main.feature”)

public class Runner {


Thank you!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s