meldoobs
12 years agoOccasional Contributor
Output raw request and response including headers to a file
Hi all,
I'm very new to using groovy scripts and have very little programming knowledge so i've been picking up bits of scripts from the forum and adapting them.
So far i have been able to output the REST requests and responses i'm interesting in to a file by using the following statements in a groovy script immediately following my test step (eg not a tear down script)
myFile.append( context.expand('${my test step name#Request}') ) and
myFile.append( context.expand('${my test step name#Response}') )
This is great in that it outputs the actual values rather than the parameter names in my xml.
But i want to go one stage further and output the whole raw xml responses, including the http return code and headers etc. eg. exactly what you would see if you clicked on the "raw" tab in the UI.
Like this...
HTTP/1.1 200 OK
Date: Wed, 06 Feb 2013 21:42:33 GMT
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Accept-Ranges: none
Server: anyoldserver.com.au
Content-Type: application/xml
Transfer-Encoding: chunked
Connection: close
<?xml version="1.0" encoding="ISO-8859-1" ?>
<blahblahblah>
......
</blahblahblah>
Thanks in advance for any help.
I'm very new to using groovy scripts and have very little programming knowledge so i've been picking up bits of scripts from the forum and adapting them.
So far i have been able to output the REST requests and responses i'm interesting in to a file by using the following statements in a groovy script immediately following my test step (eg not a tear down script)
myFile.append( context.expand('${my test step name#Request}') ) and
myFile.append( context.expand('${my test step name#Response}') )
This is great in that it outputs the actual values rather than the parameter names in my xml.
But i want to go one stage further and output the whole raw xml responses, including the http return code and headers etc. eg. exactly what you would see if you clicked on the "raw" tab in the UI.
Like this...
HTTP/1.1 200 OK
Date: Wed, 06 Feb 2013 21:42:33 GMT
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Accept-Ranges: none
Server: anyoldserver.com.au
Content-Type: application/xml
Transfer-Encoding: chunked
Connection: close
<?xml version="1.0" encoding="ISO-8859-1" ?>
<blahblahblah>
......
</blahblahblah>
Thanks in advance for any help.