Friday, September 30, 2011

DataTable Methods

QTP is having a powerful utility that is DataTable.It is normally used to enter the test data into the QTP script during script execution.
The following are some data table methods and their descriprions with examples.

Data table methods:

Data table methods are used for performing the operations on the runtime data table

1. Add- sheet: It is used for adding the new sheet for the runtime data table
SYNTAX: Data table.add sheet ”sheet name”

2. Delete- sheet: It is used for deleting a specified sheet from the run time data table
SYNTAX: Data table.delete sheet”sheet name”

3. Import: It is used for importing the data present in all the sheets in an excel file to the runtime data table
SYNTAX: Data table.import ”path of the excel file”

4. Import Sheet: It is used for importing specified sheet of data from the excel file to the specified sheet in the runtime data table
SYNTAX: Data table. Import sheet “path of the excel file, source sheet id, destination sheet id”

5. Export: It is used for exporting the complete data present in the run time data table to a specified location
SYNTAX: Data table. export “Path of the location with a file name.xls extension”

6.Export Sheet: It is used for exporting the data present in a specified sheet in the run time data table to a specified location
SYNTAX: Data table .export sheet “path of the location with a file name.xls extension”, sheet id to be exported.

7. Set currant row: It is used for making the QTP focus on a specified row
SYNTAX: Data table. Set currant row (row number)

8. Set next row: It is used for making the QTP focused on the next of the currently focused row
SYNTAX: Data table. Set next row

9.Set Prev Row: It is used for making the QTP focus on the previous row of the currently focused tow
SYNTAX: Data table. Set prev row

10. Value Method: It is used for getting a value from a specified sheet, specified column and currently focused row.
SYNTAX: Variable= Data Table. Value ( “column name”, sheet id)

11. Get Sheet: It is used for making the QTP to focus on a specified sheet
SYNTAX: Data table. Get sheet (sheet id)

12 Get Row Count: It is used for getting the row count of a global sheet
If at all one wants to get the row count of a specified sheet first of all they need to make the QTP to focus on a specified sheet and then get the row count
SYNTAX 1: Variable= Data Table. Get row count
SYNTAX 2: Variable= Data Table. Get sheet (“sheet id”). Get row count

Example:
DataTable.Addsheet “Alok”
DataTable.Importsheet “e:\Alok\td122.xls,1,3
N=Datatable.Getsheet( 3).getrowcount
For i= 1 to n
Data table. Setcurrantrow( i )
Vbwindow(“form1”).vbedit(“val1”).set datatable(“v1”,3)
Vbwindow(“form1).vbedit(‘val2’).set datatable(“v2”,3)
Vbwindow(”form1”).vbbutton(“add”).click
Expval= Datatable.value(“ev”,3)
Actval= vbwindow(“form1”).vbedit(“res”).getroproperty(“text”)
If (Expval= Actval) then
Datatable (“res”,3)= “pass”
Else
Datatable (“res”,3)= “fail”
End if
Next
Datatable.Export sheet “D;\fl_automation\log\file2.xls”,3
Datatable.Delete “Alok”

No comments:

Post a Comment