Hello,
Is it possible to somehow change file’s name, which is being used by TestData, during the run-time instead of specifying in TestData’s object as shown below?
In my case, file’s name will be different every time I run the test case so I need to find a way how to tell my testdata object that file name is changed.
I don’t think you can change the name of a pre-defined TestData object at runtime. Instead, you can create a new TestData (ExcelData in your case) object programmatically at runtime as follows:
With this lib, along with its Apache POI counterpart, you have full control over test data presented in Excel or CSV formats. Depends on how much elbow grease you want to put into it though
In reading the CSV, you can also try this approach:
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
//this is to get all the used rows or total number of rows
csvData.allData or csvData.getAllData()
csvData.getValue(‘columnname’, int rowNumber)
csvData.rowNumbers
csvData.columnNumbers
csvData.columnNames
Not sure if you will see this, but any idea what I’m doing wrong. I’m following your basic instructions (import command) + defining where my csv file is located, and every time I run this I get an error:
Test Cases/ReadCSVExample FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: CSVSeparator for class: Script1567532257335
at ReadCSVExample.run(ReadCSVExample:19)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1567536185335.run(TempTestCase1567536185335.groovy:21)
my code looks like:
import com.kms.katalon.core.testdata.CSVData
CSVData csvData = new CSVData(“C://test_files//matter_data_download.csv”,false,CSVSeparator.COMMA)
I’ve tried without the //, I’ve tried with \ characters, nothing I do works. I also tried replacing the CSVSeparator with just “,”
Just looking for a simple solution to read the contents of a very basic CSV file and I’m getting nowhere. Appreciate any feedback you can provide.
I see your code example on many different topics so I have to assume this should still work.
OMG, nevermind, I don’t know what I had done wrong but it must be a copy paste issue. I made a few tweaks and used Katalon’s hints and it magically started working
Thanks for the feedback, honestly I’m not sure what I did but picking some values from the code hints Katalon provided seems to have fixed my issue, I must have had something wrong with the CSVSeparator argument. Feel like a dummy but I really was loosing my mind here.