Forum Discussion

88scythe's avatar
New Contributor
5 years ago

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

4 Replies

    • 88scythe's avatar
      New Contributor
      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?
      • TSanchez_1's avatar

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