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





