Quick Test Professional - The starters Guide
Chapters
Data Tables in QTP
The Data Table has the characteristics of a Microsoft Excel spreadsheet, meaning that you can store and use data in its cells and you can also perform mathematical formulas within the cells.
A Data Table in QTP, which helps to create data driven test cases that can be used to run an Action multiple times.
Types of Data Tables:
- Local Data Table: Here the data that is available to a certain action. 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: Here the data is available to all the actions in a test.
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, to set the iterations of global data table in the Test Settings dialog.
To access it: Go to File, select Settings click Run (Tab) as shown below:
Example:
The Parameters can be created as shown below. Most of the functionalities of Excel can be used in Data table as well.
Methods for Data table object:
There are three types of objects to access Data Table:
- Data Table Object Methods
- DTParameter Object Properties
- DTSheet Methods
Data Table Object Methods:
- AddSheet: Adds the specified sheet to the run-time Data Table
Syntax: DataTable.AddSheet(SheetName)
Ex: Datatable.AddSheet(strSheetName) - DeleteSheet: Deletes the specified sheet from the run-time Data Table.
Syntax: DataTable.DeleteSheet SheetID
Ex: Datatable.DeleteSheet(strSheetName) - Export Method: Saves a copy of the run-time Data Table in the specified location.
Syntax: DataTable.Export(FileName)
Ex: Datatable.Export(strExcelFile) - ExportSheet Method: Exports a specified sheet of the run-time Data Table to the specified file.
Syntax: DataTable.ExportSheet(FileName,SheetName)
Ex: DataTable.ExportSheet(FileName, DTSheet) - GetCurrentRow: Returns the current (active) row in the first sheet in the run-time Data Table (global sheet).
Syntax: DataTable.GetCurrentRow
Ex: row = DataTable.GetCurrentRow - GetParameterCount Method: Returns the total number of parameters (columns) in the run-time Data Table sheet.
Syntax: DataTable.GetParameterCount
Ex: paramcount = DataTable.GetSheet("Test").GetParameterCount - GetRowCount Method: Returns the total number of rows in the longest column in the run-time Data Table sheet.
Syntax: DataTable.GetRowCount
Ex: rowcount = DataTable.GetSheet("Test").GetRowCount - GetSheet Method: Returns the specified sheet from the run-time Data Table.
Syntax: DataTable.GetSheet(SheetID)
Ex: MyParam=DataTable.GetSheet ("MySheet") - GetSheetCount: Returns the total number of sheets in the run-time Data Table.
Syntax: DataTable.GetSheetCount
Ex: intSheet = datatable.getSheetCount - Import Method: Imports the specified Microsoft Excel file to the run-time Data Table.
Syntax: DataTable.Import(FileName) - ImportSheetMethod: Imports a sheet of a specified file to a specified sheet in the run-time Data Table.
Syntax: DataTable.ImportSheet(FileName, SheetSource, SheetDest)
Ex: DataTable.ImportSheet(FileName, SheetSource, SheetDest) - SetCurrentRow Method: Sets the specified row as the current (active) row in the run-time Data Table.
Syntax: DataTable.SetCurrentRow(RowNumber)
Ex: DataTable.GetSheet("MySheet").SetCurrentRow(2) - SetNextRow Method: Sets the row after the current (active) row as the new current row in the run-time Data Table.
Syntax: DataTable.SetNextRow
Ex: DataTable.GetSheet("MySheet").SetNextRow
- SetPreviousRow Method: Set the focus to the row above the current active row.
Syntax: DataTable.SetPreviousRow
If the current active row is the first row, then it will move the focus to the last row of the DataTable.
Data Table Object Properties:
- GlobalSheet Property: Returns the first sheet in the run-time Data Table (global sheet).
Syntax: DataTable.GlobalSheet
Ex: DataTable.GlobalSheet.AddParameter "Name", "qtp" - LocalSheet Property: Returns the current (active) local sheet of the run-time Data Table.
Syntax: DataTable.LocalSheet
Ex: DataTable.LocalSheet.AddParameter "Name", "qtp"
- RawValue Property: Retrieves the raw value of the cell
Syntax: DataTable.RawValue ParameterID, [SheetID]
- Value Property: Retrieves the value of the cell in the specified parameter.
Syntax: DataTable.Value(ParameterID, [SheetID])
DTParameter Object Properties:
- Name: Returns the name of the parameter in the run-time data table.
Syntax: DTParameter.Name - RawValue : This returns the actual value present in the cell before computing the values. Suppose we have some formula present in the cell, so this method will return the formula but not the value computed by the formula.
Syntax: DTParameter.RawValue
rawVal = DataTable.RawValue(ColumName, SheetNameOrId) - Value: Retrieves or sets the value of the cell in the current (active) row of the parameter in the run-time Data Table.
Syntax: DTParameter.Value
Ex: DataTable.GetSheet("Action1").GetParameter("Destination").Value="Pithoragarh" - ValueByRow: Retrieves the value of the cell in the specified row of the parameter in the run-time data table.
Syntax: DTParameter.ValueByRow(RowNum)
Ex: DataTable.GetSheet("Action1").GetParameter("Destination").ValueByRow(7)
DTSheet Methods:
- AddParameter: Adds the specified parameter (column) to the sheet in the run-time Data Table, sets the value of the first row to the specified value
Syntax: DTSheet.AddParameter(ParameterName, Value)
Ex: DataTable.GetSheet("dtGlobalSheet").AddParameter "Name","qtp"
DataTable.AddSheet("MySheet").AddParameter("Name", "qtp")
paramname = DataTable.LocalSheet.AddParameter("Name", "qtp").Name - DeleteParameter Method: Delete the specified parameter from the sheet in the run-time Data Table.
Syntax: DTSheet.DeleteParameter(ParameterID)
Ex: DataTable.GetSheet("MySheet").DeleteParameter("Name") - GetCurrentRow Method: Return the row number of the current (active) row in the run-time Data Table sheet.
Syntax: DTSheet.GetCurrentRow
Ex: row = DataTable.GetSheet("MySheet").GetCurrentRow - GetParameter Method: Retrieve the specified parameter from the run-time Data Table sheet.
Syntax: DTSheet.GetParameter(ParameterID)
Ex: DataTable.GetSheet("ActionA").GetParameter("Date").RawValue - GetParameterCount Method: Returns the total number of parameters (columns) in the run-time Data Table sheet.
Syntax: DTSheet.GetParameterCount
Ex: paramcount = DataTable.GetSheet("Test").GetParameterCount - GetRowCount Method: Returns the total number of rows in the longest column in the run-time Data Table sheet.
Syntax: DTSheet.GetRowCount
Ex: rowcount = DataTable.GetSheet("Test").GetRowCount - SetCurrentRow Method: Sets the specified row as the current (active) row in the run-time Data Table.
Syntax: DataTable.SetCurrentRow(RowNumber)
Ex: DataTable.GetSheet("MySheet").SetCurrentRow(2) - SetNextRow Method: Sets the row after the current (active) row as the new current row in the run-time Data Table.
Syntax: DataTable.SetNextRow
Ex: DataTable.GetSheet("MySheet").SetNextRow - SetPrevRow: Shifts the Focus to the Previous Row of the Data Table.
Syntax: DTSheet.SetPrevRow
Description
In this tutorial, we will get to know Quick test professional. At the time of writting QTP is at version 12.2. This tutorial is subdivided into multiple parts as shown below
- What is QTP
- Automating tests
- Environment
- Recording and Playback
- Object Repository
- Actions
- Data Table
- Checkpoints in QTP
- Synchronization
- Smart Identification
- Debugging and Error handling
- Recovery Scenarios
- Environment Variables
- Library Files
- Test Results
- GUI Objects
- Virtual Objects
- Accessing Databases
- Working with XML
- Descriptive Programming
- Automation Object Model
- A work on Frameworks
Leave your feedback for us, Feedback help us improve our tutorials.
Prerequisites
Some knowledge on Windows OS and VB Script is recommended
Audience
Students who wish to learn QTP
Learning Objectives
Learn QTP
Author: Subject Coach
Added on: 16th Mar 2015
You must be logged in as Student to ask a Question.
None just yet!