Forum Discussion

Murali7660's avatar
Occasional Visitor
3 years ago

How to record rest response to file using groovy script : soapui tool

How to record rest response to local directory files using groovy script. I tried files are creating but responses are not saving, how to do that for rest api requests? Pls help me guys.

Advance thanks. 

1 Reply

  • ChrisAdams's avatar
    Champion Level 2



    Pretty straightforward.  Create a Groovy test step after the API call.  In the Groovy step, add....


    def myRequestStep = testRunner.testCase.getTestStepByName(['SOAP Request']);  // Substiture 'SOAP Request' with your step name.
    def rawRequest = new String(myRequestStep.testRequest.messageExchange.rawRequestData);
    def rawResponse = new String(myRequestStep.testRequest.messageExchange.rawResponseData);
    // Log the raw request and raw response;;
    // Create the file for the request and write to it.
    def requestFile = new File("/some path/request.txt");
    // Create the file for the response and write to it.
    def responseFile = new File("/some path/response.txt");
    // Note the .write() action overwrites anty pre-existing file.