How to handle complex Json request payload when we use Excel sheet as data source?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to handle complex Json request payload when we use Excel sheet as data source?
Hi All,
I know how to do data driven testing using Datasource, Loop and so in Ready API. I would like to understand the best practice to handle Complex JSON request payload. In other words, If my JSON payload has multiple arrays and I need to run multiple iterations of data how could I efficiently handle this?
For example, consider below is my JSON request payload. Lets assume, I will have to run 10 different iterations of data with the below pay load template. How could I approach my test data parameterization in Ready API?
[ { "id": "0001", "type": "donut", "name": "Cake", "ppu": 0.55, "batters": { "batter": [ { "id": "1001", "type": "Regular" }, { "id": "1002", "type": "Chocolate" }, { "id": "1003", "type": "Blueberry" }, { "id": "1004", "type": "Devil's Food" } ] }, "topping": [ { "id": "5001", "type": "None" }, { "id": "5002", "type": "Glazed" }, { "id": "5005", "type": "Sugar" }, { "id": "5007", "type": "Powdered Sugar" }, { "id": "5006", "type": "Chocolate with Sprinkles" }, { "id": "5003", "type": "Chocolate" }, { "id": "5004", "type": "Maple" } ] }, { "id": "0002", "type": "donut", "name": "Raised", "ppu": 0.55, "batters": { "batter": [ { "id": "1001", "type": "Regular" } ] }, "topping": [ { "id": "5001", "type": "None" }, { "id": "5002", "type": "Glazed" }, { "id": "5005", "type": "Sugar" }, { "id": "5003", "type": "Chocolate" }, { "id": "5004", "type": "Maple" } ] }, { "id": "0003", "type": "donut", "name": "Old Fashioned", "ppu": 0.55, "batters": { "batter": [ { "id": "1001", "type": "Regular" }, { "id": "1002", "type": "Chocolate" } ] }, "topping": [ { "id": "5001", "type": "None" }, { "id": "5002", "type": "Glazed" }, { "id": "5003", "type": "Chocolate" }, { "id": "5004", "type": "Maple" } ] } ]
- Labels:
-
Data-Driven Testing
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In short, maybe multiple datasources and loops. Datasource loops can be nested...
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you please elaborate more?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's difficult to elaborate more based on what you have given.
As you say, the JSON is complex, even for a single donut. What isn't clear is how many donuts per payload? How much variation of batter and how much variation of toppings? How many items in batter? 1..n? 1..3 max?
One thing I can say is that when using datasources, you don't have to restrict a cell in the datasource to be a single, discreet value. e.g. {$datasource$ingredient} gives chocolate. You could instead have a cell that contains the JSON for a whole topping record. E.g. {$datasource$topping} returns '
{ "id": "5001", "type": "None" }
or even...
{$datasource$topping} returns
{ "id": "5001", "type": "None" },{ "id": "5002", "type": "Glazed" },{ "id": "5003", "type": "Chocolate" },{ "id": "5004", "type": "Maple" }
With separate datasources of donuts, batters and toppings, with the latter two nested inside donuts, you potentially could test lots of variations with a relatively small numbers of rows in each.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the detailed reply @ChrisAdams .
To answer your questions, The No of donuts, No of batter and No of toppings may vary test case by test case. For example my test case 1 may have 3 nos of donuts, my test case 2 may have 2 nos of donuts. Same thing applicable for batter and toppings too. That's why it is making too complex for me to handle the datasource.
Can you please show me some example excel sheet to accommodate this complex JSON?
Also help me by showing some sample datasource Steps and usage of datasource in ReadyAPI for this Complex JSON?
Appreciate your effort on this!!
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Sorry, I not sure that I can without a lot of effort.
The thing with datasources is that you call each row, so the random nature does make it harder to model.
If randomness is key, have a look at Groovy script steps. E.g. a script that returns a random number of batters, toppings etc.
You could use a combination of groovy scripts and excerpts of payloads in files that you could use to build a 'random' payload.
you could build your requests in text files
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@ChrisAdams Thanks for your reply!
I understand it will take lot of effort to put together.
I will look into that and try to come up with some solution for this.
Thanks for you help!!
