Tuesday, September 7, 2010

Working with DataTable

Datatable assists in parameterizing the Tests.

'Add a Sheet in QTP At RunTime
Syntax: DataTable.AddSheet(SheetName)
Example
DataTable.AddSheet("SampleSheet")

'Delete a Sheet in QTP At RunTime
Syntax: DataTable.DeleteSheet SheetName or SheetId
Example
DataTable.DeleteSheet "SampleSheet"
DataTable.DeleteSheet 2

'Exports contents of Run-time Datatable to an excel
sheet.

DataTable.Export(FileName)
DataTable.Export("C:\FLIGHTS.XLS")

'Exports a specified sheet of Run-Time DataTable
DataTable.ExportSheet(FileName, SheetName)
DataTable.ExportSheet("C:\FLIGHTS.XLS",1)

'Gets the current row from Run-Time DataTable
CurrentRow = DataTable.GetCurrentRow
msgbox CurrentRow

'Total Number of Rows in Run-Time DataTable
RowCount = DataTable.GetSheet(SheetName).GetRowCount

'Total Number of Sheets in Run-Time DataTable
DataTable.GetSheetCount

'Importing values from an Excel sheet to Run-Time DataTable
DataTable.Import ("C:\flights.xls")

'Importing values from a particular excel Sheet to Run-Time DataTable
DataTable.ImportSheet(FileName, SheetSource, SheetDest)

'Sets specified row as the current row in the Run-Time DataTable
DataTable.SetCurrentRow(RowNumber)

'Sets the row after the current row as the new current row in the Run-Time DataTable
DataTable.SetNextRow

'Sets the row above the current as the new current row in the Run-Time DataTable
DataTable.SetPrevRow

'Retrieves or Sets the value of the cell in the specified parameter and the current row of the run-time DataTable
Syntax:
To get the value:
DataTable.Value (ParameterID, SheetID)
(OR)
DataTable(ParameterID, SheetID)

To set the value:
DataTable.Value (ParameterID, SheetID)=New Value
(or)
DataTable(ParaterID[, SheetID]) = NewValue

Example:
DataTable(2,3) = "UserName2"

No comments:

Post a Comment