Forum Discussion

chetanpatel's avatar
chetanpatel
New Contributor
9 years ago
Solved

View Assertion Value in SoapUI

Hi,   I am doing REST testing and have made assertions to validate the JSon files. My question is, is there a way to view the assertion value only ? The web services I'm running creates a productId...
  • nmrao's avatar
    nmrao
    9 years ago

    Since I dont have the exact JSON response, using an assumed response as below to show how to assert the value

     

    Json Response :

    {
      "widget": {     
                  "debug": "on",     
                  "window": {         
                              "title": "Sample Konfabulator Widget",
                              "name": "main_window",
                              "width": 500,
                              "height": 500     
                   },
                  "image": {          
                              "src": "Images/Sun.png",         
                              "name": "sun1",
                              "hOffset": 250,
                              "vOffset": 250,
                              "alignment": "center"     
                  },
                  "text": {         
                              "data": "Click Here",         
                              "size": 36,         
                              "style": "bold",
                              "name": "text1",
                              "hOffset": 250,
                              "vOffset": 100,
                              "alignment": "center",         
                              "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
                  }
       }
    }

    Here we are going to check the value of widget -> window -> title

     

    Here is the code block for script assertion for the rest step:

     

    import net.sf.json.groovy.JsonSlurper
    def response =new JsonSlurper().parseText(messageExchange.responseContent)
    //In your case the path of the required element as mentioned below
    def expectedValue = response.widget.window.title
    //asserting that response does not have a null
    assert null != expectedValue, "Response does not contain value"
    //optionally, you can log the value from response
    log.info "Value received in the response for the element is : ${expectedValue}"