Ask a Question

NPE when trying to save SOAP requests / responses

New Contributor

NPE when trying to save SOAP requests / responses


I have a testsuite with a testcase that runs two SOAP calls, for which I want to store request + response using Groovy.

Found a couple of things online and at one point I had it working as expected.

Unfortunately, after some changes on my testsuite, it fails to save the requests and responses and I can't seem to find out why. It's probably something silly but I just don't see it.

Script below.

The error I'm getting is java.lang.NullPointerException error at line: 25

Which refers to the "requests.each{" line

If I interpret this correctly, this implies that there are no such requests to take actions on.

However, the log line for "requests to save" neatly shows the two SOAP calls in my testcase.


Any help would be appreciated.



import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep

//Check where the files must be stored
PathBackSlash = testRunner.testCase.testSuite.getPropertyValue("homeDir") + "\\" + testRunner.testCase.testSuite.getPropertyValue("Folder") + "\\""Folder to use: " + PathBackSlash)

PathFrontSlash = PathBackSlash.replaceAll("\\\\", "/");
def c
c = createFolder(PathFrontSlash)
public String createFolder(def PathFrontSlash){
    File f = new File("$PathFrontSlash");
    return "Files will be stored under $PathFrontSlash"

// Timestamp for the files
def timestamp = new java.text.SimpleDateFormat("yyyyMMdd'-'HHmm.ssS").format(new Date());

//Define the object for the collection of requests in the soapUI test case
def requests = testRunner.testCase.getTestStepsOfType(WsdlTestRequestStep.class)"Requests to save: " + requests)

//Loop through each requests in the test case.

requests.each {
 //Creating file name using current date and time
 def fileName = timestamp + "_" +
 def inputFileRequest = new File(PathBackSlash + fileName+"-Request.txt")
 def inputFileResponse = new File(PathBackSlash + fileName+"-Response.txt")

//Writing soapUI request to the file

//Writing soapUI response to the file

There is a way that you can save Request/Response without having to script in Ready API which is what I would recommend. Use the datasink teststep and use property expansion to pick up full request and full response, more information about this here:


Let me know if this is helpful.


Temil Sanchez
Ready API Product Owner

Thanks for the reply, appreciate the helping hand.
I'm sure you're right and it would also be a viable option to work with datasink, but I'd honestly rather stick to fixing the existing groovy script, as I plan to do more with it than just saving. (Also it worked until recently so I feel the solution must be close by.)
Would you perhaps have an idea what could be causing the NPE?

ll take a closer look at the script and get back to you.

Temil Sanchez
Ready API Product Owner

Extra info: I just noticed that actually, both files (request and response) for the first SOAP call are getting stored.

Only, the request file contains the actual request data, while the response file is empty.

In the SOAP call itself I see a normal, valid reply.

The second SOAP call isn't getting stored (no request file, no response file), while also this request itself is going fine. / I realise that in the screenshot of this topic I had the second SOAP call disabled, but meanwhile I have enabled it again.

I though that maybe the Groovy script tried saving the request / response too soon, but even when adding delay steps of 5 seconds I'm still getting the NPE.

Showing results for 
Search instead for 
Did you mean: