Read data from excel file or csv in Custom keyword


is there any way we can read data from excel file or any external file in custom keyword and use the data for further testing ? any method please?

Hi Mehran,

You can refer to this links:

Hope that helps. . . :slight_smile:

I am not sure about Custom Keyword but I use excel to fetch a random First Name and Last Name from a list of 2000 names, The excel formula returns a new random First Name and Last Name on a particular cell and Katalon Test picks data every time from that cell.

1 Like

Hi Manpreet,

For random selection approach, refer to this. . .

Hope that helps. . . :slight_smile:

Hi Arnel,

Well i have try both ways CSV method working fine but for the excel file its always giving the error “File not found”

Object excelData = ExcelFactory.getExcelDataWithDefaultSheet(“‪D:/Testdata.xlsx”, “first_file”, true)
int z = excelData.getRowNumbers()

I have import the package etc but still its not working and object not recognize any method like .getRowNumbers()

Hi Mehran,

I think it’s because you entered a wrong slash. Try changing your slash from “/” to “\”.
should be like this: “D:\Testdata.xlsx” should be backslash.

Hope that helps. . . :slight_smile:

Hi Arnel

well with the changes its not even accepting the parameters like “D:\Testdata.xlsx” mostly in java we are using “/”

Hi Mehran,

Sorry my bad, it should be double backslash… like this: D:\\Testdata.xlsx

Hi Arnel,

I have done and everything and try to solve it but still its giving the error file not found.

Here is the Excel file

And here is my Actual Test case with code and import and console error.

Not sure whats wrong here with Excel file.

Hi Mehran,

I don’t see anything wrong with your code.

Can you double check the location of the file, is it really stored in D:\\? did you save it already?

And based on your logs, it fails on test case “New Test Case” not in test case “Testdata”.

Could you run the test case “Testdata” for me and send the logs here for me to see…


Hi Arnel

Well its a magic what i can say but now its working even :slight_smile: i have’t change anything.

Oh really? That’s great!


1 Like

Hi Mehran, can you please share further info how use this data code in Keyword?

//get the excel file
Object excelData = ExcelFactory.getExcelDataWithDefaultSheet(“yout Excel File”, “your_SheetName”, true)

Here true mean the first line consider as a header.


Let’s try the Read/Write Excel Custom Keyword plugin in Katalon Store. I think it can help.

Hi Mehran_Shafqat

Can you help me to get the CSV method to read data.My code for reading and writing back to CSV file is not working.
Appreciate the help.


Hi Vidya,

Can you please share the code or any error screenshot ? will surely try to help.

Or I will create a Custom keyword and share with you for more easy to use

Thanks Mehran…It wil be a great help
but still code is as below

//File initialiation to write valid and broken links
File file = new File(“E:\brokenUrls.csv” );
FileWriter outputfile = new FileWriter(file);
CSVWriter writer = new CSVWriter(outputfile);

// have some code here which chek every link from the system and next write broken link on CSV file

if(respCode >= 400){
System.out.println(url+" is a broken link");
// add data to csv