I have published the new v0.4.12. I will show you new reports.
List of Locators with container Test Objects
Another Test Case script generates a JSON titled “LocatorIndex”
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import com.kazurayam.ks.reporting.Shorthand
import com.kazurayam.ks.testobject.combine.ObjectRepositoryGarbageCollector
import com.kms.katalon.core.configuration.RunConfiguration
import groovy.json.JsonOutput
import internal.GlobalVariable
/**
* ObjectRepositoryGarbageCollector#jsonifyCombinedLocatorIndex() demonstration
*/
ObjectRepositoryGarbageCollector gc =
new ObjectRepositoryGarbageCollector.Builder()
.includeObjectRepositoryFolder("**/Page_CURA*")
.build()
String json = gc.jsonifyCombinedLocatorIndex()
Path projectDir = Paths.get(RunConfiguration.getProjectDir())
Path classOutputDir = projectDir.resolve("build/tmp/testOutput/demo/ObjectRepositoryGarbageCollector")
Path outDir = classOutputDir.resolve("ORGC_jsonifyCombinedLocatorIndex")
Files.createDirectories(outDir)
File outFile = outDir.resolve("garbage.json").toFile()
outFile.text = JsonOutput.prettyPrint(json)
This script produced this (trimmed):
{
"CombinedLocatorIndex": {
"Number of Locators": 13,
"Number of Suspicious Locators": 3,
"Locators": [
{
"Locator": {
"value": "(.//*[normalize-space(text()) and normalize-space(.)='Sa'])[1]/following::td[31]",
"selectorMethod": "XPATH"
},
"Number of Container TestObjects": 2,
"Container TestObjects": [
{
"TestObjectId": "main/Page_CURA Healthcare Service/td_28",
"is used": false
},
{
"TestObjectId": "main/Page_CURA Healthcare Service/xtra/td_28",
"is used": false
}
]
},
{
"Locator": {
"value": "//a[@id='btn-make-appointment']",
"selectorMethod": "XPATH"
},
"Number of Container TestObjects": 1,
"Container TestObjects": [
{
"TestObjectId": "main/Page_CURA Healthcare Service/a_Make Appointment",
"is used": true,
"References from TestCase": [
{
"TestObjectId": "main/Page_CURA Healthcare Service/a_Make Appointment",
"Number of ForwardReferences": 2,
"ForwardReferences": [
{
"TestCaseId": "main/TC0",
"DigestedLine": {
"line": "WebUI.click(findTestObject('Object Repository/main/Page_CURA Healthcare Service/a_Make Appointment'))",
"lineNo": 12,
"pattern": "main/Page_CURA Healthcare Service/a_Make Appointment",
"matchAt": 47,
"matchEnd": 99,
"matched": true,
"regex": false
},
"TestObjectId": "main/Page_CURA Healthcare Service/a_Make Appointment"
},
{
"TestCaseId": "main/TC1",
"DigestedLine": {
"line": "WebUI.click(findTestObject('Object Repository/main/Page_CURA Healthcare Service/a_Make Appointment'))",
"lineNo": 11,
"pattern": "main/Page_CURA Healthcare Service/a_Make Appointment",
"matchAt": 47,
"matchEnd": 99,
"matched": true,
"regex": false
},
"TestObjectId": "main/Page_CURA Healthcare Service/a_Make Appointment"
}
]
}
]
}
]
},
...
See the full file at here
The CombinedLocatorIndex JSON tells me the following points:
- this project contains 12 “Locators” declared in the Object Repository.
- A Locator could be found in one or more Test Objects. If “Number of Container TestObjects” has value 2 or more, it means that the Locator is duplicating. You may want to avoid duplication.
- A TestObject may be used by zero or more Test Cases. If the number of references from TestCase" of a TestObject is 0, it means the TestObject is unused.
"is used": falsedenotes this. You may want to remove the unused TestObject. - This JSON could be large. As large as mega-bytes. The size depends on the number of TestObjects in your Object Repository. A too-large JSON won’t be very useful.
- The ObjectRepositoryGarbageCollector supports
includeObjectRepositoryFolder(pattern)andexcludeObjectRepositoryFolder(pattern). For example:
ObjectRepositoryGarbageCollector gc =
new ObjectRepositoryGarbageCollector.Builder()
.includeObjectRepositoryFolder("**/Page_CURA*")
.build()
You can specify from which sub-folders of the “Object Repository” to select Test Objects as target. Thus you can make the JSON much smaller and forcused.
Concise list of Suspicious Locators
Final Test Case script generates a JSON titled “Suspicious Locator Index” which would be most useful.
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import com.kazurayam.ks.testobject.combine.ObjectRepositoryGarbageCollector
import com.kms.katalon.core.configuration.RunConfiguration
import groovy.json.JsonOutput
/**
* ObjectRepositoryGarbageCollector#jsonifySuspiciousLocatorIndex() demonstration
*/
ObjectRepositoryGarbageCollector gc =
new ObjectRepositoryGarbageCollector.Builder()
.includeObjectRepositoryFolder("**/Page_CURA*")
.build()
String json = gc.jsonifySuspiciousLocatorIndex()
Path projectDir = Paths.get(RunConfiguration.getProjectDir())
Path classOutputDir = projectDir.resolve("build/tmp/testOutput/demo/ObjectRepositoryGarbageCollector")
Path outDir = classOutputDir.resolve("ORGC_jsonifySuspiciousLocatorIndex")
Files.createDirectories(outDir)
File outFile = outDir.resolve("garbage.json").toFile()
outFile.text = JsonOutput.prettyPrint(json)
This script generated a JSON as follows:
{
"SuspiciousLocatorIndex": {
"Number of Locators": 3,
"Number of Suspicious Locators": 3,
"Locators": [
{
"Locator": {
"value": "(.//*[normalize-space(text()) and normalize-space(.)='Sa'])[1]/following::td[31]",
"selectorMethod": "XPATH"
},
"Number of Container TestObjects": 2,
"Container TestObjects": [
{
"TestObjectId": "main/Page_CURA Healthcare Service/td_28",
"is used": false
},
{
"TestObjectId": "main/Page_CURA Healthcare Service/xtra/td_28",
"is used": false
}
]
},
{
"Locator": {
"value": "//body",
"selectorMethod": "XPATH"
},
"Number of Container TestObjects": 1,
"Container TestObjects": [
{
"TestObjectId": "misc/dummy1",
"is used": false
}
]
},
{
"Locator": {
"value": "//section[@id='summary']/div/div/div[7]/p/a",
"selectorMethod": "XPATH"
},
"Number of Container TestObjects": 3,
"Container TestObjects": [
{
"TestObjectId": "main/Page_CURA Healthcare Service/a_Foo",
"is used": false
},
{
"TestObjectId": "main/Page_CURA Healthcare Service/a_Go to Homepage",
"is used": true,
"References from TestCase": [
{
"TestObjectId": "main/Page_CURA Healthcare Service/a_Go to Homepage",
"Number of ForwardReferences": 1,
"ForwardReferences": [
{
"TestCaseId": "main/TC1",
"DigestedLine": {
"line": "WebUI.click(findTestObject('Object Repository/main/Page_CURA Healthcare Service/a_Go to Homepage'))",
"lineNo": 36,
"pattern": "main/Page_CURA Healthcare Service/a_Go to Homepage",
"matchAt": 47,
"matchEnd": 97,
"matched": true,
"regex": false
},
"TestObjectId": "main/Page_CURA Healthcare Service/a_Go to Homepage"
}
]
}
]
},
{
"TestObjectId": "main/Page_CURA Healthcare Service/xtra/a_Go to Homepage",
"is used": false
}
]
}
]
},
"Run Description": {
"Project name": "katalon",
"includeScriptsFolder": [
"main",
"misc"
],
"includeObjectRepositoryFolder": [
"main",
"misc"
],
"Number of TestCases": 5,
"Number of TestObjects": 16,
"Number of unused TestObjects": 5
}
}
Let me explain about this JSON.
- A Locator is suspicious if it is declared by a Test Object which is unused (referred by none of Test Cases)
- The “SuspiciousLocatorIndex” JSON contains only suspicious Locators. It doesn’t contain trustworthy Locators. Therefore the JSON file would be far smaller than the full list of Locators.
- As you work on cleaning your Object Repository, the “SuspiciousLocatorIndex” will become smaller. When the index has got 0 entries, you can be sure you finished cleaning up.