88scythe
6 years agoNew Contributor
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) }