Ask a Question

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

Murali7660
Occasional Visitor

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 1
ChrisAdams
Frequent Contributor

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

Hi,

 

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
log.info(rawRequest);
log.info(rawResponse);

// Create the file for the request and write to it.
def requestFile = new File("/some path/request.txt");
requestFile.write(rawRequest);

// Create the file for the response and write to it.
def responseFile = new File("/some path/response.txt");
responseFile.write(rawResponse);

// Note the .write() action overwrites anty pre-existing file.

 

cancel
Showing results for 
Search instead for 
Did you mean: