Stop playback: Alt+F12
Pause playback: Ctrl+Pause/Break
Posts Tagged ‘TestPartner (TP)’
#28: How to pause or stop playback in TestPartner
#27: How to modify script in QTP debug mode
The only thing that I do not like in QTP is scripts are read only in debug mode: if an error pop up during a playback in QTP, and I choose to “Debug”, then I can not modify anything since the script is read only.
However, TestPartner is much more convenient in this particular area, since its scripts can be modified during debug mode: once you choose to debug, the playback is paused, and you can modify your script, and drag the current step indicator (i.e., the yellow arrow) to the line where you want the script to resume.
The only work around in QTP debug mode is to use the Command tab in the Debug Viewer:
Using the Debug Viewer
You use the Debug Viewer pane to view, set, or modify the current value of objects or variables in your function library, when it stops at a breakpoint, or when a step fails and you select the Debug option. The Debug Viewer is useful for debugging operations (functions) in a business component, but is not intended for use with other types of component steps.
To open the Debug Viewer pane:
Choose View > Debug Viewer. The Debug Viewer pane opens.
The Debug Viewer tabs are used to display the values of variables and objects in the main script of the selected subroutine.
Command Tab
Use the Command tab to execute a line of script in order to set or modify the current value of a variable or VBScript object in your function library. When the run continues, QuickTest uses the value that you set.
A detailed example about how to use the Debug Viewer and its Watch Tab, Variables Tab, and Command Tab can be viewed from here.
#25: Differences of Funtion that returns array in VBScript and VBA
To create and call a Function that returns array in VBScript and VBA are slightly different (QTP uses VBScript and TestPartner uses VBA):
In VBA,
Function GetExcelSheetData(FilePath As String, SheetName As String) Dim CellArray() As String 'A dynamic array that is not sized in the Dim statement ... Calculate RowCount and ColumnCount ReDim CellArray(RowCount, ColumnCount) As String ... Populate data in CellArray GetExcelSheetData = CellArray() End Function
Sub Main() Dim SheetData() As String 'Dynamic array .. Calculate RowCount and ColumnCount ReDim SheetData(RowCount, ColumnCount) As String SheetData() = Function_GetExcelSheetData.GetExcelSheetData(ExcelFilePath_MeasurementTab, "Package")
In VBScript,
Function Function_ImportExcelToArray(FilePath, SheetName) Dim CellArray 'A dynamic array that is not sized in the Dim statement ... Calculate RowCount and ColumnCount ReDim CellArray(RowCount, ColumnCount) ... Populate data in CellArray Function_ImportExcelToArray = CellArray 'Note: if write "Function_ImportExcelToArray = CellArray()", 'then will get error "Subscript out of range: 'CellArray'". End Function
Sub Sub_LoginRedirect() Dim PageURL 'DO NOT write "PageURL()", 'otherwise, will get error "type mismatch". .. Calculate RowCount and ColumnCount ReDim PageURL(RowCount, ColumnCount) PageURL = Function_ImportExcelToArray(InputExcel, "Sub_LoginRedirect") 'Note: if write "PageURL() = Function_ImportExcelToArray(InputExcel, "Sub_LoginRedirect")", 'then will get error "Subscript out of range: 'PageURL'".
Conclusion, in VBScript, do not use Array with empty brackets, such as Array(), but you can use not-empty brackets, such as Array(1, 2).
===========================================================
More information about Array in VBScript:
Much of the time, you only want to assign a single value to a variable you have declared. A variable containing a single value is a scalar variable. Other times, it is convenient to assign more than one related value to a single variable. Then you can create a variable that can contain a series of values. This is called an array variable. Array variables and scalar variables are declared in the same way, except that the declaration of an array variable uses parentheses ( ) following the variable name. In the following example, a single-dimension array containing 11 elements is declared:
Dim A(10)
Although the number shown in the parentheses is 10, all arrays in VBScript are zero-based, so this array actually contains 11 elements. In a zero-based array, the number of array elements is always the number shown in parentheses plus one. This kind of array is called a fixed-size array.
You assign data to each of the elements of the array using an index into the array. Beginning at zero and ending at 10, data can be assigned to the elements of an array as follows:
A(0) = 256
A(1) = 324
A(2) = 100
. . .
A(10) = 55
Similarly, the data can be retrieved from any element using an index into the particular array element you want. For example:
. . .
SomeVariable = A(8)
. . .
Arrays aren’t limited to a single dimension. You can have as many as 60 dimensions, although most people can’t comprehend more than three or four dimensions. You can declare multiple dimensions by separating an array’s size numbers in the parentheses with commas. In the following example, the MyTable variable is a two-dimensional array consisting of 6 rows and 11 columns:
Dim MyTable(5, 10)
In a two-dimensional array, the first number is always the number of rows; the second number is the number of columns.
You can also declare an array whose size changes during the time your script is running. This is called a dynamic array. The array is initially declared within a procedure using either the Dim statement or using the ReDim statement. However, for a dynamic array, no size or number of dimensions is placed inside the parentheses. For example:
Dim MyArray()
ReDim AnotherArray()
To use a dynamic array, you must subsequently use ReDim to determine the number of dimensions and the size of each dimension. In the following example, ReDim sets the initial size of the dynamic array to 25. A subsequent ReDim statement resizes the array to 30, but uses the Preserve keyword to preserve the contents of the array as the resizing takes place.
ReDim MyArray(25)
. . .
ReDim Preserve MyArray(30)
There is no limit to the number of times you can resize a dynamic array, although if you make an array smaller, you lose the data in the eliminated elements.
#18: TestPartner is not compatible with the currently installed VBA
Sometimes, when you try to launch TestPartner, you may get a pop up message saying “TestPartner is not compatible with the currently installed version of VBA (6.5.****)”.
This is because when you updated your windows, your VBA got updated too, and the new VBA version is no longer compatible with your TestPartner version.
There are 2 solutions for you: upgrade your TestPartner, or downgrade your VBA.
To upgrade your TestPartner, please contact Micro Focus/Compuware. This will cost you money.
To downgrade your VBA, please find the correct VBA version for your TestPartner (e.g., TP 6.3 supports VBA 6.5.1040), then find the DLL file for this VBA version (e.g., VBE6.DLL for VBA 6.5.1040), then replace the DLL file at C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6.
Here is the VBE6.DLL for VBA 6.5.1040 for you to download
#17: Reformat data in Excel (sheet A to Array x to Array y to sheet B)

![]()
This post is an example for you to practice post#9 and post#16. The 2 images on the right hand side are illustrations to show what I am tyring to do in this post:
In the excel file “MeasurementTab”, I created 2 sheets, one is called “Raw” and the other is called “ModeCategoryUnit”. I copied all the protocol tables from our Software Specifications, and paste them one by one to the “Raw” sheet. There are less than 50 Protocols, so it is okay to copy them manually. However, each Protocol table contains 2 to 20 measurements, so there are about 500 measurements in-total, and I want to rearrange all these measurements in another format/order and save them in the “ModeCategoryUnit” sheet, which will take days if I do it manually.
I decide to automate the data process. I will export the data from “Raw” sheet to an array called Raw(). By using the array Raw() and another small array ModeArray(1 To 9), I will rearrange the data in a new order, and save the data to an array called ModeCategoryUnit(). Finally, data in array ModeCategoryUnit() will be exported to sheet “ModeCategoryUnit” in the Excel file.
'Convert "Raw" sheet (populated directed from software specification - word version) to "ModeCategoryUnit" sheet in "Measurement.xlsx"
'If handle all the Packages/Protocols/Measurments, then need to increase ModeCategoryUnit's size and size parameters in Function_SaveArrayAsExcelSheet
'$TPinclude "Declaration_GlobalConstants"
Sub Main()
'Store Data from the "Raw" Sheet to array Raw()
Dim RowCount As Integer
Dim ColumnCount As Integer
Dim Raw() As String
RowCount = Function_ExcelSheetRowCount.ExcelSheetRowCount(ExcelFilePath_Measurement, "Raw")
ColumnCount = Function_ExcelSheetColumnCount.ExcelSheetColumnCount(ExcelFilePath_Measurement, "Raw")
ReDim Raw(1 To RowCount, 1 To ColumnCount) As String
Raw() = Function_GetExcelSheetData.GetExcelSheetData(ExcelFilePath_Measurement, "Raw")
'Delete extra space (if any) for each cell of array Raw()
Dim TrimRaw() As String
ReDim TrimRaw(1 To RowCount, 1 To ColumnCount) As String
Dim i As Integer 'row number of array Raw()
Dim j As Integer 'column number of array Raw()
For j = 1 To ColumnCount
For i = 1 To RowCount
TrimRaw(i, j) = Trim(Raw(i, j))
Next
Next
'Convert data from array TrimRaw() to array ModeCategoryUnit()
Dim ModeCategoryUnit(1 To 15, 1 To 60) As String 'Size should be increased if handle all the Packages/Protocols/Measurments
'First, write the header section (top 3 rows) of array ModeCategoryUnit()
'Including Package (1st row), Protocol (2nd row) and Mode (3rd row)
Dim Package As String
Dim Protocol As String
Dim ModeArray(1 To 9) As String
Dim ModeList As String
Dim Counter As Integer
Dim Column As Integer
Column = 1
For j = 1 To ColumnCount
If TrimRaw(1, j) <> "" Then
Package = TrimRaw(1, j)
If TrimRaw(2, j) <> "" Then
Protocol = TrimRaw(2, j)
'Reset Counter, Clearn ModeList and ModeArray for the FOR loop
Counter = 1
ModeList = ""
Erase ModeArray
For i = 3 To RowCount
If TrimRaw(i, j + 3) <> "" Then
'If TrimRaw(i, j + 3) doesn't exist in ModeList
If InStr(ModeList, TrimRaw(i, j + 3)) = 0 Then
ModeArray(Counter) = TrimRaw(i, j + 3)
'ModeList looks like "ModeArray(Counter),ModeArray(Counter+1),,,,,,,,"
ModeList = Join(ModeArray, ", ")
Counter = Counter + 1
End If
Else: Exit For
End If
Next
'Reset Counter for the DO loop
Counter = 1
Do While Counter <= UBound(ModeArray) And ModeArray(Counter) <> ""
ModeCategoryUnit(1, Column) = Package
ModeCategoryUnit(2, Column) = Protocol
ModeCategoryUnit(3, Column) = ModeArray(Counter)
Counter = Counter + 1
Column = Column + 3
Loop
End If
End If
Next
'Second, write the rest section of array ModeCategoryUnit()
'including Measurement, and its Category and Unit (same row)
Dim Measurement As String
Dim Category As String
Dim Unit As String
Dim Mode As String
Dim k As Integer 'row number of array ModeCategoryUnit()
Dim l As Integer 'column number of array ModeCategoryUnit()
For j = 1 To ColumnCount
If TrimRaw(1, j) <> "" Then
Package = TrimRaw(1, j)
If TrimRaw(2, j) <> "" Then
Protocol = TrimRaw(2, j)
For i = 3 To RowCount
If TrimRaw(i, j) <> "" Then
Measurement = TrimRaw(i, j)
Unit = TrimRaw(i, j + 1)
Catergory = TrimRaw(i, j + 2)
Mode = TrimRaw(i, j + 3)
'Search all the columns of array ModeCategoryUnit()
For l = LBound(ModeCategoryUnit, 2) To UBound(ModeCategoryUnit, 2)
If ModeCategoryUnit(1, l) = Package And ModeCategoryUnit(2, l) = Protocol And ModeCategoryUnit(3, l) = Mode Then
For k = 4 To UBound(ModeCategoryUnit)
If ModeCategoryUnit(k, l) = "" Then
ModeCategoryUnit(k, l) = Measurement
ModeCategoryUnit(k, l + 1) = Catergory
ModeCategoryUnit(k, l + 2) = Unit
Exit For
End If
Next
Exit For
End If
Next
Else
If TrimRaw(i, j + 3) <> "" Then
Mode = TrimRaw(i, j + 3)
For l = LBound(ModeCategoryUnit, 2) To UBound(ModeCategoryUnit, 2)
If ModeCategoryUnit(1, l) = Package And ModeCategoryUnit(2, l) = Protocol And ModeCategoryUnit(3, l) = Mode Then
For k = 4 To UBound(ModeCategoryUnit)
If ModeCategoryUnit(k, l) = "" Then
ModeCategoryUnit(k, l) = Measurement
ModeCategoryUnit(k, l + 1) = Catergory
ModeCategoryUnit(k, l + 2) = Unit
Exit For
End If
Next
Exit For
End If
Next
Else: Exit For
End If
End If
Next
End If
End If
Next
'Use shared module "Function_SaveArrayAsExcelSheet" to write data from array to Excel
a = Function_SaveArrayAsExcelSheet.SaveArrayAsExcelSheet(ModeCategoryUnit, 15, 60, ExcelFilePath_Measurement, "ModeCategoryUnit")
'Erase arrays
Erase ModeCategoryUnit
Erase TrimRaw
Erase Raw
End Sub
From the above script, we practiced the following:
1, Use a module “”Declaration_GlobalConstants”" to define a globe constants “ExcelFilePath_MeasurementTab”. (for more details see post#10)
2, Call Function_GetExcelSheetData to transfer data from the “Raw” sheet to array Raw(). (for more details see post#9)
3, Use Trim function to remove spaces on both sides of a string.
4, Join array elements to a string (ModeList = Join(ModeArray, “, “))
5, Call Function_SaveArrayAsExcelSheet to transfer data from array ModeCategoryUnit() to “ModeCategoryUnit” sheet. (for more details see post#16)
6, Erase array (e.g., Erase Raw)
There are an potential improvement for the above script. Currently, I hard coded the size of array “ModeCategoryUnit”, so when there are more measurements added, then I need to change the size in the script. However, there is a solution: “Adding New Elements to array on the Fly” . I didn’t do this because that the logic of the script is already complected, and I do not want to confuse you, but you can try this out by yourself!
#16: Export data from Two-Dimensional Array (2D array) to an Excel Sheet
In Post#9, we talked about how to import data from Excel (with multiple sheets) to an Array.
In this post, we will discuss that how to export data from a Two-Dimensional Array (2D array) to an Excel sheet.
Function SaveArrayAsExcelSheet(ArrayData() As String, ArrayRowCount As Integer, ArrayColumnCount As Integer, ExcelFilePath As String, SheetName As String)
'On error jump to "Error Handler:" line
On Error GoTo ErrorHandler
'Variable declaration
Dim SheetCount As Integer
'Open the Excel file
Set ObjExcel = CreateObject("Excel.Application")
Set ObjWorkBook = ObjExcel.Workbooks.Open(ExcelFilePath)
'Count how many sheets in the Excel file
SheetCount = ObjWorkBook.WorkSheets.Count
'If the sheet named "SheetName" exists, delete it
For i = 1 To SheetCount
If ObjWorkBook.WorkSheets(i).Name = SheetName Then
ObjExcel.DisplayAlerts = False 'Disable the delete confirmation message
ObjWorkBook.WorkSheets(i).Delete
ObjExcel.DisplayAlerts = True 'Enable the delte confirmation message
Exit For
End If
Next
'Create a new sheet in the Excel file and name this sheet as "SheetName"
ObjWorkBook.WorkSheets.Add.Name = SheetName
'Transfer data from an array to a Excel sheet
Dim ObjRange As Excel.Range
For i = 1 To SheetCount
If ObjWorkBook.WorkSheets(i).Name = SheetName Then
Set ObjRange = ObjWorkBook.WorkSheets(i).Range(ObjWorkBook.WorkSheets(i).Cells(1, 1), ObjWorkBook.WorkSheets(i).Cells(ArrayRowCount, ArrayColumnCount))
ObjRange.Value = ArrayData()
End If
Next
'Save and Close the Excel file
ObjWorkBook.Save
ObjWorkBook.Close
Exit Function
ErrorHandler: ' This is a normal VBA line label
MsgBox Err.Description
ObjWorkBook.Close
End Function
The VBA script above solves the problem (it will add or overwrite a sheet in the Excel file to receive data). The script should be saved as an shared module in TestPartner. To make the script work, you need to go to Tools->Reference to check the reference for Microsoft Excel, otherwise, TestPartner will give you an error on line “Dim ObjRange As Excel.Range”. (see Chapter 8 page 96 of “TestPartner Advanced Training Guide.pdf for Test Partner 5.2” listed in post#8 for more details.)
If you want to apply the script in QTP which uses VBScript instead of VBA, you need to make some minor modifications:
A, The function script needs to be created in the QTP Function Library (File – New – Function Library);
B, In the function script, delete anything related to the ErrorHandler (2 paragraphs);
C, In the function script, delete any definition for variable type, e.g., modify “SheetName As String” to “SheetName”, and change “Dim SheetCount As Integer” to “Dim SheetCount”.
D, Create a Test/Action to execute the function script, and the test/action will look like this (compare to TestPartner test script, no “Sub” nor “End Sub”, no need to assign the function to a variable, and no function file name nor brackets, i.e.,
in Testpartner (In TestPartner, if the function does not have a return value, but it has more than 1 input values, then in order to execute the function, you still need to define a variable in your test script, and assign the function to the variable.):
Sub Main() a = Function_SaveArrayAsExcelSheet.SaveArrayAsExcelSheet(ArrayName, 15, 60, "C:\...\MeasurementTab.xlsx", "Sheet2") End Sub
in QTP:
SaveArrayAsExcelSheet ArrayName, 15, 60, "C:\...\MeasurementTab.xlsx", "Sheet2")
E, Associate the Function file with the Test/Action file (right click on the Function file script and choose “Associate…” on the pop up menu), then you can run the function by running the test/action.
The script above should be fast enough to handle 10,000 data, but if your data is more than 50,000, then you may experience some slowness (depends on your computer speed too). There are two ways to solve the speed problem:
1, export the data from array to csv, then convert csv to Excel.
2, use ExcelCreator.NET instead of Excel Object, which is more efficient.
For more details, please refer to this website (you need to understand Chinese) .
#1: Step by Step to learn QTP and TestPartner
The best article I found about how to learn QTP by yourself is from Ankur’s website, you may want to open the link and have a look.
1) Start with basics of Software Testing.
2) Learn what is regression testing.
3) learn about when should automation testing come into picture.
Now the real thing:
4) Download QTP tutorial. Preferably for the latest version. Go through the the tutorial word by word.
5) Download QTP demo version. This is valid for 14 days, which – if you work hard – should be enough for you to get a good hold on basics.[Remember to put "quick test professional" as your search string not "qtp" on the HP site]
6) Download QTP Student handbook. It takes you through the step by step sample case study. Practice with the demo applications provided. One is web based and the other is windows based.
7) Next learn VBScript, the scripting language used with QTP.
Once you’re comfortable with this much, you are ready to take on a real-world project.
9) I am sure by now you must have started hearing about descriptive programming. (see QTP Advanced Guide chapter 5)
10) Once you have mastered the basics, go to Testing Tools Forums . Try answering questions. Remember, questions asked in the forums are from the real-time scenarios – you will get to learn a lot by sharing and reading different approaches to solve a particular problem.
Beside QTP Tutorial, you can also read this doc: QTP Basic Features User’s Guide, you should be able to find this doc though “Help-Printer Friendly doc” after you install QTP 9.0. This doc is 878 pages long, and it gives you much more details than the tutorial.
You may want to ask, how can I finish a doc almost 900 pages. The answer will be, yes you can, just read it on your way to work and on your way back home. I spend 2 hours on bus each weekday, and I read this.
You know what, I got my CQE certificate from ASQ just by study on the bus by myself for about 3-4 months. This is how you use your time efficiently. In 3-4 months, I finished study a lot of CQE materials which can make a banker’s box full.
Everything is possible as long as you are working on it.
As Ankur’s step 8, “Once you’re comfortable with this much, you are ready to take on a real-world project. If you can’t get hold of any project, practice with the demo applications provided.”
Since I have finished the first 7 steps he mentioned, now, I am inviting you to start with me from step 8 by testing YouPlayOff. My goal is, before the end of September (4 months from now), let us become masters of QTP!
Once you know how to use QTP, then TestPartner can be learned within 20 minutes.


