How to save the request and response in a folder along with time stamp
Hi
I am trying to save the request and response in a folder along with time stamp. I am able to save the response with timestamp. But request is saving with empty file. please find the below code :
import groovy.json.JsonOutput;
testCase.testStepList.each{
type = it.config.type
name = it.name
response = it.getPropertyValue("Response")
request = it.getPropertyValue("Request")
if(type == "restrequest"){
def pretty = JsonOutput.prettyPrint(response);
def req = JsonOutput.prettyPrint(request);
date = new Date()
dateFormat = new java.text.SimpleDateFormat('yyyyMMdd-HHmmss')
shortDate = dateFormat.format(date)
def responseFile= "C://Users//SS//Desktop//proj//"+name.toString()+shortDate+"_response.doc";
def requestFile= "C://Users//SS//Desktop//proj//"+name.toString()+shortDate+"_request.doc";
def rsfile = new File(responseFile);
def reqfile = new File(requestFile);
rsfile.write(pretty, "UTF-8");
reqfile.write(req,"UTF-8");
}
}
Request file has the user name and password in encrypted form with multiple columns.
Thanks.
Hi Sirisha2020 !
This query involves custom scripting, let's see if what I found would be of help!
This script gets the request data and raw response with headers:
def myRequestStep = testRunner.testCase.getTestStepByName('TestStepName') def GetrequestData = new String(myRequestStep.testRequest.messageExchange.rawRequestData) def GetresponseData = new String(myRequestStep.testRequest.messageExchange.rawResponseData) log.info ("Request = " + GetrequestData) log.info ("Response = " + GetresponseData)
You can try to modify this script to see if that would fit your needs!