Forum Discussion

DGramß's avatar
DGramß
Occasional Contributor
16 years ago

Assertion Script

Have read all the docu and searched this forum, but still don't see how to do this....

I have a CONTAINS assertion in a Test Step which I now want to put in a groovy script.

Have this code:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )

def holder = groovyUtils.getXmlHolder( "Test_Request_sPUA#Response" )

How can I test with an assertion if the response stored in holder contains the string "" ?

Tnks, Kevin

4 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    You can do it without assertion in groovy like this :


    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder( "Test_Request_sPUA#Response" )
    if (holder.xml.indexOf("<Produkt>") > -1)
    log.info "have it"
    else
    log.info "don't have it"


    robert
  • DGramß's avatar
    DGramß
    Occasional Contributor
    Thank you very much, that works fine.

    I have set up an excel datasink which successfully collects the material_number used and now I want to write in the columns beside it whether the product for this material-number was found or not.

    Have the following code in my test step groovy script and a property called produkt_found in my datasink_excel step:

    def response = holder.getXml()


    if (holder.xml.indexOf("") > -1)
    {
    log.info "have it"
    produkt_found = "Found"
    }
    else
    {

    log.info "don't have it";

    produkt_found = "Not found"   
        }

    So my question is, what code do I need in the value box of the property in the datasink so that it collects the value "Found" or "Not Found" set by the groovy script?

    I promise sincerely that I have rtfm and googled my socks off before posting this
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello!

    The variables set in the groovy script are lost once the script is done executing. What you need to do is store the values directly to the data sink from the script. This is done as follows:


    def response = holder.getXml()


    if (holder.xml.indexOf("<Produkt>") > -1)
    {
      log.info "have it"
      testRunner.testCase.testSteps['DataSink'].properties['produkt_found'].value = 'Found'
    }
    else
    {
      log.info "don't have it"
      testRunner.testCase.testSteps['DataSink'].properties['produkt_found'].value = 'Not Found'
    }


    (Replace 'DataSink' with the name of your DataSink teststep)

    Regards,
    Dain
    eviware support
  • DGramß's avatar
    DGramß
    Occasional Contributor
    That hit the spot!  Will check out the testRunner stuff, many thanks...