Forum Discussion

livetoski78's avatar
livetoski78
New Contributor
6 years ago
Solved

How to set the value of a test case property from JSON response via Groovy?

I'm using SoapUI open source for REST testing, so I need to do things the hard way via Groovy (no JSON property transfer).  I have a test step that places a call to /workspaces, creating a new worksp...
  • nmrao's avatar
    nmrao
    6 years ago

     

    livetoski78 ,

    Please use below script assertion to the REST Request Test step( that means remove the additional groovy script test step)

     

    /**
    * Below is the script assertion for the REST Request step
    * which extracts the data id and set it test case property
    **/
    assert context.response, 'Response is empty or null'
    def json = new groovy.json.JsonSlurper().parseText(context.response)
    //Change the property name as needed
    log.info json.data.id
    context.testCase.setPropertyValue('ID', json.data.id.toString())