Showing results for 
Search instead for 
Did you mean: 

Get Soap Response and Soap Requests of all Test Steps in a Testcase

Regular Visitor

Get Soap Response and Soap Requests of all Test Steps in a Testcase

Hi everyone,


I started using the free version of SOAP UI recently and was wondering how to properly implement a loop to get the soap  Response and Request of every test step and collate them into a file. I also looked into the API documentation but I was lost and I don't know which one to use. Anyway, I was able to retrieve a specific teststep response and request using the code below. 


def response = context.expand( '${TestStepName#Response}' )
def rawrequest = context.expand( '${TestStepName#RawRequest}' )
def soapresponse = 'c:/users/Desktop/soapoutput/a.doc'
def soaprawrequest = 'c:/users/Desktop/soapoutput/b.doc'
def f = new File(soapresponse)
def g = new File(soaprawrequest)
f.write(response, "UTF-8")
g.write(rawrequest, "UTF-8")

I also searched the net and found this snippet regarding the teststep loop




//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.

 //Creating file name using current date and time

//Writing soapUI response to the file
//Writing soapUI request to the file
   Date startTime = new Date();
 def cur_Time = startTime.getMonth() + "_" + startTime.getDate();
 cur_Time = cur_Time + "_" + startTime.getHours() + startTime.getMinutes() +startTime.getSeconds()
 def fileName = + "_" + cur_Time
 def inputFileRequest = new File("C:/Users/Desktop/soapoutput"+ "Request_" + fileName+".txt")
 def inputFileResponse = new File("C:/Users/Desktop/soapoutput"+ "Response_" + fileName+".txt")

There were no problems during the execution of the script but the file is not generated. This is the response after execution.


script output.png



Any help will be much appreciated.



Just an update,


Using the code below I can now extract the soap response from each teststep. Unfortunately this also retrieves the value of "response" from all test steps including groovy step, etc. which results to "null" being displayed in the log output.Also "a.doc" has no content.



// This will get the list of all testSteps in the testCase
def testSteps = context.testCase.getTestStepList() 

//The variable definition below will loop through the teststep abd retrieve the response
 def z = context.testCase.getTestStepByName('response')
 def soapresponse = 'c:/users/Desktop/soapoutput/a.doc'
 def f = new File(soapresponse)

//def soaprawrequest = 'c:/users/Desktop/soapoutput/b.doc'
//def g = new File(soaprawrequest)
//g.write(rawrequest, "UTF-8")
//def zz = context.testCase.getTestStepByName('response')

loop output.png

New Here?
Join us and watch the welcome video:
Top Kudoed Authors