NPE when trying to save SOAP requests / responses
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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) }
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
https://support.smartbear.com/readyapi/docs/soapui/steps/data-sink.html?#datasink-types
Let me know if this is helpful.
Ready API Product Owner
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ll take a closer look at the script and get back to you.
Ready API Product Owner
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
