I have made a demo project and published at
- GitHub - kazurayam/KatalonDiscussion10209: A Katalon Stuido project where HTTP Response Header and Body are logged into disk in the Materials directory
- I want to test a Web Service API, like katalon-studio-samples/jira-api-tests
- I want to save HTTP Response Header and Response Body into files in JSON format.
- I want to retain files chronologically for logging purpose. I do not like overwriting files. If I execute a single Test Suite 3 times, then I want to retain 3 sets of json files.
- I will look back retained sets of json files frequently. So I want a nice GUI that enables me to retrieve stored files quickly.
I would introduce Materials, a java/groovy library that resolves output file paths in a well-structured format. The
com.kazurayam.materials.MaterialRepository class provides convenient methods with which I can solve the above-mensioned problems easily.
resolveMaterialPath(String testCaseId, String fileName)method returns
java.nio.file.Pathobject for a File to be created. The path would be in the format of
makeIndex()method generates the
./Materials/index.htmlfile. This is a simple viewer for the
- download the zip of this project from releases page.
- unzip it. You will obtain a folder named
- start your Katalon studio, and open the project
- open a Test Suite named
Test Suites/TS_Materials_appliedand run it.
- you should run it multiple times. e.g., try 3 times.
This project is based on the katalon-studio-samples/jira-api-tests project. I added a few codes on it without changing files of the original project.
Test Suites/TS_Materials_applied executes
Test Cases/Simple examples/api-2-issue/Get issue/Get an issue by Key - 1 - Materialized. The test case code looks like this:
// Send the request and get the responseresponse = WS.sendRequest(findTestObject('Simple examples/api-2-issue/Get issue/Get an issue by Key'))// Verify the responseWS.verifyResponseStatusCode(response, 200)// make MaterialRepository accessibleMaterialRepository mr = (MaterialRepository)GlobalVariable.MATERIAL_REPOSITORY// store the HTTP Response Headers into filePath path2 = mr.resolveMaterialPath(GlobalVariable.CURRENT_TESTCASE_ID, "headers.json")Map<String, List<String>> headerFields = response.getHeaderFields()String headersJson = CustomKeywords.'com.kazurayam.ksbackyard.WebServiceTestSupport.convertHeaderFieldsToJsonString'(headerFields)path2.toFile().append(headersJson, 'utf-8')// store the HTTP Response Body into filePath path3 = mr.resolveMaterialPath(GlobalVariable.CURRENT_TESTCASE_ID, "body.json")String body = response.getResponseBodyContent()path3.toFile().append(body, 'utf-8')
This test case send a HTTP GET request to a RESTFul URL https://katalon.atlassian.net/rest/api/2/issue/KD-1000?expand=names&fields=summary,status,issuetype,assignee,project,priority,description&= . The test case makes a bit of assertions over the response. And it writes the HTTP Response Headers and Body into files on local disk in JSON format.
Test Suites/TS_Materials_applied, a new folder
<projectDir>/Materials will be created. In there you can find a folder tree and a HTML file named
You can browse the index.html. It will look like this:
In the index you will find as many records of test suite runs as you executed. In the above screenshot, you can find 3 times of test suite run recorded.
Each test suite run contains a record of test case run, which contains links to the files created.
By clicking the links, you can view the files in modal widdow. Here is
The created files has a path like this:
A concrete path example:
./Materials/TS_Materials_applied/20181018_140249/Simple examples.api-2-issue.Get issue.Get an issue by Key - 1 - Materialized/header.json
Please note that this folder tree contains a timestamp layer
yyyyMMdd_hhmmss. Having a timestamp layer enables you to retain outputs as long as you like until you intensionally delete them. This chronological folder structure is best fit for logging purpose.
Here I would describe, step by step, for you how to recreate a Katalon Studio project which has the Materials library builting and enabled.
- create a new katalon project, or clone some existing project. For example, clone the katalon-studio-samples/jira-api-testsproject.
- import Materials-0.22.0.jar or heigher into your katalon project. Refer to the Katalon documentation 'Import Java library’for operation instruction. You can download jar from release page. Or you can reuse the jar already imported into this project.
- Edit Profiles > default in your project. Add
MATERIALS_REPOSITORYwith type Null. Add
CURRENT_TESTCASE_IDwith type String.
- Create a Test Listener in your project, and copy & paste the source of Tests. You need not change it at all. If you have your own test listener, then carefully edit it so that your test listener works similar to the
- Add a test case named
Test Cases/cleanMaterialsin your project. Copy and paste the source of
Test Cases/clearMaterials. You need not to change the code at all.
- Add a test case name
Test Cases/makeIndexin your project. Copy and paste the source of
Test Cases/makeIndex. You need not to change the code at all.
- Now you add your own test case which actually test your target Web Services. Refer to Test Cases/Simple examples/api-2-issue/Get issue/Get an issue by Key - 1 - Materialized as an example.
- Add a test suite which calls 3 test cases —
cleanMaterials, your own test case and
makeIndex. . The test suite can have any name you like.
- In the definiton of test suite, there is a row labeled
Run. In the Run row, there are toggle controls. You can choose each test cases to run or not. If you toggle on the
cleanMaterialstest case, then the
./Materialsdirectory will be cleaned every time when the test suite runs. If you toggle off, then you can see multiple records of test sute runs accumulated in the index.html viewer.