Tuesday, 27 March 2012

Data Table Methods In QTP

Data Tables plays major role when using Data/Keyword Driven frameworks. It'll be easy to work with Data tables if we know the methods.We have the following methods in Data Tables.


AddSheet:This method is used to add only one new sheet to the run time data table.
Syntax: DataTable.AddSheet "sheet name"
Example: DataTable.AddSheet "stc"


DeleteSheet:This method is used to delete a single sheet from run time data table.
Syntax:DataTable.DeleteSheet (sheet id)
Example: DataTable.DeleteSheet (3)


GetSheetCount:This method is used to get the number of sheets available in the run time table.
Syntax:DataTable.GetSheetCount


GetRowCount:This method is used to get the number of rows from the run time data table. Obviously it'll return the longest used column count from the data table.
Syntax:DataTable.GetRowCount


GetSheet: This method is used to return the specific sheet from the run time data table.
Syntax: DataTable.GetSheet(sheet id)
Example:DataTable.GetSheet("stc").GetRowCount


Value: This method is used to set or get the values from a particular cell of the run time data table.
Syntax to set data:
DataTable.Value(Parameter_Name,Sheet_Name) =  value or variable
DataTable(Parameter_Name,Sheet_Name) =  Value
Example: DataTable.Value(5,2)=a


Syntax to get data:
variable = DataTable.Value(Parameter_Name,Sheet_Name)
variable = DataTable.(Parameter_Name,Sheet_Name)
Example: a= DataTable.Value(5,2)


SetCurrentRow:This method is used to set a particular row as current row. By default it's first row of the 1st sheet.
Syntax:DataTable.SetCurrentRow(rowNumber)
Example: dataTable.SetCurrentRow(3)
dataTable.value(1,1)="software testing community"


SetNextRow:This method is used to set the next row as the new current row after the current row.
Syntax:DataTable.SetNextRow
Example:DataTable.SetCurrentRow(3)
DataTable.SetNextRow
DataTable.Value(2,1)="software testing community"


SetPrevRow:This method is to set the row before the current row as the current row in the run time data table.
Syntax:DataTable.SerPrevRow
Example:datatable.SetCurrentRow(3)
datatable.SerPrevRow
datatable.value(1,1)="stc"


Import:This method is used to import an Excel file to the run time table.Assume that we have 3 workbooks in the selected file.We can import all 3 worksheets to the run time data table.
Syntax: DataTable.Import "file path"
Example:DataTable.Import "C:\Automation\DataSheet\stc.xls"


ImportSheet: This method is used to import a particular sheet of the selected Excel file to the run time data table.
Syntax: DataTable.ImportSheet "file path","source sheet", "destination sheet"
Example: datatable.ImportSheet "C:\Automation\DataSheet\stc.xls",2,1


Export: This method is used to export a copy of the run time data table to a particular location.
Syntax:DataTable.Export "file path".This will export all the sheets from the run time data table.
Example:DataTable.Export "C:\Automation\DataSheet\stc1.xls"


ExportSheet: This method is used to export copy of a particular sheet in  the run time data table to a particular location.

Syntax:DataTable.ExportShee "file path","source sheet.
Example:DataTable.Export "C:\Automation\DataSheet\stc1.xls",3

0 comments:

Post a Comment

 
Back To Top