punter's avatar
punter
Contributor
2 years ago
Status:
New Idea

Save the response and validate the response automatically

Hi Team,

I have created a utility which will validate the saved response with new response for an api request

how to achieve that

1) I will save the sample response which will be compared with response received at run time

2) The utility will generate all the json path for the new response generated and old saved response and store as list

3)it will iterate over any one list extract the content of each node by doing getstring(jsonpath) function and compare with node value received for saved response using same  getstring(jsonpath) 

4)it will validate the size if response with respect to saved response by asserting size of both the list

5)if user wants to ignore specfic jsonpath they can pass keyword as exclude it will that jsonpath and will not compare that path value

 

if integrated with soapui/ready api feature it will save significant time in asserting response 

  • Hi Chris ,

     

    thanks for the reply ,it was basically a product feature suggestion to smartbear  team to have inbuild feature to achieve the above steps where in readyApi will provide you the drop down to exclude or include the jsonpath of to validate 

     

    Internally it will generate the json path of response and iterate over the jsonpath and ignore the jsonpath where user has opted exclude and validate the json path value with passed value for include drop down 

     validate "savedresponse" with actual response


    Exclude-$..versionid
    Include-$.customer[2].name->punter or $globalvalue

     

    Here i am validating the incoming response with "savedresponse" ignoring all the versionid and expecting name at second place to be punter or saved global variable value

     

    Remaining json path it will validate exactly with saved response

     

    As a user one just have to tell what fields he wants to ignore or validate with some value

  • ChrisAdams's avatar
    ChrisAdams
    Champion Level 3

    Hi,

    You can already do this sort of thing in ReadyAPI.

    There isn't a nice simple function(s) that let you define saved responses and validate against future tests and cherry pick values to assert, but you can do it yourself.

    You can use Groovy in Groovy Script steps in between 'standard' test steps to pretty much do all of the above.

    I've pretty much done all you've mentioned with Groovy script in between test steps.

    When looking at Groovy, the most useful thing is the ability to call a Groovy class outside of SoapUI.  I use this a lot.  When I started using SoapUI (as it was) I wrote some Groovy that I used to assert a service response against db contents.  This was great, until I realised that I'd need this script in almost every test I'd run against that service.  That meant when the service and/or data was extended with new columns, I'd then have to update every test that contained my script assertion.  This became a maintenance nightmare, until I found I can call a Groovy class that sits outside of SoapUI. I created a Groovy class to do my db assertions, I then had to update each test to call this external class.  But now, if there any content changes to the service, all I have to do is update my external class and all my tests then 'just work'.

    When building your solution, think about the above to see opportunities for calling shared checks, scripts, whatever, etc.