Forum Discussion

Donkey2017's avatar
Donkey2017
Occasional Contributor
8 years ago

JSON - check for a specific response

Hi all, I am after a simple assertion to check that a specific parameter "status" has produced the word "COMPLETED". NMRAO helped me out a few weeks back with a script that checked if "id" produced a number. This works well but I can't modify it to check "status".

Below is part of the expected response from SOAP:

---------------------------------------

{"wf_job_group": {
   "blotter_id": null,
   "complete_date": null,
   "complete_time": null,
   "status": COMPLETED

   },
   "portfolio_id": null,
   "priority": "1",

--------------------------------------------

I need an Assertion to check if status does = COMPLETED ...... if YES then pass.

 

Any help appreciated.

Regards

1 Reply

  • nmrao's avatar
    nmrao
    Champion Level 3

    Try below Script Assertion.

     

    //Below Script Assertion should do the job
    def json = new groovy.json.JsonSlurper().parseText(context.response)
    def actualStatus = json.wf_job_group.status
    assert actualStatus instanceof String, 'status is not string type'
    assert 'COMPLETED' == actualStatus, 'actual status does not match with expected'