Forum Discussion

slapstick's avatar
slapstick
Regular Visitor
9 years ago

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.

soapuiRequests.each{
 //Creating file name using current date and time

//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)
 
   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:/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() 
testSteps.each{

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

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

loop output.png

No RepliesBe the first to reply