How to read input data from an excel spreadsheet and pass it JSON payload in karate framework?

A few points:

  • I recommend you look at Karate’s built-in data-table capabilities, it is far more readable, integrates into your test-script and you won’t need to depend on other software. Refer these examples: call-table.feature and dynamic-params.feature
  • Next I would recommend using JSON instead of an Excel or CSV file, it is natively supported by Karate: call-json-array.feature
  • Finally, if you really wanted to, you can call any Java code and if you return data in a Map / List form, it will be ready for Karate to use. This example shows how to read a database via JDBC: dogs.feature. So although this is not built into Karate, just write a simple utility to read a CSV or Excel file and you can do pretty much anything Java can do.

EDIT: Karate now supports CSV files that can be used to even do data-driven testing: https://github.com/intuit/karate#csv-files

Leave a Comment