I need to create data driven unit tests for different APIs in karate framework. The various elements to be passed in the JSON payload should be taken as input from an excel file.
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
anddynamic-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.
来源:https://stackoverflow.com/questions/47954754/how-to-read-input-data-from-an-excel-spreadsheet-and-pass-it-json-payload-in-kar