Reusable method to get item path of a TreeView item using TestPartner

over 8 years ago

There is no available methods to get the item path of a TreeView item in TestPartner. This type of method would be able to return the full item path for the tree items at runtime. Below is a reusable method 'GetItemPathTreeView' that will be able to perform this operation provided that the parent node is known. This approach means that the user must provide the possible parent nodes of where the tree item should be, the function then searches the specified parent nodes for the tree item and will return the full paths of the item that are found. Note that the function below uses the 'TreeViewItemExists' function from wiki article 'Resuable method to verify if a TreeView item exists...'.

' Function to get item path of a specified TreeView object from a given parent node
Public Function GetItemPathTreeView(ByVal TreeView As TTreeView, ByVal ParentNodes As Collection, ByVal NodeToSearch As String) As Collection
      Dim cPaths As New Collection
On Error GoTo Err
      Dim Node As Variant
      For Each Node In ParentNodes
            Dim sPath As String
            sPath = "\" & Node & "\" & NodeToSearch
            If TreeViewItemExists(TreeView, sPath) Then
                  cPaths.Add (sPath)
            End If
      If Err.Number <> 0 Then
            msg = "Error # " & Str(Err.Number) & " was generated by " _
            & Err.Source & Chr(13) & Err.Description
            MsgBox msg, , "Error", Err.HelpFile, Err.HelpContext
      End If
      Set GetItemPathTreeView = cPaths
End Function

Below is a subroutine that uses the above function:

' Example to show how to determine location(s) of an item
Sub ExampleGetItemPath()
      ' TestPartner current does not have the method to get the item paths at runtime,
      ' therefore, you will need to create a list to store all the parent tree paths

      Dim ParentNodes As New Collection
      ParentNodes.Add ("Node-1")
      ParentNodes.Add ("Node-2")
      ParentNodes.Add ("Node-3")
      ' Specify the item we are searching for in the parent nodes
      Dim NodeToSearch As String
      NodeToSearch = "Item-C"
      ' Attach to Tree View Window
      Window("Tree View Window").Attach
      Dim resPaths As Collection
      Set resPaths = GetItemPathTreeView(TreeView("Label='The Tree View'"), ParentNodes, NodeToSearch)

      Dim path As Variant
      For Each path In resPaths
            MsgBox path
End Sub


Support Tip
Comment List
Related Discussions