cancel
Showing results for 
Search instead for 
Did you mean: 

Output raw request and response including headers to a file

Highlighted
Occasional 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.
3 REPLIES 3
Highlighted
Super Contributor

How about this:

myRequestStep = testRunner.testCase.getTestStepByName('my test step name')
myFile.append(new String(myRequestStep.testRequest.messageExchange.rawRequestData))
myFile.append(new String(myRequestStep.testRequest.messageExchange.rawResponseData))
"Ignorance more frequently begets confidence than does knowledge"
Highlighted
Occasional Contributor

M Mac, you are a star. Thanks very much, that worked perfectly.
Highlighted
Community Leader

@M_McDonald

 

Thanks for the post, this works perfectly fine.. I was looking for the solution from past one week..thanks a ton 🙂 .. Keep posting good work.


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors