1

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?

Sree
  • 331
  • 1
  • 4
  • 14

2 Answers2

2
  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.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
1

I agree with your approach. I also think it’s better to read data from JSON array or using the table capability. I am working on that now. I work on a premise which has a lot of access restrictions. I inform the team about your answers. We keep a watch on these questions. However, I cannot login to stack overflow from office. So got delayed to respond on this. Sorry for the delay.

Now I am mainly doing an R&D to find a solution to test web services which can be integrated with the webdriver + DB validations. We earlier decided to go with rest assured. After using karate we have definitely changed our mind. One of our friend who work in ThoughtWorks suggested about karate and we came to know about it.

We are really impressed with its capability and also really happy to see the questions posted in stack overflow are so quickly answered. This gives us more confidence to use Karate. I would suggest that karate needs an individual website like rest assured.

Sree
  • 331
  • 1
  • 4
  • 14
  • thanks for the feedback. I hear you on the web-site - but you will actually get used to it, I'm sure :) a lot of users actually like how all documentation is on one page, and you quickly get the hang of using the index or doing `CTRL+F` to search and jump straight to what you want. – Peter Thomas Nov 15 '17 at 04:50