Forum Discussion

dmigarashi's avatar
dmigarashi
Occasional Visitor
8 years ago

Saving several xml responses

Hi guys! I am using SoupUI NG to submit several xml requests, and I would like to store these responses.

I tried to use the dump file resource, but it saves only one response.

How can I store each response xml file?

 

Thanks in advance.

  • groovyguy's avatar
    groovyguy
    Community Hero

    You can use a groovy script assertion on required test steps like follows:

     

    def projDir = context.expand( '${projectDir}' );
    
    def label = context.testCase.getTestStepAt(context.getCurrentStepIndex()).getLabel();
    
    def response = messageExchange.responseContentAsXml.toString();
    
    log.info(response);
    
    def responseFile = new File(projDir + "\\" + label + ".xml");
    
    responseFile << response;
    
    assert responseFile.length() > 0;

     

     

     

  • nmrao's avatar
    nmrao
    Champion Level 3

    dmigarashi,

     

    There are multiple ways to save the response. One of the way, like groovyguy suggested, is to use Script Assertion.

     

    Below is for information benefit of others.

     

    I was thinking for alternative ways and got strike with ways such as TearDown Script, Events etc.,

     

    If I were to do the same, go for the Events because, Script in single place and gets fired automatically.

     

    In the Events also, there are multiple available to handle this case as given below:

     

     - SubmitListener.afterSubmit

     - RequestFilter.afterRequest

     - TestRunListener.afterStep

     - MonitorListener.onMessageExchange

     

    I would go with last one as I feel it is more appropriate based on the descriptions here in the documentation. However, I could not get that working.

     

    So, trying with 1st one i.e., SubmitListener.afterSubmit Event.

     

    Create a project level custom property LOCATION and provide directory name where the responses needs to be saved say C:/Users/apps/Data (Use / as path separator even on windows)

     

    Here is the script that needs to go into above mentioned event:

     

    https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/readyapi/events/SubmitListener_AfterSubmit/SaveResponse.groovy

     

     

    EDIT:

     

    Above script is refactored / moved to below location:

     

    https://github.com/nmrao/readyAPIGroovyScripts/blob/master/groovy/events/SubmitListener/afterSubmit/SaveResponse.groovy

     

  • nmrao's avatar
    nmrao
    Champion Level 3
    dmigarashi, not sure if the issue still persists.

    Would you mind showing the structure of your test case / suite with some context?