Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
664 views
in Technique[技术] by (71.8m points)

karate - How to read test data from csv for JSON requests other than using set options

I used the set feature of Karate to change the values in keys using JSON expression. I used it mainly to change the request contents based on test scenarios. This gave me the capability to avoid reading lot of test data from csv files. However, still in some situations, I prefer to use csv.

For example, I have around 230 test scenarios as post requests and I have 130 different customer information which I need to use on the 230 test cases based on the context. The customer information includes first, last names, age, address etc. However, the schema is same. If I need to use something like groovy template engines what will be the best approach to use in Karate

I need to keep these data in a csv, read it and pass the values to a JSON template before I fire the request. I need to still rely on csv/ external sources because these data becomes obsolete very often and I need to change it frequently. Could you please share your thoughts on this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  1. Using a similar approach to this example (JDBC) you should be able to write a CSV to JSON converter in less than an hour: dogs.feature

  2. IMO once you get used to the table or set multiple syntax, it is far better than CSV-s as it is more readable. You can use call and load the data from a second feature file that only contains the data.

  3. Personally I would recommend using a JSON array instead of CSV. There are plenty of tools that allow you to edit JSON. And it is so easy to read JSON in Karate and use that for data-driven testing. You can even combine set or table, take a look at this for ideas: dynamic-params.feature

  4. I guess you are aware of JSON templating built-in to Karate: embedded expressions - and you should look at the extensive test-case examples here: js-arrays.feature

Make sure you go through the demo-examples.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...