Reusable method to verify if a TreeView item exists using TestPartner

over 8 years ago

There is no available methods to verify the existence of an item in a TreeView object in TestPartner. However, we know that if we can select an item in a TreeView, that the item does exist. Therefore, we can use the SelectItem method within an error handler to verify if an item exists in a TreeView object. This operation can be performed in a method that returns a boolean value on whether the selection passed or failed as shown below.

' Function to check if a TreeView item exists
Public Function TreeViewItemExists(ByVal TreeView As TTreeView, ByVal item As String) As Boolean
On Error GoTo Err
      TreeViewItemExists = TreeView.SelectItem(item)
      If Err.Number <> 0 Then
            TreeViewItemExists = False
      End If
End Function

Below is an example subroutine that uses the above function:

' using the TreeViewItemExists function to check if an item exists
Sub ExampleTreeItemExists()
      ' TreeView has the following items
      ' \Node-1, \Node-1\Item-A, \Node-1\Item-B, \Node-1\Item-C
      ' \Node-2, \Node-2\Item-A, \Node-2\Item-C
      ' \Node-3, \Node-3\Item-A, \Node-3\Item-B

      ' Attach to Tree View Window
      Window("Tree View Window").Attach

      ' Display True/False if the TreeView item exists
      MsgBox (TreeViewItemExists(TreeView("Label='The Tree View'"), "\Node-1\Item-C"))
End Sub


Support Tip
Comment List
Related Discussions