Loop through excel file

The documentation for this was not much help, so in case somebody else searches for this hopefully this will help.

First of all I created new test data file pointing at my excel file

Then I looped through printing out the names using the following code in my test case

import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
TestData data = findTestData('mydata')
for (def index : (0..data.getRowNumbers() - 1)) {
println ("First name =: " + data.internallyGetValue('firstname', index))
println ("Last name =: " + data.internallyGetValue('surname', index))

The output of which looked like this

You can see in the screenshot that each row of the excel file is printed as requested

While this is only printing to the console the same method can be used for other actions for example setting text

WebUI.setText(findTestObject('Page_SignUp/txt_FirstName'), data.internallyGetValue('firstname', index))

Hope this helps others




When I try to use, “data.internallyGetValue()”, Katalon underlines “internallyGetValue”. Looking at the API documentation, this method is protected (and therefore should not be used). https://docs.katalon.com/javadoc/com/kms/katalon/core/testdata/AbstractTestData.html

The unprotected equivalent would be data.getObjectValue(String columnName, int rowIndex).

1 Like