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.
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.
Comments
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
df_GetDataFilePath
End IF
Log DataFilePathName
Add 1 To RowCount
Put It Into Item RepeatIndex() Of Global IterateData
End Repeat
//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
Put The First Item Of Global IterateData Into DataRefs
Put DataRow + 1 Into DataRowRef
Put DataValues split by DelimChar Into SplitDataValues
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
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