Self-Solve Knowledge Search

Minimize Maximize
How to traverse an Object Repository in XLM format
Title :
How to traverse an Object Repository in XLM format
Document ID :
KM01339228
Product - Version:
quicktest professional ; functional testing ;
OS :
Updated :
Thu Jan 08 20:10:16 GMT 2015
Summary :
There are times when is necessary to handle object repositories in xml format, since the object repository can be exported to xml format it can be traversed as a normal xml document using CreateObject("Microsoft.XMLDOM")
Is there a way to navigate or traverse through the objects and child objects in an object repository in xml format?
Solution

Object Repository that has been exported to xml format is a well formed xml document, so it can be iterated using available xml API as Microsoft.XLMDOM. Here is example code that will recursively traverse an xml object repository document to list all test objects creating the corresponding replay statement.

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("C:\repository.xml")

Dim rootObjects, objParentNodes,objParentNode, objChildNode, objChildNodes, strNode, tabs

Set rootObjects = objXMLDoc.documentElement.getElementsByTagName("qtpRep:Objects")

For Each objParentNode In rootObjects
 Set objParentNodes = objParentNode.ChildNodes
 For Each objParent in objParentNodes
   tabs = 1
   Print "-------------------------[ Parent Object ]-------------------------------------"
   Print objParent.getAttribute("Class") & "(""" & objParent.getAttribute("Name") &  """)"
   Call describeOR(FindChildObjectsNode(objParent), tabs)   
 Next 
Next

Set objParentNodes = Nothing
Set objXMLDoc = Nothing

Function describeOR(xmlNode, tabs)
 If xmlNode.hasChildNodes Then
    tabs = tabs + 1 
    For Iterator = 1 To tabs
        strTabs = strTabs & vbTab
    Next 
    For Each strNode in xmlNode.childNodes      
      Print strTabs & strNode.getAttribute("Class") & "(""" & strNode.getAttribute("Name") &  """)"
      Call describeOR(FindChildObjectsNode(strNode), tabs)
    Next      
 End If
End Function

Function FindChildObjectsNode(xmlNode)
 If xmlNode.hasChildNodes Then
    Set chlObjs = xmlNode.getElementsByTagName("qtpRep:ChildObjects")
    Set FindChildObjectsNode = chlObjs(0) 
    Set chlObjs = Nothing
 End If 
End Function

The code above will produce an output similar to this:

-------------------------[ Parent Object ]-------------------------------------
Window("Temp")
  WinObject("Items View")
   WinList("Items View")
-------------------------[ Parent Object ]-------------------------------------
Dialog("Windows Task Manager")
  WinCheckBox("Show processes from all")
  WinButton("End Process")
-------------------------[ Parent Object ]-------------------------------------
Browser("Tryit Editor v2.3")
  Page("Tryit Editor v2.3")
   Frame("Frame")
    WebElement("Search w3schools.com:")
-------------------------[ Parent Object ]-------------------------------------
Browser("Google")
  Page("Google")
   WebElement("SearchButton")
   WebEdit("SearchText")

 DISCLAIMER

The code contained herein is provided “as is” basis and as an example only, it it’s not part of UFT and is not supported by HP, any additional modifications needed are total user responsibility.