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, and everytime I run the file it generates a new productId. I have the assertion to validate there is a productId there. I need it to show me just the productId. In the report, I have a whole bunch of stuff I don't need, I just need to highlight or view the productId. If anyone can help me out, thank you

 

 

Chetan

  • 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}"

     

     

5 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    Is it enough to just log the required stuff?
    • chetanpatel's avatar
      chetanpatel
      New Contributor
      It is, but I would like to know the value of my product because it changes every time I run the service. I want to verify that a new product is there. Any help/input would be great. Thank You
      • nmrao's avatar
        nmrao
        Champion Level 3
        Ok. It would be of help if you can show the response, so that what kind of assertion would be fit. By the way, is it an autogenerated id or as per the user input value that it will be created by web service?