There are Two Types of Data tables.
Design Time datatable: is the one which we find on the main screen, consisting of Global Data Sheet and Local Data Sheets
Run time datatable: is the one that is displayed in the test results window.
Multiple sets of test data is placed in the design time datatable in any of the sheets (either global or local datasheets)and is used by the script to parameterise it.
The methods used on datatable are:
Datatable.AddSheet: To add an extra sheet to the datatable. Datatable.AddSheet "SheetName"
Datatable.DeleteSheet: To delete a specified sheet from the datatable. Datatable.DeleteSheet "SheetName"
Datatable.ImportSheet: To Import data from a specified sheet in the excel file to a specified sheet in the datatable. Datatable.ImportSheet "Path of excel File", SourceSheetID, DestinationSheetID eg: Datatable.ImportSheet path.xls, 1, 3
Datatable.Import: To Import data present in all the sheets in an excel file to datatable. Datatable.Import "Path of excel File"
Datatable.ExportSheet : To Export the specified sheet of data in the runtime datatable to a specified location. Datatable.ExportSheet "Path of excel File", SourceSheetID, DestinationSheetID
eg: Datatable.ImportSheet path.xls, 1, 3
Datatable.Export: To Import All sheets of data from Run time datatable to a specified locaiton. Datatable.Export "Path of excel File"
SetCurrentRow: To set the QTPs pointer in the datatable on the current Row number given
eg: SetCurrentRow(4): sets the focus of QTP on the 4th row of the Datatable.
SetNextRow: To set the QTPs pointer in the datatable on the Next Row
eg: SetNextRow
SetPrevRow: To set the QTPs pointer in the datatable on the Previous Row
eg: SetPrevRow
GetSheet: To kae QTP focus on a specified Sheet
eg: Datatable.GetSheet(2)
GetSheetCount: To get the number of Sheets in the datatable.
eg: cnt=Datatable.GetSheetCount
GetRowCount: To get the number of rows in the give sheet. By default, GetRowCount will give number of rows in the Global Sheet
eg: Datatable.GetSheet(3).GetRowCount
Datatable.GetRowCount
GetParameterCount: To get the number of columns in a given sheet.
eg: Cnt = DataTable.GetSheet(1).GetParameterCount
Value: To Capture a value from specified Sheet, Specified Column and currently focussed row.
Eg: Datatable.Value("ColumnName",SheetID) OR Datatable.Value("ColumnName",SheetID)
The ColumnName is the column header in a given sheet of datatable. SheetID for the Global sheet is 1 and Second Sheet is 2, Third sheet is 3 and so on.
Example : To add two numbers A and B and compare them with the another column ExpectedVal in the datatable and the value Result from application.
' adding a new sheet to datatable
Datatable.AddSheet "Addition"
'importing from 1st sheet of add.xls to 2nd sheet of datatable
Datatable.ImportSheet "C:\Add.xls", 1,2
' get number of rows from second sheet of datatable
n=Datatable.GetSheet(2).GetRowCount
For 1= 1 to n
' set the current row as i
Datatable.SetCuttentRow(i)
Browser("...").Page("...").WebEdit("name:=a").Set Datatable(A,2)
Browser("...").Page("...").WebEdit("name:=b").Set Datatable(B,2)
Browser("...").Page("...").WebButton("name:=add").Click
' putting expected value under column AB of 2nd Sheet
ExpectedVal=Datatable(AB,2)
' getting the resuld of addition from the application
Result=Browser("...").Page("...").WebEdit("name:=result").GetROProperty("innertext")
If (ExpectedVal=Result) Then
' save Pass under Result column in 2nd Sheet
Datatable("Result",2)="Pass"
Else
' save Fail under Result column in 2nd Sheet
Datatable("Result",2)="Fail"
End IF
Next
' exporting sheet from 2nd sheet of datatabel to system drive C
Datatable.ExportSheet "C:\Res.xls",2'
'Delete the sheet added in datatable
Datatable.ExportSheet "C:\Res.xls",2'
'Delete the sheet added in datatable
Datatable.DeletSheet "Addition"
No comments:
Post a Comment