I published a GitHub repository:
This project provides a Groovy class com.kazurayam.ks.testobject.ObjectRepositoryGarbageCollector
class
in a jar file. This class is useful to find out unused TestObjects in the “Object Repository”.
A simple demo
I made a Test Case script as follows:
import com.kazurayam.ks.testobject.combine.ObjectRepositoryGarbageCollector
import groovy.json.JsonOutput
/**
* A demonstration of ObjectRepositoryGarbageCollector.
*
* This TestCase outputs a JSON file which contains a list of garbage Test Objects
* in the "Object Repository" folder.
*
* A "garbage" means a Test Object which is not used by any scripts
* in the "Test Cases" folder.
*/
// the Garbage Collector instance will scan 2 folders: "Object Repository" and "Test Cases"
ObjectRepositoryGarbageCollector gc = new ObjectRepositoryGarbageCollector.Builder().build()
// gc.jsonifyGarbages() triggers scanning through the 2 folders and analyze the files.
// All forward references from TestCase scripts to TestObject entities are identified.
// Consequently, it can result a list of unused TestObjects.
// Will output the result in a JSON string
String json = gc.jsonifyGarbage()
println JsonOutput.prettyPrint(json)
When I ran this, I got the following output in the console:
2025-05-02 20:53:28.048 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/demo/ObjectRepositoryGarbageCollector/ORGC_jsonifyGarbage
{
"Garbage": [
"main/Page_CURA Healthcare Service/a_Foo",
"main/Page_CURA Healthcare Service/td_28",
"main/Page_CURA Healthcare Service/xtra/a_Go to Homepage",
"main/Page_CURA Healthcare Service/xtra/td_28",
"misc/dummy1"
],
"Run Description": {
"Project name": "katalon",
"includeScriptsFolder": [
],
"includeObjectRepositoryFolder": [
"**/*"
],
"Number of TestCases": 27,
"Number of TestObjects": 16,
"Number of unused TestObjects": 5
}
}
2025-05-02 20:53:29.897 INFO c.k.k.c.keyword.builtin.CommentKeyword - {"started at":"2025-05-02T20:53:29.438","duration seconds":0.258}
I found that this project contains
- 27 TestCase scripts
- 16 TestObjects
- out of 16, 5 TestObjects are unused by any of TestCase scripts.
- it took approximately 0.3 seconds to get the result.
Very quick, isn’t it?
This tool just compiles the report. It does NOT remove any TestObject files out of your project.
How to install the library.
- Visit the KS_ObjectRepositoryGargabeCollector, Releases page. Identify the latest version. Find a
KS_ObjectRepositoryGarbageCollector-x.x.x.jar
file attached. Download the jar file, save it into theDrivers
folder of your Katalon project. - Visit the MonkDirectoryScanner, Releases. Identify the latest version. Find a
MondDirectoryScanner-x.x.x.jar
file attached. Download the jar file, save into theDrivers
folder of your katalon project. - Close and reopen the project. Confirm that the jars are recognized by Katalon Studio.
- Create a Test Case script, which should be similar to the above “GC” script.
- You are done. Run it and see how quickly you can get the result.
Dependencies, versions, etc
This library uses only the libraries bundled in Katalon Studio. You don’t have to add any more external libraries other than the aforementioned jar.
This library should run on Katalon Studio Free, Katalon Studio Enterprise, and Katalon Runtime Engine. The jar is compiled by Katalon Studio Free v10.1.0 with JDK17, so the jar requires KS v10.x or above.
More features?
This library supports more:
- It can report all Forward References from TestCase scripts to TestObjects.
- It can report all Backward References, which is a list of TestObjects associated with list of ForwardReferences to each TestObject.
- It can report all Locators (XPath, CSS Selector) associated with list of duplicating TestObjects that implement the same locator
- You can specify sub-folder(s) of the “Object Repository” folder to choose the entries from. By this, you can get the report smaller and forcused.
I will write a more details documentation with sample codes later.
Disclaimer
I hope the library reports correctly. But I would not be responsible for the damages when you manually clear away what it found as “garbages”. I would recommend you to set your project backed by Git, and to store the snapshots before cleaning.