How to use csv file as database in sensetalk

Hello,

We have a CSV File,which stores different data used in our application. We are currently implementing Data Driven Framework. Now we are trying to use this CSV File as a DataBase, as we normally do with other Automation Tools like RFT or QTP.

So, my question is how we can use this csv file as database in sensetalk. If anyone share a sample code,then this would really be helpful.

This is described in our documentation at Gathering and Using Data and [url=http://docs.testplant.com/?q=content/data-driven-test]Data-Driven Tests

In V17.2.0 a CSVValue() function was added which can directly convert a CSV file (or any text in CSV format) into a list of property lists. The corresponding CSVFormat() function generates text in CSV format from a list of values. These functions are now the simplest and most direct way to work with CSV files.

With CSVValue() I got a hang of that in File and Folder Interaction. Any other practical code examples for this function? Iā€™m looking at a five column data set that includes FNAME, LNAME, EMAIL, UNAME, and PASSWD. Going to have roughly 50 rows. The idea is an iterative function that fills in a web form for 50 different users until the last row has been used. Still getting into the headspace needed for functions like this :slight_smile: Thanks!

I created 2 functions.
The first reads the content of a csv file into a global Parameter, the second gives me the required row of data as a properties list for use within a repeat loop.
Seems to work ok for me. Hope this helps!

// FUNCTION1 df_GetIterativeData
// Example Call : df_GetIterativeData "TC001 Data.csv"
Params DataFileName
If DataFileName does not contain ".csv" Then
Set DataFilename = DataFileName & ".csv"
End If
If Global DataFilePath Is Empty Then
df_GetDataFilePath
End IF
Put Global DataFilePath & DataFileName Into DataFilePathName
Log DataFilePathName
Repeat For Each Line Of file DataFilePathName
Add 1 To RowCount
Put It Into Item RepeatIndex() Of Global IterateData
End Repeat
Set Global NumDataRows = RowCount - 1

//FUNCTION2 df_ReadInIterativeDataRow
// Example Call : Repeat Global NumDataRows Times
// Put RepeatIndex() Into IterCount
// Put df_ReadInIterativeDataRow(IterCount) Into TestData
// log TestData.FirstName etc ...
Params DataRow
// Resolve Delimitter
If "DataFileDelim" is among the keys of Global GParams Then
Put Global GParams.DataFileDelim Into DelimChar
Else
Put ";" Into DelimChar
End If
// Get the data
Put The First Item Of Global IterateData Into DataRefs
Put DataRow + 1 Into DataRowRef
Put Item DataRowRef Of Global IterateData Into DataValues
Put DataRefs split by DelimChar Into SplitDataRefs
Put DataValues split by DelimChar Into SplitDataValues
Repeat For Each Item In SplitDataRefs
Put Item RepeatIndex() Of SplitDataRefs Into DataRef
Put Item RepeatIndex() Of SplitDataValues Into DataVal
Set PropDataList = PropDataList & "," & DataRef & ":" & quote & DataVal & quote
End Repeat
Delete First Occurrence Of "," From PropDataList
Set PropDataList = "(" & PropDataList & ")"
Put PropDataList as a property list into ReturnData
Return ReturnData
1 Like

Hi Chris,
If you have the option to do so, you would likely be better served by leaving the Excel in .xls format and referencing it as such. The big advantage is that Row 1 always gets automatically recognized as the field name. Also, if you give the Excel over to another team to fill out, and they insert or remove a column, you do not have to recode. More on that here: http://forums.testplant.com/discussion/3048/retrieve-an-excel-object-by-value-as-a-database-connecton#latest

Hope that helps,
Dave

1 Like