Ask a Question

Get TimeTaken from a REST POST request

Occasional Contributor

Get TimeTaken from a REST POST request

I'm trying to write the response times for SOAP and REST calls from the my test cases to a database. I have it working with one exception. The REST POST requests are giving me the following: ERROR:java.lang.NullPointerException: Cannot invoke method getTimeTaken() on null object


I'm using the TestListener.AfterRun event. Here is the relevant code:


for (myResult in testRunner.getResults())
    if((myResult.testStep.config.type == "request") || (myResult.testStep.config.type == "restrequest")){
        //if this is a request we want to get the amount of time it took
        //if the repsonse for the request takes longer than 2 seconds (2000 milliseconds)
        //Mark it as an SLA Failure
        if(myResult.response.timeTaken > 2000){
            SLAFailureValue = "True"


My failure is on the BOLD and Italics line.


Why is this working for GET requests buy not POSTs?

(ALSO as a note I use this exact code on the SOAP side and I haven't seen any issues there)


Super Contributor

This sounds a bit odd, I tried a simple rest request test step, with a GET request, and then added a Groovy test step after it with the following code:


testRunner.getResults().each() { result ->
	assert result.hasResponse()



Now here's the odd thing when my REST request test step has no assertions, all was OK, but once I added an assertion (a simple "Valid HTTP Status Code" one) I then see the behaviour you describe, albeit via hasResponse() returning false (even having disabled assertions seemed to cause the issue).


This doesn't sound right I think I would raise a support call with Smartbear, at this link:


Please post back with any details Smartbear provide. Note: I am using Ready API 1.7 I had a quick look at the release notes to see if a later version had a fix, but couldn't see anything similar.


As a side note, when I added a Script assertion to the REST request with:


assert messageExchange.hasResponse()


It seamed to work correctly.

Occasional Contributor

Redford.....Nice catch!! I removed (deleted, disabling doesn't work) the assertion on the REST call and my script worked.


I'll send this over to support and come back when I hear back from them.

Just wanted to follow up since it's been about a week. I opened Case #0023601. Someone replied back that they would reproduce and get back to me, but I'm still waiting to hear back.

I heard back from support. the issues is no longer seen in 1.9.0 maintenance builds. If you see this error you can download that. I asked when the 1.9.0 build will be available to the public but have not heard back yet. Hope this helps everyone.

Thanks for posting back the information, that is really useful.


From what I've seen Smartbear rarely issue official point releases. Fixes usually just appear in the next feature release.

Occasional Contributor

Thanks....I figured that, but I'm hoping that they are due for a release soon as we typically don't like to take maintenance release and RC releases for testing. But good to know.

SmartBear Alumni (Retired)

FYI, the maintenance releases are not to be confused with a release candidate or a beta. The are the real thing (the release) but with selected important bug fixes added. It shouldn't give you surprises or half baked features.

Showing results for 
Search instead for 
Did you mean: