Array of test objects

Hello,
Please advice how to create an array from test objects.
Thank you in advance for your answers.

Instead of Array, can I suggest a List or List<TestObject>

Groovy - Lists (tutorialspoint.com)

Lists in Groovy | Baeldung

An example of creating a List of TestObjects:

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.testobject.TestObject as TestObject

List<TestObject> list = new ArrayList<>()
list.add(findTestObject("Page_Login/btn_Login"))
list.add(findTestObject("Page_Login/txt_Password"))
list.add(findTestObject("Page_Login/txt_UserName"))

list.forEach { tObj ->
	println tObj.toString()
}

An alternative.

The following Test Case scripts walks through the Object Repository folder to return a list of all Test Objects found.

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import java.nio.file.FileVisitResult
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.SimpleFileVisitor
import java.nio.file.attribute.BasicFileAttributes
import java.util.stream.Collectors

import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.testobject.TestObject

class FileTreeBuilder extends SimpleFileVisitor<Path> {
	private final Path baseDir
	private final Set<String> subPaths

	FileTreeBuilder(Path baseDir) {
		Objects.requireNonNull(baseDir)
		assert Files.exists(baseDir)
		this.baseDir = baseDir.toAbsolutePath().normalize()
		this.subPaths = new HashSet<>()
	}

	@Override
	FileVisitResult visitFile(Path file, BasicFileAttributes attributes) {
		Path relative = baseDir.relativize(file.toAbsolutePath().normalize())
		subPaths.add(relative.normalize().toString())
		return FileVisitResult.CONTINUE
	}

	Set<String> getSubPaths() {
		return subPaths
	}

	static Set<String> scan(Path baseDir) {
		FileTreeBuilder builder = new FileTreeBuilder(baseDir)
		Files.walkFileTree(baseDir, builder)
		return builder.getSubPaths()
	}
}

Path projectDir = Paths.get(RunConfiguration.getProjectDir())
Path objectRepository = projectDir.resolve("Object Repository")

Set<String> nodes = FileTreeBuilder.scan(objectRepository)
//nodes.forEach { p ->
//	println p.toString()
//}

List<TestObject> list = nodes.stream()
							.filter({ str -> str.endsWith('.rs') })
							.map({ str -> str.substring(0, str.lastIndexOf('.')) })
							.map({ s -> findTestObject(s) })
							.collect(Collectors.toList())

list.forEach({ tObj ->
	println "Test Object: ${tObj.toString()}"
})

When I ran this, it got the following console output:

2023-04-02 16:15:22.749 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/makeListOfTestObjects
2023-04-02 16:15:23.455 DEBUG testcase.makeListOfTestObjects           - 1: projectDir = Paths.get(getProjectDir())
2023-04-02 16:15:23.464 DEBUG testcase.makeListOfTestObjects           - 2: objectRepository = projectDir.resolve("Object Repository")
2023-04-02 16:15:23.481 DEBUG testcase.makeListOfTestObjects           - 3: nodes = FileTreeBuilder.scan(objectRepository)
2023-04-02 16:15:23.575 DEBUG testcase.makeListOfTestObjects           - 4: list =  }).collect(Collectors.toList())
2023-04-02 16:15:23.903 DEBUG testcase.makeListOfTestObjects           - 5: list.forEach({ java.lang.Object tObj -> ... })
Test Object: TestObject - 'Object Repository/Page_CURA Healthcare Service/a_Make Appointment'
Test Object: TestObject - 'Object Repository/Page_CURA Healthcare Service/input_Username_username'
Test Object: TestObject - 'Object Repository/Page_CURA Healthcare Service/button_Login'
2023-04-02 16:15:23.986 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/makeListOfTestObjects

A collection of TestObjects from what?

If you want to get a collection of web elements on a page, as TestObjects, given some xpath you could do the following:

public final class GeneralWebUIUtils { 
    public List<TestObject> GetTestObjectsFromXpath(String xpath){  
        return DriverFactory.getWebDriver()
            .findWebElements(By.xpath(xpath))
            .collect({ WebElement element -> return WebUI.convertWebElementToTestObject(element)})
    }
}