vivekkulkarniOccasional ContributorJoined 4 years ago6 Posts1 LikeLikes received1 SolutionView All Badges
ContributionsMost RecentMost LikesSolutionsRe: Comparing Json node values against each other Hi ChrisAdams, I used part of you logic and got the solution. 1. Converted both json responses to string and created objects of it (Using jsonSlurper()) with parsing //Stored response def response1 = context.expand( '${TestCaseName#Response}' ) def response2 = context.expand( '${TestCaseName#Response}' ) def jsonSlurper = new JsonSlurper(); //Parsing the response received def resp1_obj = jsonSlurper.parseText( response1.toString()); def resp2_obj = jsonSlurper.parseText( response2.toString()); 2. Accessed json file content with Key resp1_obj.key_value[i] resp2_obj.key_value[i] 3. Parameterized the key indexing ('i' value parameterized) 4. Compared the node values one after teh other using for loop. for(int i=0;i<5;i++) { if(resp1_obj.key_value[i] == resp2_obj.key_value[i]) log.info("PASS") else log.error("FAILED") break } Thanks once again for the solution and response. Thanks & Regards, Vivek Kulkarni Re: Comparing Json node values against each other Thanks Chris for the code and detailed explanation. I'll try this approach in the project and keep you posted. (Hope this works finger crossed) Thanks, Vivek Kulkarni Re: Comparing Json node values against each other Hi Richie, Thanks for the answer. I have 2 different APIs calls. The response of two API contains common fields and data. Want to compare those data against each other. Hope scenario is clear. It would be great if the solution provided by you works for this scenario as well. If you have any video tutorial or code sample for you solution that helps me to get understand better. Thanks, Vivek Kulkarni Re: Comparing Json node values against each other Hi Chris, Thanks for teh quick response. I tried the groovy, but it compares specific node data. I want to compare teh data of all the nodes present. Iteration is teh challenge. Can you please post related to that. How can I traverse and validate values. If you require can post json files of the response data. Thanks, Vivek Kulkarni Comparing Json node values against each other Hi Team, I have query regarding the json values comparison. I have request say Request-1 and gives response as Response-1. Gives 10 node values One more request say Request-2 and gives response as Respnse-2. Gives 10 node values I need to compare both response values of all the node values which are common to both. Kindly let me know. I added smart assertion to do comparison, but if node value changes from 10 to 11 the fails to compare or may miss to validate. Thanks, Vivek Kulkarni Solved