Tuesday, May 24, 2011

Groovy IV - how to log response size, request size, time taken

@Title : Gr-oooo-vy Code IV
@Description : to log the response size, request size and time taken to get the response data.
@Author : Pradeep Bishnoi

Last few blogs were related to Groovy script, however i didn't mentioned about one of most useful groovy code lines which can be very handy when you want to verify the certain things without actually looking into the response data.

The cases where you want to time taken by server to provide the response, or the validating the response data by verifying/comparing  the size of response data or request data. I personally use these script lines to frequently see all the logged data when executing the testcases/testsuite for validating the correctness of my data. For instance, if you recv a valid response for a request size would be xx Bytes and whenever there is any error it would be yy Bytes. Similarly, if the timetaken by response is exceeding your assigned/recommended values, you can use this to verify (note: you can also use 'assert' keyword to use any specific value as the assertion).

Use the below provided code lines in the groovy script assertion of each test step in a testcase.

log.info("Request size :" + messageExchange.requestContent.size())
log.info("Response size :" + messageExchange.responseContent.size())
log.info("Time :" + messageExchange.getTimeTaken())

With every run of the teststep, script log section/tab will update the display with the size of request, response & timetaken to provide the response.


  1. this is also giving the time taken for firing the request. I have checked the response time manually and for my request it was taking 80 seconds when I used my stop watch and this method gives 5852ms

  2. is messageExchange a groovy method ?