Forum Discussion

GIE_SI2M_Suppor's avatar
GIE_SI2M_Suppor
New Contributor
15 years ago

data driven Test Case - saving requests / responses to an ex

Hello,

First, My apology for my bad english.

I'm a new SOAPUI PRO user (this post already exist in the soapUI Board ).

Here is my issue :

I try to save responses (including attachments) to an external folder and unfortunately I can't succeed adapting the "groovy scripts" I found in the Forum, or with the parameters (TestRequestProperties etc…).

• Requirements are:
- Automatically export Xml response in a dedicated Folder (that's work!)
- Automatically export response attachments in a dedicated Folder (that don’t work :/)

• Request :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://xxxxxxx/">
<soapenv:Header/>
<soapenv:Body>
<ws:recevoirCr_Demande>
<codeCollecteur>JDC</codeCollecteur>
<motDePasse>JDC01</motDePasse>
<versionDadsu>V01X04</versionDadsu>
<crNouveau>OUI</crNouveau>
<crDemandeArray/>
</ws:recevoirCr_Demande>
</soapenv:Body>
</soapenv:Envelope>

• Response :
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:recevoirCr_Reponse xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:ns2="http://xxxxxx/">
<envCrRetourneArray>
<envCrRetourne>
<idEnvDadsu>DAD_JDC_001000000000000000000000000000000006</idEnvDadsu>
<nomEnveloppeCr>CR_DAD_JDC_001000000000000000000000000000000006_001_CR2.zip</nomEnveloppeCr>
<fichier>
<Include href="cid:1998f71c-c8e9-4645-a14c-16ea092bb1dd@example.jaxws.sun.com" xmlns="http://www.w3.org/2004/08/xop/include"/>
</fichier>
</envCrRetourne>
<envCrRetourne>
<idEnvDadsu>DAD_JDC_001000000000000000000000000000000002</idEnvDadsu>
<nomEnveloppeCr>CR_DAD_JDC_001000000000000000000000000000000002_001_CR2.zip</nomEnveloppeCr>
<fichier>
<Include href="cid:fe53e511-3d37-4069-8ddf-51c345a9d7ae@example.jaxws.sun.com" xmlns="http://www.w3.org/2004/08/xop/include"/>
</fichier>
</envCrRetourne>
</envCrRetourneArray>
<crIndisponibleArray/>
<codeRetour>00</codeRetour>
<libelleRetour>Prise en compte correcte</libelleRetour>
</ns2:recevoirCr_Reponse>
</S:Body>
</S:Envelope>

• You can find 1 to x attachments in the response, the attachment is always a .zip file.

• The idea is :
1. Each time I run the testcase or testsuite to create a folder named: “AAAAMMDD HHMMSS”-“name of the testcase”
2. In this folder simply save all the attachments (the filename is the response: “nomEnveloppeCr” propertie).

Could you help me resolve that?

Looking forward to hearing from you

Regards

Pierre

2 Replies

  • Hi Pierre,

    hmm.. one way to do this would be to create a project event handler for the TestRunListener.afterStep event in which you would check if the executed teststep was a request teststep (via its config.type property) and then check its requests response object for attachments.. ie something like this:

    // was this a SOAP request?
    if( testStepResult.testStep instanceof WsdlTestRequestStep )
    {
    // loop the attachments
    for( a in testStepResult.testStep.testRequest.response.attachments )
    {
    // create filename
    def fileName = ...

    // write to file
    com.eviware.soapui.support.Tools.writeAll( new FileOutputStream( fileName ), a.inputStream )
    }
    }

    Hope this helps!

    regards,

    /Ole
    eviware.com
  • Hi Ole!

    Thank you for your Help!

    It's work fine now.

    I just didn't understood the first part , the "was this a SOAP Request" ones.

    So we managed to make somethink like :
    (after the def Location and getResponseFilename(name) part)

    int i=0
    for( a in testRunner.testCase.testSteps["Requete RC"].testRequest.response.attachments )
    {
    i++
    def fileName = context.expand( '${Requete RC#Response#declare namespace ns2=\'http://ws_dadsu_cp_cr.si2m.fr/\'; //ns2:recevoirCr_Reponse[1]/envCrRetourneArray[1]/envCrRetourne['+i+']/nomEnveloppeCr[1]}' )

    com.eviware.soapui.support.Tools.writeAll( new FileOutputStream( Location+fileName ), a.inputStream )
    }

    It work just fine, as far we tried.

    Regards

    Pierre