How to programatically obtain list of test cases (count, titles) before execution of test suite?

Hi Katalon Support,

In order to setup a Test Suite within our Test Management tool (via Katalon’s Script), I am looking for list of test cases (count with their titles) to be available before the test execution starts. I need to obtain this through the script.

The context object (testSuiteContext) is providing only the ID and Status of Suite, and not the information regarding child tests. Could you please suggest a solution for this?

Thanks and regards,
Tanmay

1 Like

Hi Tanmay K,

Test Suite file (.ts) is written as XML format. One approach to handle your current request is to count the number of <testCaseLink> node in the current context of a Test Suite.

https://www.mkyong.com/java/how-to-count-xml-elements-in-java-dom-parser/

So when applied to @beforeTestSuite, it can be (just a mockup):

String filepath = Runconfiguration.getProjectDir() + "${testSuiteContext.getTestSuiteId()}.ts";
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(filepath);
NodeList list = doc.getElementsByTagName("testCaseLink");

// Number of test cases in the current test suite
System.out.println("Total of elements : " + list.getLength());

Regards