Refresh internal excel data

Hi Guys,

So I have a testcase where I write data to an excel file using a custom keyword, this works fine the file is updated. However, in the next testcase I need to retrieve this data again to verify. My issue is that in this test case I am binding the data file to variables but the data being used is the data before the excel file was updated. Which makes me believe that Katalon does not refresh the data from the excel file that is being used during execution. My question is is there a way for me to refresh the data file? Or is my only solution to create another custom keyword to retrieve the data directly from the excel file?

1 Like

Can you share your test code?

Hi Morgan,

I think you need to call your excel file again. Because by default katalon only reads the loaded test data upon execution and it will be the same data even if you did a change on your test data while executing the test. It’s like you need to restart the test to acquire the updated values.

Now, to get the updated values you need to access the excel directly or programmatically.

try calling it using this. . . I think this will do the trick…

import com.kms.katalon.core.testdata.reader.ExcelFactory

//create an instance
Object excel = ExcelFactory.getExcelDataWithDefaultSheet("yourExcelPath.xlsx", "SheetName", true)

//pass your test case variables
excel.getValue("tc_variable", 1)

/**
Where 1st param is string column name and 2nd param integer is row number.

theres an overload to that method where the first param is integer.
**/

Or if you don’t have many sheets or you only have default sheet in your test data, try this other approach. . .

import com.kms.katalon.core.testdata.ExcelData

ExcelData excelData = new ExcelData("yourExcelPath.xlsx", true)
excelData.getValue("tc_variable", 0)

//same param definition as mentioned above.

Hope that helps. . . :slight_smile:

man exceldata is an abstract class,i am not able to create an instance of this class as

ExcelData myData = new ExcelData("C:....\\Data Files\tester1.dat",true)

is there any class that helps me define programmatically excel data file and change sheet when needed

Hello neamehbaydoun66,

You can try this

import com.kms.katalon.core.testdata.reader.ExcelFactory

//create an instance
ExcelData excel = ExcelFactory.getExcelDataWithDefaultSheet("yourExcelPath.xlsx", "SheetName", true)

//pass your test case variables
excel.getValue("tc_variable", 1)

Where
-First parameter will be the excel path
-Second parameter will be the sheet name. You can change sheet name on run time just put a string variable
-Third, make it true if you want to make the first row as headers or false if you want to make the first row as plain record

Hope that helps. . . :smiley:

1 Like

That’s running fine thanks for the help :people_hugging:

Sure, you’re welcome. Glad I helped.

Cheers! :beers: