Search code examples
vbscriptqtphp-uft

Dynamically Rename Shared OR object names


As per the naming convention we are following, we need to rename every object to its standard name. One such convention is to replace space between with ‘_’

eg. Object name ->Object_name

Is there any way to perform it dynamically using lines of code.?


Solution

  • Export the OR to xml file and use the following line of code. And use the xml generated to import OR back to QTP. This is specific to SAP GUI

    Function  ModifyORXML(inputFilepath,outputFilepath)
    Set xmlDoc =  CreateObject("Microsoft.XMLDOM")
    xmlDoc.Async = "False"
    xmlDoc.Load(inputFilepath)
    Set xmlNodeList = xmlDoc.getElementsByTagName("qtpRep:Object")
    num = xmlNodeList.length
    
    For each x in xmlNodeList
        AttName=x.getattribute("Name")
        If x.getattribute("Class")="SAPGuiButton" Then
            tmp=Split(AttName," ",-1,1)
            AttName=tmp(0)
        End If
        AttName=Replace(AttName,Chr(34)," ")
        AttName=Replace(AttName,")"," ")
        AttName=Trim(AttName)           
        oldAttName=AttName
        AttName=Replace(AttName,":"," ")                
        AttName=Trim(AttName)
        AttName=Replace(AttName," ","_")    
        AttName=Replace(AttName," __","_",1,-1,1)   
        x.Attributes.getNamedItem("Name").Text = AttName
    Next    
    xmlDoc.Save outputFilepath  
    End Function