How to get the iteration names in data-driven testing at runtime

Hi All,

Is there any way to get the iteration names (the Set Test Name) in the Test Suite at runtime?

your screenshot is from the help guide. The iteration name is supposed to be in the report generated when you execute the test suite. Are you trying to do something that isn’t in the guide?

Yes. I want to get that iteration name to set in the screenshot name. If not, the screenshots will be replaced in the next loop because they’re having the same name.

Can you give us more detail on what you’re specifically trying to accomplish? What data item do you want and where you do you want it to go?
Do you have any code for what you’ve tried so far?

Sure.
I’m trying to run the Test Suite (1 Test Case) with iteration (5 times). In the Test Case, I take screenshot 10 times, so in total I should have 50 screenshots after completing the run, but only 10 screenshots were appeared in the folder. So I realized that all screenshots in the previous run had been replaced by the new ones in the next run because they’re having the same name.
Now I’m having a plan to automatically get the iteration name and put that to the screenshot name. The screenshot name is in the following format:

Module_TC Index_SS Index.png

I want to put the Iteration Name after the Module part to avoid duplicating names. If I don’t run the Test Suite with iteration, the Iteration Name will be emptied and I can easily remove that by the code replaceAll(“__”, “_”). Here’s the code:

If you follow that help guide, and follow the steps for data-driven testing, you’ll be able to get the value for the variable, which will be your ‘set test name’ option in your first screenshot.
You will need to add a variable in the test case - have you done that already?
The variable in the test case pulls data from your data file.
The test case can have binding at test case or test suite level. Once the binding is complete, your code can take the value of the local variable rather than a global variable.

You want a unique string that identifies each screeenshots so that the file names won’t overwrap. I would take this as your requirement.

I made a sample project that demonstrates my idea how to uniquely identify the screenshots created during multiple runs of a single Test Suite.

I made a CSV file as input data:

USERNAME,PASSWORD
aaa,pw1
bbb,pw2
ccc,pw3

I made a Test Case tryLogin:

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

// make sure the parameters are passed from the credentials.csv file
assert USERNAME != null
assert PASSWORD != null

TestObject makeTestObject(String id, String xpath) {
	TestObject tObj = new TestObject(id)
	tObj.addProperty("xpath", ConditionType.EQUALS, xpath)
	return tObj
}
TestObject usernameField = makeTestObject("Username", "//input[@name='username']")
TestObject passwordField = makeTestObject("Password", "//input[@name='password']")

Path getTestSuiteIdentification() {
	if (RunConfiguration.getReportFolder() != null) {
		Path folder = Paths.get(RunConfiguration.getReportFolder())    
		//println "folder=${folder}"    // e.g. /User/foo/project/Reports/20241114_184316/TS1/20241114_184317
		Path reports = folder.getParent().getParent().toAbsolutePath()
		//println "reports=${reports}"    // e.g. /User/foo/project/Reports/20241114_184316
		Path relative = reports.relativize(folder)                     
		//println "relative=${relative}"  // e.g. TS1/20241114_184317
		return relative	
	} else {
		return Paths.get("who_knows")
	}
}

String getCurrentHHmmss() {
	return DateTimeFormatter.ofPattern("HHmmss").format(LocalDateTime.now())
}

String testSuiteRunId = getCurrentHHmmss()

WebUI.openBrowser('')
WebUI.setViewPortSize(800, 520)
WebUI.navigateToUrl("https://katalon-demo-cura.herokuapp.com/profile.php#login")
WebUI.verifyElementPresent(usernameField, 5)
WebUI.setText(usernameField, USERNAME)
WebUI.setText(passwordField, PASSWORD)
WebUI.delay(1)

// take screenshot and save a PNG into a directory dedicated to this time of TestSuite run
Path outDir = Paths.get("screenshots/${getTestSuiteIdentification()}")
Files.createDirectories(outDir)
Path png = outDir.resolve("${testSuiteRunId}_${USERNAME}_login.png")
WebUI.takeScreenshot(png.toString())

WebUI.closeBrowser()

I made a Test Suites TS1 which binds the above Test Case tryLogin

The TS1 has the following setup for Data Binding:

When I ran the TS1, I got the screenshots folder created with screenshot PNG.

$ tree screenshots/
screenshots/
└── TS1
    └── 20241114_203306
        ├── 203312_aaa_login.png
        ├── 203324_bbb_login.png
        └── 203333_ccc_login.png

3 directories, 3 files

The TS1 repeated 3 times for the lines in the given CSV file, created 3 screenshots which are uniquely identified; not overwritten. I twisted creating meaningful subfolders for each individual Test Suite runs.

Hello @kazurayam . Thanks for your help. Actually, the screenshot format is hardcoded and I cannot change the format like yours, as you can see in my screenshot, this is custom keywords with only 1 parameter (delay). So the remaining Global Variables have been created from the Test Listeners, and now I want to get the iteration value from that as well.