Loading test data file programmatically (Dynamic Test Data)

Hi Guys,

Just wanted to share some ideas about test data. If your test data changes upon running your test automation it seems impossible to load it again or refresh it when you use the standard process of loading your test data file.

To give you a scenario, assuming that you already loaded your test data(.csv, .xlsx) in the data files or you have already bind it in your test suite. When you execute your suite the automation will load the test data first before running your test steps or code. So it means if your test steps or code has the ability to change the test data like running a third party application(.vbs, .exe) that penetrates the .csv or .xlsx file, the currently loaded test data will be useless, you need to load it again to use the updated values of your test data. So this is like having a dynamic test data.

In order to load it programmatically, you need to have a look at the following classes
(CSVData, ExcelData, DBData, InternalData, TestData, etc. . . .) you can find those classes in this link: Index (Katalon Studio API Specification)

In my case, Iā€™m using CSVData as my dynamic test data file. CSVData class allows you to programmatically load your .csv file and set your desired configurations. There are 3 parameters in that class CSVData(String sourceUrl, boolean containsHeader, CSVSeparator separator).

To give an example of how to use it refer to my shortcode below:

import com.kms.katalon.core.testdata.CSVData

CSVData csvData = new CSVData(ā€œC:\yourCSV.csvā€, true, CSVSeparator.COMMA)

//to access or to get the .csv file values refer to some commonly used commands
csvData.allData or csvData.getAllData()
csvData.getValue(ā€˜columnnameā€™, int rowNumber)
csvData.rowNumbers //this is to get all the used rows or total number of rows
csvData.columnNumbers
csvData.columnNames
. . . and many more.

Hope this helps :slight_smile:

5 Likes

I have a test suite in KS which validates a website with parameterized data(FirstName, LastName, Phone#, City etcā€¦)which means, every time I run my test suite it looks for the csv file which has multiple rows and columns in order to read the contents and submit the form vis website.

My question is, am planning to do CICD where whenever my developers push and commit any changes to branch my test build in Jenkins will invoke automatically and run the test. But my concern is, I donā€™t want my test build to consume same test data from csv rather it should be a loop. To cut it short, every time it should take different set of test data from my csv file. Any thoughts will be helpful.

Thanks,
Vimal

Hi Vimal,

Apologies. Iā€™m quite confused about your inquiry. Are you saying that you will be using multiple test data?

Could you explain a little further?

Thanks.

I donā€™t want to use multiple test data on a single run. So the CSV file would have headers as FirstName, LastName, City, Phone#, PostalCode and there will be around 20 rows(ie, 20 test data) in a csv/xls file. I would like to see whenever Jenkins test build gets invoked how it will not end up choosing the same row#(same test data). Because, when my Jenkins test build got invoked for the first time it would have chosen row#1ā€¦now when the job got invoked again for the 2nd time, how will I make sure it wonā€™t chose again the row#1 but row#2 ?

A dual post is here:

@kazurayam Can I see the page you posted above? It seems to be private