Forum Discussion

88scythe's avatar
88scythe
New Contributor
5 years ago

NPE when trying to save SOAP requests / responses

Hi


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") + "\\"
log.info("Folder to use: " + PathBackSlash)

PathFrontSlash = PathBackSlash.replaceAll("\\\\", "/");
def c
c = createFolder(PathFrontSlash)
public String createFolder(def PathFrontSlash){
    File f = new File("$PathFrontSlash");
    f.mkdirs();
    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)
log.info("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 + "_" + it.name
 def inputFileRequest = new File(PathBackSlash + fileName+"-Request.txt")
 def inputFileResponse = new File(PathBackSlash + fileName+"-Response.txt")

//Writing soapUI request to the file
 inputFileRequest.write(context.testCase.getTestStepByName(it.name).getProperty("request").value)

//Writing soapUI response to the file
 inputFileResponse.write(context.testCase.getTestStepByName(it.name).getProperty("response").value)
  }

4 Replies

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

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