Forum Discussion

mpunjani's avatar
mpunjani
Occasional Contributor
14 years ago

Automatically saving request and response files

Hi All,

I am using SoapUI Pro 3.6.1. I would like to automatically save all the request and response messages (executed) to any file (no matter which extension).

I found the script below (FYI I dont know anything about scripts or how they work)
filePath = 'c:/'
fos = new FileOutputStream( filePath + testStepResult.testStep.label + '.txt', true )
pw = new PrintWriter( fos )
testStepResult.writeTo( pw )
pw.close()
fos.close()

I closed my SoapUI project and restarted and ran a test request from one of the test suite. But there was no output file in C drive.

I think I will require some basic information here (step-by-step)

Can anyone please help?

Thanks
Mak

3 Replies

  • Hi Mak,

    You can add a groovy script step as the last step of ur test case.
    Try following code in the groovy script step.
    It will create a .txt file.

    def filename = "C:\\<filename>.txt"
    logFile = new File(fileName)
    def request = context.expand("<Your request>")
    def response = context.expand("<Your response>")

    logFile.append("\nRequest: " + request)
    logFile.append("\nResponse: " + response)



    //Step 3 and 4 can be also created by right clicking the blank space, selecting "Get data" and then selecting the request.

    Regards,
    AnkitaT
  • mpunjani's avatar
    mpunjani
    Occasional Contributor
    Hi Ankita

    Thanks for that. It worked

    Anyway but the response and request messages starts one after another. How can I automatically press enter after the word 'request' and 'response'?

    Thanks
    Mak

    ankitaT wrote:
    Hi Mak,

    You can add a groovy script step as the last step of ur test case.
    Try following code in the groovy script step.
    It will create a .txt file.

    def filename = "C:\\<filename>.txt"
    logFile = new File(fileName)
    def request = context.expand("<Your request>")
    def response = context.expand("<Your response>")

    logFile.append("\nRequest: " + request)
    logFile.append("\nResponse: " + response)



    //Step 3 and 4 can be also created by right clicking the blank space, selecting "Get data" and then selecting the request.

    Regards,
    AnkitaT
  • mpunjani's avatar
    mpunjani
    Occasional Contributor
    I fixed that as well. Thanks again.

    mpunjani wrote:
    Hi Ankita

    Thanks for that. It worked

    Anyway but the response and request messages starts one after another. How can I automatically press enter after the word 'request' and 'response'?

    Thanks
    Mak

    ankitaT wrote:
    Hi Mak,

    You can add a groovy script step as the last step of ur test case.
    Try following code in the groovy script step.
    It will create a .txt file.

    def filename = "C:\\<filename>.txt"
    logFile = new File(fileName)
    def request = context.expand("<Your request>")
    def response = context.expand("<Your response>")

    logFile.append("\nRequest: " + request)
    logFile.append("\nResponse: " + response)



    //Step 3 and 4 can be also created by right clicking the blank space, selecting "Get data" and then selecting the request.

    Regards,
    AnkitaT