Hoe can I automatically store response header and body in a file as a log for a test case? (I use Katalon in command line mode)
I do not think Katalon Studio supports automatically storing response and body in a file.
You need to write test case codes to write data into files for yourself.
Getting JSON body from the HTTP response is easy, writing a JSON into a file is also easy.
But it is not very easy to resolve paths for files appropriately for logging purpose.
I have just posted another tips:
This post presents an external java library named Materials. The Materials library makes it easy to resolve output file path in a well structured format like:
${projectDir}/Materials/${testSuiteName}/${testSuiteTimestamp}/${testCaseName}/${subdirs}/${fileName}
for example
./Materials/TS07_visit_a_web_site/20180919_132138/TC07_visit_a_web_site/1 CURA_Homepage.png
This format of path includes a directory layer of Timestamp . This makes it easy to store files chronologically just like Katalon’s Reports. It would be best suited for logging purpose.
I have written another post
I believe I have developed a useful tool for logging HTTP Response Header and Bodies.
EDIT in Sept 2021
I have abandoned the Materials library. I won’t maintain it any longer. Please do not use it.
Instead, I newly developed a library named materialstore
. Using the materialstore library, I createded a demo project Visual Inspection in Katalon Studio. This sample Katalon Studio project includes a Test Case that
- visiit “https://www.google.com/” and make search with key “takalon”
- take PNG screenshots of web pages, save them into local folder named
<projectDir>/store
- take HTML page source of web pages, save them into local folder names
<projectDir>/store
- generate a HTML Report in which you can see the screenshots and page sources.
If you can write a test case script that make a respose to webservice, the you should be able to write 2 lines:
String responseText = response.getContentText()
Material m = store.write(jobName, jobTimestamp, FileType.JSON, metadata, responseText)
This will be sufficient to store the JSON response into file.
If you do not like my solution, then a simplest way will be 2 lines of Groovy script:
File f = new File("filename.json")
f.text = response.getResponseText()