Below Groovy Script is an example of how to write the requests and responses available in a test case to a text file.
In this sample groovy script, we are getting an object of all the test requests available in the test case. Then by using a "each" loop we capture all the request and response XMLs. By using the file creation groovy script, we create two files to write the SOAP request and response. This script will also name the file using the current date and time. This is achieved by using the Groovy Script to capture the current date and time.
def soapuiRequests = testRunner.testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep )
//Groovy Script to loop through each requests in the test case.
//Groovy Script to loop through each requests in the test case.
soapuiRequests.each{
//Creating file name using current date and time
Date startTime = new Date();
def cur_Time = startTime.getMonth() + "_" + startTime.getDate();
cur_Time = cur_Time + "_" + startTime.getHours() + startTime.getMinutes() +startTime.getSeconds()
def fileName = it.name + "_" + cur_Time
def inputFileRequest = new File("C:\\"+ "Request_" + fileName+".txt")
def inputFileResponse = new File("C:\\"+ "Response_" + fileName+".txt")
//Writing soapUI response to the file
//Writing soapUI response to the file
inputFileResponse.write(context.testCase.getTestStepByName(it.name).getProperty("response").value)
//Writing soapUI request to the file
//Writing soapUI request to the file
inputFileRequest.write(context.testCase.getTestStepByName(it.name).getProperty("request").value)
}
How about getting response from a JDBC test step?
Please refer my post JDBC Response for the details.
Thanks very much! I've noticed that my resulting filenames are one month off. For example, while we're currently in the month of May, the filename uses "4" (as in April). It gets the day and time correctly, though.
Hi i m new in soapui testing . Please let me know what is this "it" object doing. I m noticing it in many lines like (it.name) .
Please help
do I add this as last step in my test run/suite so it will log all request/response ?
Thanks mate.. mad my day .. I changed the code as per my need of file having request as well as response.
//Define the object for the collection of requests in the soapUI test case
def soapuiRequests = testRunner.testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep )
//Groovy Script to loop through each requests in the test case.
soapuiRequests.each{
//Creating file name using current date and time
Date startTime = new Date();
def cur_Time = startTime.getMonth() + 1 + "_" + startTime.getDate() + "_" + startTime.getHours() + startTime.getMinutes() +startTime.getSeconds()
def fileName = it.name + "_" + cur_Time
def path = "C:\\MyOutDir\\"
def apiFile = new File(path + fileName + ".xml")
//def inputFileRequest = new File("C:\\"+ "Request_X" + fileName+".xml")
//def inputFileResponse = new File("C:\\"+ "Response_X" + fileName+".xml")
apiFile.write("\n\n");
apiFile.append(context.testCase.getTestStepByName(it.name).getProperty("request").value)
apiFile.append("\n\n\n\n");
apiFile.append("\n\n");
apiFile.append(context.testCase.getTestStepByName(it.name).getProperty("response").value)
apiFile.append("\n\n\n\n");
//Writing soapUI response to the file
//inputFileResponse.write(context.testCase.getTestStepByName(it.name).getProperty("response").value)
//Writing soapUI request to the file
//inputFileRequest.write(context.testCase.getTestStepByName(it.name).getProperty("request").value)
}
HOW CAN I SAVE RAW REQUEST AND RAW RESPONSE?