free seo tool

Write soapUI Request & Response to text File using Groovy

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


//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() + "_" + 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
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)
}

7 comments:
  • Anonymous says:
    March 04, 2012

    How about getting response from a JDBC test step?

  • Sudeesh says:
    March 06, 2012

    Please refer my post JDBC Response for the details.

  • Anonymous says:
    May 08, 2012

    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.

  • Anonymous says:
    May 07, 2014

    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

  • Miten says:
    September 01, 2014

    do I add this as last step in my test run/suite so it will log all request/response ?

  • Anonymous says:
    November 18, 2014

    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)

    }

  • Tester says:
    May 12, 2016

    HOW CAN I SAVE RAW REQUEST AND RAW RESPONSE?

Post a Comment

This is a new website mainly for SOA Testers using soapUI. Let me know your thoughts/ suggestions.