Dynamically Rename Shared OR object names

398 views Asked by At

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.?

2

There are 2 answers

0
rijinrv On BEST ANSWER

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
0
Saikrishna On

What you can do , Export the repository to the XML . Then Using the XML dom Object you can navigate to each Node.Each Node will have a Name Attribute .Then you can check there is a space if it is You can change the logical name of it .This will change the Object Repository Names .

But you need do similar king of change in your QTPscript to get reflected .