A DataTable, similar to Microsoft Excel helps testers to create data driven test cases that can be used to run an Action multiple times. There are two types of Datatables.
- Local Data Table - Each action has its own private data table also known as local data table which is can also be accessed across actions.
- Global Data Table - Each test has one global data sheet that is accessible across actions.
The Data sheet can be accessed from the "Data" Tab of QTP as shown below:
To execute a test case for some specified number of iterations,one can set the iterations of global data table in the Test Settings dialog, that can be accessed using File -> Settings -> Run(Tab) as shown below:
Example:
For Instance, if user wants to parameterize "compound Interest" of "http://easycalculation.com/" that can be accessed using "http://easycalculation.com/compound-interest.php". The Parameters can be created as shown below. Most of the functionalities of Excel can be used in Data table as well.
Data Table Operations:
There are three types of objects to access Data Table. Data Table Operations can be well understood by traversing through the below link:
| Object Type | Description |
|---|---|
| Data Table Methods | Gives Detailed information about the data table methods. |
| DTParameter Object Methods | Gives Detailed information about the DTParameter methods. |
| DTSheet Object Methods | Gives Detailed information about the DTSheet methods. |
DataTable Methods:
These methods are applied on either DataTable object or DTSheet object or DTParameter object. Here are the methods and their properties:
Adds the specified sheet to the run time data table.
DataTable.AddSheet(“My Sheet”)
DataTable Object - Methods
Add Sheet:Adds the specified sheet to the run time data table.
DataTable.AddSheet(“My Sheet”)
DeleteSheet:
Deletes the specified sheet from the run time data table.
DataTable.DeleteSheet “My Sheet”
Deletes the specified sheet from the run time data table.
DataTable.DeleteSheet “My Sheet”
Export:
Exports the complete data table to the specified path.
DataTable.Export(“C:\abc.xls”)
ExportSheet:
Exports the current sheet to the specifed path.
DataTable.ExportSheet “C:\abc.xls”,1
Exports the complete data table to the specified path.
DataTable.Export(“C:\abc.xls”)
ExportSheet:
Exports the current sheet to the specifed path.
DataTable.ExportSheet “C:\abc.xls”,1
GetCurrentRow: (for global sheet)
Retrieves the current row number of the global data sheet.
Row=DataTable.GetCurrentRow
Reporter.ReportEvent 1, “Row Number”, row
Retrieves the current row number of the global data sheet.
Row=DataTable.GetCurrentRow
Reporter.ReportEvent 1, “Row Number”, row
GetRowCount: (for global sheet)
Retrieves the number of rows in the longest column in the first sheet(global data sheet) in the run time data table.
Rowcount=DataTable.Get Sheet(“My Sheet”).GetRowCount
Reporter.ReportEvent 2, “There are” &rowcount, “rows in the data sheet”
Retrieves the number of rows in the longest column in the first sheet(global data sheet) in the run time data table.
Rowcount=DataTable.Get Sheet(“My Sheet”).GetRowCount
Reporter.ReportEvent 2, “There are” &rowcount, “rows in the data sheet”
GetSheet:
Retrieves the specified sheet in the run time data table.
DataTable.Getsheet(“My Sheet”).AddParameter(“Time”,”08:00”)
Retrieves the specified sheet in the run time data table.
DataTable.Getsheet(“My Sheet”).AddParameter(“Time”,”08:00”)
GetSheetCount:
Retrieves the total number of sheets in the run time data table.
Sheetcount=DataTable.GetSheetCount
Reporter.ReportEvent 0, “sheet number”, “There are” &sheetcount “sheets in data table”
Retrieves the total number of sheets in the run time data table.
Sheetcount=DataTable.GetSheetCount
Reporter.ReportEvent 0, “sheet number”, “There are” &sheetcount “sheets in data table”
Import:
Import the specified Microsoft Excel file to the run time data table.
DataTable.Import(“C:\abc.xls”)
Import the specified Microsoft Excel file to the run time data table.
DataTable.Import(“C:\abc.xls”)
ImportSheet:
Imports the specified sheet of Microsoft Excel file to the run time data table.
DataTable.ImportSheet”C:\abc.xls”, 1, ”Name”
Imports the specified sheet of Microsoft Excel file to the run time data table.
DataTable.ImportSheet”C:\abc.xls”, 1, ”Name”
SetCurrentRow:
Sets the specified row as the current(active) row in the run time data table.
DataTable.SetCurrentRow(2)
Sets the specified row as the current(active) row in the run time data table.
DataTable.SetCurrentRow(2)
SetNextRow:
Sets the row next to the current row as the new current row in the run time data table sheet.
DataTable.GetSheet(“My Sheet”).SetNextRow
SetPrevRow:
DataTable.GlobalSheet.AddParameter “Time”,”08:00”
Sets the row above the current row as the new current row in the run time data table sheet.
DataTable.SetPrevRow
DataTable Object - Properties
GlobalSheet Property:Description: Returns the first sheet in the datat table.DataTable.GlobalSheet.AddParameter “Time”,”08:00”
LocalSheet Property:
Description: Returns the current (active) sheet of the data table.
MyParam=DataTable.LocalSheet.AddParameter “Time”,”09:00”
Description: Returns the current (active) sheet of the data table.
MyParam=DataTable.LocalSheet.AddParameter “Time”,”09:00”
RawValue Property:
Description: Returns the raw value of the cell in the specified parameter of the current row of the data table. The raw value is the actual string written in the cell before the cell is computed, such as the actual text from a formula.
FormulaVal=DataTable.RawValue(“Date”,”ActionA”)
Description: Returns the raw value of the cell in the specified parameter of the current row of the data table. The raw value is the actual string written in the cell before the cell is computed, such as the actual text from a formula.
FormulaVal=DataTable.RawValue(“Date”,”ActionA”)
Value Property:
Description: Data table default property. Retrieves or sets the value of the cell in specified parameter and the current row of the data table.
DataTable.Value(2,3)=”New York”
Description: Data table default property. Retrieves or sets the value of the cell in specified parameter and the current row of the data table.
DataTable.Value(2,3)=”New York”
DTParameter - Methods
DtSheet.AddParameter: (Adds a new column.)
DataTable.GetSheet(“dtGlobalSheet”).AddParameter “NewColumnName”,”FirstRowVaule”
DtSheet.GetParameter:
Description: Retrieves the specified parameter from the run time data table sheet.
DataTable.GetSheet(“My Sheet”).GetParameter(“Destination”)
DtParameter – Properties
Name Property:
Description: Retrieves the name of the parameter in run time data table.
ParamName=DataTable.LocalSheet.AddParameter(“NewColumnName”,”Row1Value”).Name
RawValue Property:
Description: The raw value of the cell in the current row of the parameter in the run time data table. The raw value is the actual string written in the cell before the cell is computed, such as the actual text from a formula.
The following example uses the RawValue property to find the formula used in current row of the Date column in the ActionA sheet of the run time data table.
The statement below runs the Value:=Now()
FormulaVal=DataTable.GetSheet(“ActionA”).GetParameter(“Date”).RawValue
Value Property:
Parameter default property. Retrieves or sets the value of cell in the current row of parameter in the run time data table.
DataTable.GetSheet(“ActionA”).GetParameter(“Destination”).Value=”New York”
ValueByRow Property:
Retrieves the value of the cell in the specified row of the parameter in the run time data table.
DataTable.GetSheet(“ActionA”).GetParameter(“Destination”).ValueByRow(4)
DTSheet Methods
AddParameter Method:
Add the specific parameter(column) to the sheet in Run Time data table, sets the value of the first row to the specified value, and returns the parameter so that you can directly set or retrieve properties of new parameter in same statement.
Variable=DataTable.AddSheet(“My Sheet”).AddParameter(“Time”,”08:00”)
DeleteParameter Method:
Deletes the specified parameter from the sheet in run time data table.
DataTable.GetSheet(“My Sheet”).DeleteParameter(“Time”)
GetCurrentRow Method:
Returns the row number of the current(active) row in the run time data table sheet.
Rownum=DataTable.GetSheet(“My Sheet”).GetCurrentRow
Reporter.ReportEvent 1, “Row Number”, rownum
GetParameter Method:
Returns the specified parameter from the run time data table sheet.
DataTable.GetSheet(“My Sheet”).GetParameter
GetParameterCount Method:
Returns the total number of parameters(columns) from the run time data table sheet.
Paramcount=DataTable.GetSheet(“My Sheet”).GetParameterCount
Reporter.ReportEvent 2, “There are”, ¶mcount, “columns in this sheet”
GetRowCount Method:
Returns the total number of rows in the longest column in the run time data table sheet.
rowcount=DataTable.GetSheet(“My Sheet”).GetRowCount
Reporter.ReportEvent 2, “There are”, &rowcount, “active rows in this sheet”
SetCurrentRow Method:
Sets the specified row as the current row in the run time data table sheet.
DataTable.GetSheet(“My Sheet”).SetCurrentRow(2)
SetNextRow Method:
Sets the row next to the current row as the new current row in the run time data table sheet.
DataTable.GetSheet(“My Sheet”).SetNextRow
SetPrevRow Method:
Sets the row above the current row as the new current row in the run time data table sheet.
DataTable.GetSheet(“My Sheet”).SetPrevRow
DTSheet Properties:
Name Property:
Returns the name of the run time data table sheet.
Sheetname=DataTable.LocalSheet.Name
Reporter.ReportEvent 1, “The active sheet is”, sheetname

No comments:
Post a Comment