QTP Data Table Methods: Add Sheet
QTP Data Table Methods: Add Sheet
(1) Add Sheet: We can use this method to add one new sheet to the run time data table. Syntax: DataTable.AddSheet "sheet name" Ex: DataTable.AddSheet "gcreddy" (2) Delete Sheet: We can use this method to delete one specified sheet from the Run Time Data table.
(3) GetSheetCount
We can use this method to count number of sheets in the run time data table.
We can use this method to count number of rows in the 1st sheet (longest column) of the Run time data table.
Syntax: datatable.GetRowCount
We can use this method to return a specified sheet from the Run Time data table.
Syntax: datatable.GetSheet(SheetID)
(6) Value We can use this method to set or get value of cell in the specified parameter and the current row of the Rum time data table.
To set data
a=datatable.Value (1,1) b=datatable.Value (2,1) c=cint(a)+cint(b) datatable.Value (3,1) = c Note: Default property of Datatable is value (7) SetCurrentRow
We can use this method to take a specified row as current row in the Run Time Datatable (By default it is 1st Row of 1st Sheet) Syntax: datatable.SetCurrentRow(Row_Number) g="gcreddy" datatable.SetCurrentRow (3) datatable.Value (1,1) = g
(8) SetNextRow
We can use this method to take the row after the current Row as New Current Row in the Run time data table.
(9) SetPrevRow We can use this method to take the row before the current Row as New Current Row in the Run time data table.
Syntax: datatable.SetPrevRow
Ex: g="gcreddy"
(10) Import We can use this method to import Microsoft Excel File to the Runtime Data Table (Including all sheets)
Syntax: datatable.Import Path of File Ex: datatable.Import F:\Inputdata.xls 11) ImportSheet We can use this method to import a specified sheet of Microsoft Excel Sheet to the Runtime Data table.
Syntax: datatable.ImportSheet Path of File, Source Sheet, Destination Sheet Ex: datatable.ImportSheet E:\gcreddy.xls,3,1
(12) Export
We can use this method to export a copy of Run Time Data table to another location (Including all sheets)
13) ExportSheet
We can use this method to export a copy specified sheet of Run Time Data table to the existing or new Excel File. Syntax: datatable.ExportSheet Path of File, Sheet Name / Source Sheet
Ex: datatable.ExportSheet F:\gcreddy.xls, 2 ********************** Data Driven Testing for Login Operation using Data Table methods
Datatable.AddSheet "Login" Datatable.ImportSheet "C:\Documents and Settings\gcr\Desktop\gcreddy.xls",1,3 Rows_count=Datatable.GetSheet(3).GetRowCount For i= 1 to Rows_count Datatable.SetCurrentRow(i) SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open" Dialog("Login").Activate Dialog("Login").WinEdit("Agent Name:").Set Datatable("Agent",3) Dialog("Login").WinEdit("Password:").Set Datatable("Pwd",3) Dialog("Login").WinButton("OK").Click If window("Flight Reservation").exist(10) Then Login="Login Operation Successful" Datatable("Result",3)=Login Reporter.ReportEvent micPass,"res","Passed" else
Reporter.ReportEvent micFail,"res","Failed" Login="Login Operation Failed" Datatable("Result",3)=Login Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click Dialog("Login").WinButton("Cancel").Click End If If Window("Flight Reservation").Exist(3)Then Window("Flight Reservation").Close End if Next