How to record rest response to file using groovy script : soapui tool
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2021
04:50 AM
10-24-2021
04:50 AM
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.
Labels:
1 REPLY 1
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2021
07:31 AM
10-24-2021
07:31 AM
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.
