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

Posted: May 24, 2011 in Assertion in soapUI, groovy, soapUI
Tags: , , , , , , , , ,
@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.“~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~”)“Request size :” + messageExchange.requestContent.size())“Response size :” + messageExchange.responseContent.size())“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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s