RSS
 

Archive for the ‘TestPartner (TP)’ Category

#14: Test checkboxes for all the measurements from different protocols and packages

11 Jul

In post#10, we have tested the Checkboxes for packages, and in post#12, Checkboxes for protocols are tested. As I said before, there are 3 layers to organize the workstation measurements. The first layer is the package, and the second layer is the protocol. Today, we will use TestPartner test the Checkboxes for the third layer, i.e., the measurement.

From the script below, you can practice the following things again, which you have learned from previous posts:
1, Post#9: Get data from Excel
2, Post#11: Test Windows TreeView with Checkbox
3, Post#13: Error handling in VBA

For number 3, you will also see an improvement compare to the script in post #12: A better place to put the “On Error GoTo 0″ to capture all the errors except the scroll-bar error.

'Testing condition: After clean install.
'Check all the measurements from all the measurement packages - protocols are enabled in the Preference panel - Measurement tab

'$TPinclude "Declaration_GlobalConstants"

Sub Main()

Dim RowCount As Integer
Dim ColumnCount As Integer
Dim SheetData() As String 'Dynamic array

'Use Shared Modules "Function_ExcelSheetRowCount" and "Function_ExcelSheetColumnCount"
'to get how many rows and columns in the Measurement sheet of "MeasurementTab.xlsx"
RowCount = Function_ExcelSheetRowCount.ExcelSheetRowCount(ExcelFilePath_MeasurementTab, "Measurement")
ColumnCount = Function_ExcelSheetColumnCount.ExcelSheetColumnCount(ExcelFilePath_MeasurementTab, "Measurement")

'Array is sized dynamically
ReDim SheetData(RowCount, ColumnCount) As String

'Use Shared Module "Function_GetExcelSheetData" to store data from the Measurement sheet of "MeasurementTab.xlsx" in the array
SheetData() = Function_GetExcelSheetData.GetExcelSheetData(ExcelFilePath_MeasurementTab, "Measurement")

'Open the workstation
    ProgramManagerWindow("Application=EXPLORER.EXE Caption='Program Manager'").Attach
        ListView("Index=1").Select "the workstation", tpMouseDoubleClick

'In the workstation, open Preference panel, then open the Measurement tab
    Window("Application=VSIAPP.EXE Caption=the workstation").Attach
        Button("Caption=Prefs").Click
        TabControl("Parent.Caption=Preferences").Select "    Measurement    "

        'Select different Packages from the ComboBox, expand Protocol nodes, and check their measurements are enabled
        For i = 1 To ColumnCount
            For j = 1 To RowCount
                If j = 1 Then   'First row in the Measurement sheet is package name
                    ComboBox("Parent.Caption=Preferences").Select SheetData(1, i)   'Select the package
                    Dim Package As String
                    Package = SheetData(1, i)
                ElseIf j = 2 Then    'Second row in the Measurement sheet is protocol name
                    Dim ProtocolPath As String
                    ProtocolPath = "\Measurements\" & SheetData(j, i)
                    'Report error if the protocol name read from Excel sheet
                    'does NOT match the protocol name displayed in the workstation
                    On Error GoTo 0    'Disables error handling in the current procedure
                    TreeView("Parent.Caption=Preferences").SelectItem ProtocolPath, , tpTreeButton  'Expand Protocol nodes
                Else
                    'If the Excel cell is not empty, check all the CheckBoxes beside measurement nodes
                    If SheetData(j, i) <> "" Then
                    Dim MeasurementPath As String
                    MeasurementPath = ProtocolPath & "\" & SheetData(j, i)
                        'Report error if the measurement name read from Excel sheet
                        'does NOT match the measurement name displayed in the workstation
                        'On Error GoTo 0    'Disables error handling in the current procedure
                        TreeView("Parent.Caption=Preferences").SelectItem (MeasurementPath)

                        'Store the mouse y position after "SelectItem", which is always
                        'in the middle of the first charactor of the measurement name
                        Dim y As Integer
                        y = TreeView("Parent.Caption=Preferences").MouseY

                        'Handle the situation when the measurement name is longer than the width of the treeview window
                        On Error Resume Next    'Handle the situation when there is no scroll bar
                        TreeView("Parent.Caption=Preferences").Scroll 0, tpScrollHorizontal
                        On Error GoTo 0        'This is a better place

                        'Search if the CheckBoxInTreeView.bmp (13*13 pixels) exists or not
                        'Write the results to result summary.
                        If TreeView("Parent.Caption=Preferences").BitmapExists("CheckBoxInTreeView", 58, y - 8, 17, 17) Then
                            UserCheck "CheckBoxInTreeView", True, "The " & Package & MeasurementPath & " CheckBox is checked"
                        Else
                            UserCheck "CheckBoxInTreeView", False, "The " & Package & MeasurementPath & " CheckBox is NOT checked"
                        End If
                    End If
                End If
            Next
        Next

    'Close application to reset its original state
    Window.Close

End Sub
 
No Comments

Posted by Jia Qi in TestPartner (TP)

 

#13: Error handling in VBA (TestPartner)_Part1

01 Jul

There are 3 error handling statements in Visual Basic of Application (VBA), which can be used in TestPartner. However, not all of these statements can be used in QTP, since QTP uses the Visual Basic Scripting Edition (VBScript) scripting language (refer to post#26 for error handling in VBScript).

The 3 error handling statements in VBA are:

1, On Error GoTo line (see post#23 for using “On Error GoTo line” in a loop with “Resume Line“)
This statement has been used in post#9.
This statement enables the error-handling routine that starts at line specified in the required line argument. The line argument is any line label or line number. If a run-time error occurs, control branches to line, making the error handler active. The specified line must be in the same procedure as the On Error statement; otherwise, a compile-time error occurs.

2, On Error Resume Next
This statement has been used in post#12.
This statement specifies that when a run-time error occurs, control goes to the statement immediately following the statement where the error occurred where execution continues. Use this form rather than On Error GoTo when accessing objects.

3, On Error GoTo 0
This statement has been used in post#12.
This statement disables any enabled error handler in the current procedure (It doesn’t specify line 0 as the start of the error-handling code, even if the procedure contains a line numbered 0.).

============================================

In the script of post#12, there is a line to move the scroll bar inside the TreeView window horizontally: “TreeView(“Parent.Caption=Preferences”).Scroll 0, tpScrollHorizontal”. This line of script is necessary when a protocol name is longer than the TreeView window width.

However, when all the protocols names are shorter than the TreeView window width, then there will be no scroll bar, which is an expected situation, but since the script can not find the scroll bar, it will pop up an error message to stop the script from running.

In order to handle the above situation, I wrote “On Error Resume Next” right above “TreeView(“Parent.Caption=Preferences”).Scroll 0, tpScrollHorizontal” line. In this way, if there is a scroll bar, then the script will scroll the scroll bar horizontally to position x=0, and if there is no scroll bar, then the script will skip the scroll step, and run the next step.

Everything looks perfect until I found out this: even though the “On Error Resume Next” is right above “TreeView(“Parent.Caption=Preferences”).Scroll 0, tpScrollHorizontal” line, it does NOT only affect the “TreeView(“Parent.Caption=Preferences”).Scroll 0, tpScrollHorizontal” line, it will affect all the lines after “On Error Resume Next”, which means, if there is an error happens after “On Error Resume Next” is executed, then the error will be ignored anyway.

If LOOP is used, when an error happens at a line above “On Error Resume Next”, the error could still be ignored, as long as the error doesn’t happen at the first iteration of the loop and before “On Error Resume Next” is executed. See the example below from post#12:

For i = 1 to Imax
     ...
     TreeView("Parent.Caption=Preferences").SelectItem (ProtocolPath)
     ...
     On Error Resume Next
     TreeView("Parent.Caption=Preferences").Scroll 0, tpScrollHorizontal
     ...
Next

Real/unexpected error may happen at line “TreeView(“Parent.Caption=Preferences”).SelectItem (ProtocolPath)”, and the script needs to alert me about these errors, but since the existence of “On Error Resume Next”, most errors happen at “TreeView(“Parent.Caption=Preferences”).SelectItem (ProtocolPath)” will be ignored, unless it happens when i=1, i.e., when “On Error Resume Next” haven’t been reached.

How to solve this issue? It is simple, you just need to add the “On Error GoTo 0″ line right above “TreeView(“Parent.Caption=Preferences”).SelectItem (ProtocolPath)”. The script will looks like this:

For i = 1 to Imax
     ...
     On Error GoTo 0
     TreeView("Parent.Caption=Preferences").SelectItem (ProtocolPath)
     ...
     On Error Resume Next
     TreeView("Parent.Caption=Preferences").Scroll 0, tpScrollHorizontal
     ...
Next

In conclusion, to ignore expected error, use “On Error Resume Next”; to alert unexpected error, use “On Error GoTo 0″ if “On Error Resume Next” has been used in the script (same level).

 
No Comments

Posted by Jia Qi in TestPartner (TP)

 

#12: An example of testing TreeView CheckBox with TestPartner

29 Jun

In this post, I will give you an example script from TestPartner to test if the CheckBox is checked or not in the TreeView window. The suggestion B from post#11 is used here, i.e., the “BitmapExists” method is used to detect the CheckBox state in the TreeView window. In order to use the “BitmapExists” method, you need to capture a bitmap of the CheckBox and store it under Object Map Asset. How to do this? You can find the detailed instruction in Chapter7 Image Mapping of the TestPartner Advanced training guide.

Since multiple protocols from different measurement packages will be tested (each protocol has a CheckBox, and all the protocols are listed in the TreeView window), the data (package and protocol names) are saved in an Excel file, and will be used as input to the test script. The way to input data from Excel file is mentioned in post#9. Let’s have a look of how the data is organized in the Excel file (its path is defined in “Declaration_GlobalConstants” which is saved in Module Asset). One of the spreadsheet is called as the “Protocol” tab, and in this tab, the first row stores different packages names, and each cell stores one package name. Under each column, the first/top cell is the package name, and starting from the second cell, protocol names belong to this package are stored one after one in each cell.

'Testing condition: After clean install
'Check all the measurement protocols from all the measurement packages are enabled in the Preference panel - Measurement tab

'$TPinclude "Declaration_GlobalConstants"

Sub Main()

Dim RowCount As Integer
Dim ColumnCount As Integer
Dim SheetData() As String 'Dynamic array

'Use Shared Modules "Function_ExcelSheetRowCount" and "Function_ExcelSheetColumnCount"
'to get how many rows and columns in the Protocol sheet of "MeasurementTab.xlsx"
RowCount = Function_ExcelSheetRowCount.ExcelSheetRowCount(ExcelFilePath_MeasurementTab, "Protocol")
ColumnCount = Function_ExcelSheetColumnCount.ExcelSheetColumnCount(ExcelFilePath_MeasurementTab, "Protocol")

'Array is sized dynamically
ReDim SheetData(RowCount, ColumnCount) As String

'Use Shared Module "Function_GetExcelSheetData" to store data from the Protocol sheet of "MeasurementTab.xlsx" in the array
SheetData() = Function_GetExcelSheetData.GetExcelSheetData(ExcelFilePath_MeasurementTab, "Protocol")

'Open the workstation
    ProgramManagerWindow("Application=EXPLORER.EXE Caption='Program Manager'").Attach
        ListView("Index=1").Select "the workstation", tpMouseDoubleClick

'In the workstion, open Preference panel, then open the Measurement tab
    Window("Application=VSIAPP.EXE Caption=the workstation'").Attach
        Button("Caption=Prefs").Click
        TabControl("Parent.Caption=Preferences").Select "    Measurement    "

        'Select different Packages from the ComboBox, and check their protocols are enabled
        For i = 1 To ColumnCount
            For j = 1 To RowCount
                If j = 1 Then   'First row in the Protocol sheet is package name
                    'Select the package
                    ComboBox("Parent.Caption=Preferences").Select SheetData(1, i)
                    Dim Package As String
                    Package = SheetData(1, i)
                Else    'Other rows in the Protocol sheet are protocol names
                    'If the Excel cell is not empty, check all the CheckBoxes beside protocol nodes
                    If SheetData(j, i) <> "" Then
                        Dim ProtocolPath As String
                        ProtocolPath = "\Measurements\" & SheetData(j, i)
                        'Report error if the protocol name read from Excel sheet
                        'does NOT match the protocol name displayed in the workstation
                        On Error GoTo 0    'Disables error handling in the current procedure
                        TreeView("Parent.Caption=Preferences").SelectItem (ProtocolPath)

                        'Store the mouse position after "SelectItem", which is always
                        'at the very left and in the middle of the first charactor of the protocol name
                        Dim tempx, x, y As Integer
                        tempx = TreeView("Parent.Caption=Preferences").MouseX
                            'When the protocol name is longer than the width of the treeview window
                            'tempx = 0
                            If tempx <> 0 Then
                                x = tempx
                            End If
                        y = TreeView("Parent.Caption=Preferences").MouseY

                        'Handle the situation when the protocol name is longer than the width of the treeview window
                        On Error Resume Next    'Handle the situation when there is no scroll bar
                        TreeView("Parent.Caption=Preferences").Scroll 0, tpScrollHorizontal

                        'Search if the CheckBoxInTreeView.bmp (13*13 pixels) exists or not
                        'Write the results to result summary
                        If TreeView("Parent.Caption=Preferences").BitmapExists("CheckBoxInTreeView", x - 16, y - 8, 17, 17) Then
                            UserCheck "CheckBoxInTreeView", True, "The " & Package & ProtocolPath & " CheckBox is checked"
                        Else
                            UserCheck "CheckBoxInTreeView", False, "The " & Package & ProtocolPath & " CheckBox is NOT checked"
                        End If
                    End If
                End If
            Next
        Next

    'Close application to reset its original state
    Window.Close

End Sub

From this post, we learned the following:
1, Get the coordinates of the current cursor position (MouseX and MouseY);
2, Error handling (“On Error GoTo 0″ and “On Error Resume Next”), see post#13 for a detailed explanation;
3, How to move the scroll bar horizontally to x=0 (Scroll 0, tpScrollHorizontal);
4, How to use “BitmapExists” method (“BitmapExists(“CheckBoxInTreeView”, x – 16, y – 8, 15, 15)” means start searching from x-16 and y-8, and search for 15 by 15 pixels area; in this area, search for bitmap “CheckBoxInTreeView”);
5, How to write check results to final result summary (UserCheck).

 
No Comments

Posted by Jia Qi in TestPartner (TP)

 

#11: Who can test Windows TreeView with Checkbox? QTP or TestPartner?

23 Jun


TreeView is a Windows Standard Class, and many Windows Applications use TreeViews. Such as the Workstation I was testing in post#10, the measurement Protocols belong to each measurement Package are listed in a TreeView Window as nodes. Each Portocol Node also has a CheckBox beside it, and I need to test if these CheckBoxes are checked or not.

In TestPartner/QTP, TreeView window is identified as the “TTreeView”/”WinTreeView” object:
1, The nodes inside the TreeView window can NOT be identified by the identification tool;
2, The TreeView window is identified as a TestPartner/QTP TreeView object, not a Windows Standard TreeView object, which means you can ONLY use the TestPartner/QTP built-in methods and properties for the “TTreeView”/”WinTreeView” object. You can NOT use the Windows Standard TreeView methods nor properties.

TestPartner/QTP do have some built-in methods and properties for the “TTreeView”/”WinTreeView” object to allow you to get access to or fetch the properties of the nodes inside the TreeView window. For example, in TestPartner, the most useful method is the “SelectItem” method. However, it disappointingly returns a Boolean…Actually, NONE of the TestPartner built-in “TTreeView” methods or properties can help you to get the properties of the CheckBoxes beside the TreeView nodes. For this particular feature, QTP is much more powerful. It has a built-in method called “CheckItemProperty” for the “WinTreeView” object, which can be used to check all kinds of properties of a TreeView node, including if the CheckBox is checked or not.

The way to use “CheckItemProperty” method in QTP is:
object.CheckItemProperty (Item, PropertyName, PropertyValue, [TimeOut])
One of its “PropertyName” (a String value) is “state”: indicates whether the tree-view control node has a check box, and whether it is selected, and its possible values:
0–the tree-view control node does not have a check box
1–the tree-view control node’s check box is not selected
2–the tree-view control node’s check box is selected
The script to test the Ultrasound workstation will look like this:

Window("the workstation").WinTreeView("SysTreeView32").CheckItemProperty "Measurements;Protocol name", "State", 2

Now we know that we can use QTP to easily check if a CheckBox besides a TreeView node is checked or not. However, how do we handle this issue with TestPartner? (The built-in “TTreeView” methods and properties in TestPartner are insufficient for us to test the TreeView CheckBox).

Here I provide two solutions to use TestPartner to test the TreeView CheckBox:
A, Write a separate script to identify the TreeView object in any Windows Applications as a Windows Standard TreeView Object. In this way, you will be able to use the standard TreeView methods and properties. For example, you can use the “SelectedImageIndex” Property to get the image list index value of the image that is displayed when a tree node is selected (images can be “no CheckBox”, “with CheckBox but not checked”, “with CheckBox and checked”).

This kind of script will be difficult to write. 8thString has wrote a script about how to get TreeView item information using Win32 api. The script is very long, if you are interested, you may want to have a look of it. Besides it is long, it is also very backended. The script talks “Process”, “Memory” and “kernel32″ a lot, which is actually a developer level’s code.

If you do not understand the above script from 8thString, you may want to read my second suggestion to solve the TreeView CheckBox issue with TestPartner:
B, Use the “BitmapExists” method to verify the existence of a pixel from the check mark (saved as a bitmap image called as “MeasurementTreeViewImage”) in the CheckBox area of the TreeView window. The script to test the Ultrasound workstation will look like the following:

Window("the workstation'").Attach
    Set obj = TreeView("Parent.Caption=Preferences")
    If obj.SelectItem("\Measurements\Protocol name") Then
        y = obj.MouseY
        obj.Scroll (tpScrollHorizontal)
        For x = 0 to obj.Width 'you can reduce the search area from the TreeView area to the ChceckBox area by hard coding like this: For x = 40 To 51
            If obj.BitmapExists("MeasurementTreeViewImage", Left:=x, Top:=y, Width:=1, Height:=1) Then
                UserCheck "mycheck", True, "'Protocol CheckBox is checked"
                Exit For
            End If
        Next
    End If
 

#10: Exercise the GetExcelSheetData function with TestPartner to test a Windows Application

16 Jun



In this post, we will practice with the function I wrote in my last post#9 about storing Excel sheet data into an array. We will also start to use TestPartner to test an ultrasound workstation. You do not need to know anything about ultrasound device. You just need to know that the workstation is a Windows Application, i.e., a software.

Users will analyze ultrasound images on the workstation, and they will draw some measurements there. The measurements are built in features, users just need to select the measurement they want to use, and draw it on the image area, and the workstation will automatically calculate the values for the measurement.

There are thousands of build in measurements, which make this a perfect candidate for automation testing. The measurements are organized in 3 levels: Package, Protocol, and Measurement. Each Package contains many Protocols, and each Protocols contains many Measurements.

Today, we will test the following:
Launch the workstation -> Open the Preference Panel -> Select each measurement Packages in the Measurement Package ComboBox, and check “Enable Package” CheckBox is checked.

In the main script, we will use a Global constant called “Declaration_GlobalConstants” which is saved in the Module asset:

Public Const ExcelFilePath_MeasurementTab = "C:\...\MeasurementTab.xlsx"

3 functions will be called in the main script too, and they are saved in the Shared Module asset. Their names are “Function_ExcelSheetRowCount”, “Function_ExcelSheetColumnCount”, and “Function_GetExcelSheetData”. For their scripts please refer to my last post#9

'Testing condition: After clean install
'Check all the measurement packages are enabled in the Preference panel - Measurement tab

'$TPinclude "Declaration_GlobalConstants"

Sub Main()

Dim RowCount As Integer
Dim ColumnCount As Integer
Dim SheetData() As String 'Dynamic array

'Use Shared Modules "Function_ExcelSheetRowCount" and "Function_ExcelSheetColumnCount" 'to get how many rows and columns in the Package sheet of  "MeasurementTab.xlsx"
RowCount = Function_ExcelSheetRowCount.ExcelSheetRowCount(ExcelFilePath_MeasurementTab, "Package")
ColumnCount = Function_ExcelSheetColumnCount.ExcelSheetColumnCount(ExcelFilePath_MeasurementTab, "Package")

'Array is sized dynamically
ReDim SheetData(RowCount, ColumnCount) As String

'Use Shared Module "Function_GetExcelSheetData" to store data from the Package sheet of "MeasurementTab.xlsx" in the array
SheetData() = Function_GetExcelSheetData.GetExcelSheetData(ExcelFilePath_MeasurementTab, "Package")

'Open the workstation
    ProgramManagerWindow("Application=EXPLORER.EXE Caption='Program Manager'").Attach
        ListView("Index=1").Select "the workstation", tpMouseDoubleClick

'In the workstion, open Preference panel, then open the Measurement tab
    Window("Application=VSIAPP.EXE Caption='the workstation").Attach
        Button("Caption=Prefs").Click
        TabControl("Parent.Caption=Preferences").Select "    Measurement    "

        'Select different Packages from the ComboBox, and check if "Enable Package" is checked or not
        For i = 1 To ColumnCount
            For j = 1 To RowCount
                ComboBox("Parent.Caption=Preferences").Select SheetData(j, i)
                ExecuteCheck "Check_PackageEnable"
            Next
        Next

    'Close application to reset its original state
    Window.Close

End Sub

From this post, we learned the following:
1, How to define a Global Constant, and how to use the Global Constant;
2, How to call functions;
3, When call scripts from Module, you need to include ‘$TPinclude “Module Name” at the beginning of your script; but if it is a Shared Module, then no need to do so;
4, How to insert a property check (Insert->Check->Property…).

 
1 Comment

Posted by Jia Qi in TestPartner (TP)

 

#9: Get data from Excel for TestPartner and QTP

11 Jun

QTP and TestPartner provide integrated features for you to test multiple data in one test case. In QTP, the feature is called Data Table, and in TestPartner it is called Active Data. However, both of the features have an disadvantage, which is they only support Data Table or Active Data that has a single sheet.

For example, in TestPartner, to make the Active Data working, first, you need to import an excel file to the Active Data asset. If your excel file has multiple data sheets, and you want to use each of them, this becomes impossible, since in the Active Data asset, you can only select one data sheet (done through the option tab). If you really want to use another data sheet, then you have to rename your excel file, and import it again, and this time, select another data sheet in the option tab.

Someone like me, who wants to save space on the Database and make data easy to maintain, would like to use one Excel file that has multiple sheets instead of use multiple Excel files contain only one sheet per file.

How to do this, we should really get ride of using the Active Data from TestPartner or the Data Table from QTP. We can get data directly from an external Excel file (contains single or multiple work sheets). I have written a function for this, and will show it to you below.

In TestPartner, you may want to save the following code in the Shared Module, since this script can be used across different projects:

Function GetExcelSheetData(FilePath As String, SheetName As String)

'On error jump to "Error Handler:" line
On Error GoTo ErrorHandler

'Variable declaration
Dim SheetCount As Integer
Dim RowCount As Integer
Dim ColumnCount As Integer
Dim CellArray() As String 'A dynamic array that is not sized in the Dim statement

'Open the Excel file
Set ObjExcel = CreateObject("Excel.Application")
Set ObjWorkBook = ObjExcel.Workbooks.Open(FilePath)

'Count how many sheets in the Excel file
SheetCount = ObjWorkBook.WorkSheets.Count

'Store the data from a specific worksheet into an array
For i = 1 To SheetCount
    If ObjWorkBook.WorkSheets(i).Name = SheetName Then

        'Count how many rows and columns in the Excel file (only for the used range)
        RowCount = ObjWorkBook.WorkSheets(i).UsedRange.Rows.Count
        ColumnCount = ObjWorkBook.WorkSheets(i).UsedRange.Columns.Count

        'Array is sized with the ReDim statement
        'after RowCount and ColumnCount are given values.
        ReDim CellArray(1 To RowCount, 1 To ColumnCount) As String

        'Store the data from the specific worksheet into CellArray
        For j = 1 To RowCount
            For k = 1 To ColumnCount
               CellArray(j, k) = ObjWorkBook.WorkSheets(i).UsedRange.Cells(j, k)
            Next
        Next

    End If
Next

'Close the Excel file
ObjWorkBook.Close

'Return CellArray
GetExcelSheetData = CellArray()

Exit Function

ErrorHandler: ' This is a normal VBA line label
    MsgBox Err.Description
    ObjWorkBook.Close

End Function

From the above script, you learned the following:
1, How to write a function with input parameters
2, When deal with external files, you better write something to handle errors
3, How to use “On Error GoTo” (more details see post#13)
4, How to define an array dynamically (Dim and Redim)
5, How to use Excel Object Model, including Excel.Application, Excel.Workbook, Excel. Worksheet, and Excel.Range. (see here)
6, How to return a value in a function

Make some modifications for the Function_GetExcelSheetData Function above, you should be able to write another 2 functions: one is called as Function_ExcelSheetRowCount, and the other one is called as Function_ExcelSheetColumnCount. These 2 functions will return how many rows or columns in a specific Excel sheet, and they will be used together with Function_GetExcelSheetData in my next post.

In order to test the above function, you can write a separate test script to execute it (“Function_GetExcelSheetData” is the file name):

Sub Main()
Dim A
A = Function_GetExcelSheetData.GetExcelSheetData("C:\...\MeasurementTab.xlsx", "Sheet1")
End Sub

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. For example, you have a function “ActiveExcelSheet(FilePath As String, SheetName As String)”, which has no return value, just to active a specific sheet in the Excel file. To execute the function, your script needs to look like this:

Sub Main()
Dim A
A = Function_ActiveExcelSheet.ActiveExcelSheet("C:\...\MeasurementTab.xlsx", "Sheet1")
MsgBox (A) 'this tells you A is nothing
End Sub

If the test script looks like this:

Sub Main()
Function_ActiveExcelSheet.ActiveExcelSheet("C:\...\MeasurementTab.xlsx", "Sheet1")
End Sub

TestPartner will inform you there is a “Syntax error” and won’t allow you to run the script. However, if the function has only one input variable and no return value, then you can execute it without assign it to a variable.

Now, let’s talk about how to take the above function (e.g., the “ActiveExcelSheet” function) to QTP. Since TestPartner uses VBA, but QTP uses VBScript, you need to make the following changes in the function script:
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 “(FilePath As String, SheetName As String)” to “(FilePath, 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., “Function_ActiveExcelSheet.ActiveExcelSheet(…)” changes to “ActiveExcelSheet …”):

ActiveExcelSheet "C:\...\MeasurementTab.xlsx", "Sheet1"

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.

From this post, you may have a better understanding of QTP and TestPartner… Beside the object identifier, all the other features that you need for automation testing actually can be achieved by writing VB scripts in notepad, and save them as .vbs files…

Ok, these are just theoretically speaking, we will still write VB scripts in QTP and TestPartner instead of in notepad, right? Just for the convenience.

 

#8: Start using TestPartner to test a Windows application

01 Jun

In the coming weeks, I will show you how to use TestPartner 6.2 to test a Windows application.

Please read the TestPartner Tutorials first, it should be easy to understand if you already read my previous blogs about using QTP 9.0 to test YouPlayOff.com.

The TestPartner Tutorials has the following sections:

Visual Test Tutorial — Use the TestPartner’s visual, storyboard-based interface to create a visual test that simulates ordering parts from the Bolts ‘N Things sample web application. Learn advanced testing concepts and how to use TestPartner’s integrated time-saving features to eliminate the need for complicated scripting.

- TestPartner Basics: This module explicitly walks you through the step-by-step process of recording and playing back a visual test. Additional lessons provide you with instruction on how to analyze playback results, insert test logic to retrieve data from an external file and a test script, and how to use TestPartner’s basic debugging features.

- TestPartner Advanced Lessons: This module builds on the lessons in the first module and contains examples of advanced testing concepts and how to use TestPartner’s integrated time-saving features to insert test logic in visual tests to eliminate the need for complicated scripting.

Test Script Tutorial — Develop a traditional test script using Visual Basic for Applications (VBA) that simulates bidding on an item from the NuBid sample web application.

I also found the following TestPartner Guides, which may be useful for you. The advanced guide is a scripting level guide.

TestPartner Basic Training Guide.pdf for TestPartner 5.1
TestPartner Advanced Training Guide.pdf for Test Partner 5.2 (I suggest you to read this one)
TestPartner Basic Training Guide.pdf for TestPartner 5.3

 
No Comments

Posted by Jia Qi in TestPartner (TP)

 

#7: Relationship among VBScript, Visual Basic for Applications (VBA), Visual Basic (VB), Visual Basic .NET, and JavaScript

28 May

QTP uses the Visual Basic Scripting Edition (VBScript) scripting language, TestPartner is based on the Visual Basic for Applications (VBA), and RFT’s test script is produced as either a Java or Visual Basic.net application.

VBScript is a subset of the Visual Basic Programming language. The result of the slimming down process is a very small language that is easy to use. JavaScript can do all that VBScript can do and far more. So why use VBScript instead of JavaScript? Because VBScript is much easier to learn than JavaScript.

Visual Basic for Applications (VBA) is another subset of the Visual Basic Programming language for use with Microsoft Word, Excel, Access etc. While it contains a good many features not supported by VBScript, the basic syntax, or construction of the language, is very similar.

RFT is not the main focus for this blog, at least not yet, so for Java vs. VB.NET, you only need to know that Java is programming environment controlled by Sun, and VB.NET is developed by Microsoft.

As said above, both VBScript and VBA are subsets of Visual Basic (VB). The final release of VB was version 6 in 1998. Microsoft’s extended support ended in March 2008 and the designated successor was Visual Basic .NET (now known simply as Visual Basic)

After learning the history of the VB family and JavaScript, let us play a small game by writing the VBScript in a notepad. This is very useful if you do not want to bother to repeat the same thing over and over again.

Copy the following code into a notepad, and save it as kk.vbs, then double click on it, and see what it will do.

Dim fs, file, TSTnumber
set fs = createobject( "Scripting.FileSystemObject" )
set file = fs.OpenTextFile( "RF.BAT", 2, true )

For TSTnumber=613 to 616
file.write "VsiColorModeRAW.exe tst-18-0"
file.write TSTnumber
file.write "\tst-18-0"
file.write TSTnumber
file.write ".raw.bmode tst-18-0"
file.write TSTnumber
file.write "\tst-18-0"
file.write TSTnumber
file.write ".raw.color tst-18-0"
file.write TSTnumber
file.write "\tst-18-0"
file.write TSTnumber
file.write ".raw.xml tst-18-0"
file.write TSTnumber
file.writeline "\Color"
Next
file.close
set fs=nothing
 

#1: Step by Step to learn QTP and TestPartner

15 Jan

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.

8) 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.

 

#0: What is this blog for?

06 Sep

This blog will show you real projects examples for you to learn the following Automation testing tools:
- Quick Test Professional (QTP),
- TestPartner (TP),
- Extensible Markup Language (XML),
- Selenium (Selenium-IDE),
- Rational Functional Tester (RFT).

QTP and TestPartner are similar GUI automation testing tools, and they are both easy to learn compare to RFT which I used before. RFT uses JavaScript or VB.NET, QTP uses VBScript, and TestPartner uses VBA (more details about VB family and JavaScript, please refer to post#7). Among the three, QTP has the biggest job market. As a QA person, we should master at least one of the automation testing tools and one of the scripting language.

Selenium is a portable software testing framework for web applications. Selenium provides a test domain specific language (DSL) to write tests in a number of popular programming languages, including C#, Java, Ruby, Groovy, Python, PHP, and Perl. In this blog, we will focus on Selenium IDE, which is a complete Integrated Development Environment (IDE) for Selenium tests. It is implemented as a Firefox extension, and allows recording, editing, and debugging tests.

The difference between Selenium and QTP/TestPartner/RFT is Selenium is an open source software, i.e., it is free! See more information at post#29.

If you decide to learn automation testing, then you can follow this blog. I will share detailed test cases/scripts with you while I am learning, and I am looking forward to learn from you too, so don’t be shy to comment on my posts.

My current company uses TestPartner 6.3 to test an Ultrasound work station (a Windows Application, i.e., software, can be installed on any computer). Our major focus is to automate measurement and export testing, since we have thousands measurement types and hundreds export combinations in the app., which make manual testing very very time consuming. We will also use XML scripts (embedded in Engineering mode) to test our real-time Ultrasound machines. The Ultrasound machine supports 10 different types of transducers, we need to repeat hundred test cases for each type of the transducers, so to automate the transducer tests will save us a huge amount of time.

I also test some websites at home, just for learning purpose. In this blog, I will show you how to test a website called YouPlayOff. I will use QTP and Selenium to test this website, and you can download QTP 9.0 from the pirate bay and Selenium-IDE from Selenium website.

After we get familiar with QTP, Selenium and TestPartner, then RFT should not be a problem anymore.