RSS
 

#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
 

Tags: , , , , , , , , ,

Leave a Reply