Forum Discussion

zareen's avatar
zareen
New Contributor
6 years ago

How to assert if a particular value exist in the response using Script Assertion

I need to traverse through the list and reach an element based on required value. Before getting inside the loop to traverse, i want to make sure if that value exists in the response . How can i achieve this using Assert statement?

4 Replies

  • groovyguy's avatar
    groovyguy
    Champion Level 1

    Here's how I would do this:

     

    import com.eviware.soapui.support.XmlHolder
    
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
    
    // Fail if the response does not have the value
    assert (messageExchange.responseContentAsXml.contains("Value to be checked"));
    
    
    • sanj's avatar
      sanj
      Super Contributor

      Looks like we have this topic twice.

      groovyguy you response is right on the money

      I just gave high level psuedocode.

       

  • zareen's avatar
    zareen
    New Contributor

    Thank you very much for this! This worked for me :manhappy:

     

    • groovyguy's avatar
      groovyguy
      Champion Level 1

      Glad it worked! Don't forget to "Accept as a solution" so future forum visitors can easily see!