In traditional keyword frameworks, the object map (name mapping in TestComplete terms) is kept in a separate file than the project it self.  For example:

 

Object_Name Object_Reference Parent_Object Description
Notepad Sys.Process("Notepad")   Notepad Application
Editor Window("Notepad", "*", 1).Window("Edit", "", 1) Notepad Editor for Notepad
ChangedDialog Window("#32770", "Notepad", 1) Notepad Do you want to save the changes dialog
NoButton Window("Button", "&No", 2) ChangedDialog No Button on the save changes dialog
Represents a simple view of Notepad.
The next step is to read in the object map and create routines to find the objects when needed. I am going to use VBScript for the sample.
   1: Dim ObjectMapStorage
   2:  
   3: Class ObjectMap
   4:   Private m_TestObject
   5:   Private m_ObjectReference
   6:   Private m_ParentObject
   7:   Private m_ObjectInfo
   8:   
   9:   Public Property Get TestObject
  10:    TestObject = m_TestObject
  11:   End Property
  12:   Public Property Get ObjectReference 
  13:    ObjectReference = m_ObjectReference
  14:   End Property
  15:   Public Property Get ParentObject
  16:    ParentObject = m_ParentObject
  17:   End Property 
  18:   Public Property Get ObjectInfo  
  19:    ObjectInfo = m_ObjectInfo
  20:   End Property
  21:    
  22:   Public Property Let TestObject(Value)
  23:     if (Value <> m_TestObject) Then
  24:       if ObjectMapStorage.Exists(m_TestObject) Then
  25:         ObjectMapStorage.Remove(m_TestObject)
  26:       end if 
  27:       if ObjectMapStorage.Exists(Value) Then
  28:         ObjectMapStorage.Remove(Value)
  29:       end if 
  30:       m_TestObject = Value
  31:       Call ObjectMapStorage.Add(m_TestObject,me)
  32:     End if
  33:   End Property
  34:   Public Property Let ObjectReference(Value)  
  35:    m_ObjectReference = Value
  36:   End Property
  37:   Public Property Let ParentObject(Value) 
  38:    m_ParentObject = Value
  39:   End Property 
  40:   Public Property Let ObjectInfo(Value)   
  41:    m_ObjectInfo = Value
  42:   End Property
  43:     
  44:   Function GetTestCompleteObject
  45:      Dim S
  46:      if (VarType(ParentObject) = varNull)  Then
  47:        S = ObjectReference
  48:      Else
  49:        If not ObjectMapStorage.Exists(ParentObject) then
  50:          Log.Error("Unable to find parent [" & ParentObject & "] of object [" & TestObject & "]")
  51:          Set GetTestCompleteObject = Utils.CreateStubObject
  52:          Exit Function
  53:        End If  
  54:        Dim ParentObjMapItem
  55:        Set ParentObjMapItem  = ObjectMapStorage.Item(ParentObject)
  56:        Dim ParentObj
  57:        Set ParentObj = ParentObjMapItem.GetTestCompleteObject
  58:        S = ParentObj.FullName + "."  + ObjectReference
  59:      end if    
  60:      Set GetTestCompleteObject = Eval(S) 
  61:   End Function
  62:   
  63: End Class
  64:  
  65: Function GetTestCompleteObject(ObjectName)
  66:   if ObjectMapStorage.Exists(ObjectName) Then
  67:     Dim Obj
  68:     Set Obj = ObjectMapStorage.Item(ObjectName)
  69:     Set GetTestCompleteObject = Obj.GetTestCompleteObject
  70:   Else
  71:     Log.Error("Object Does not exist [" & ObjectName & "]")
  72:     Set GetTestCompleteObject = Utils.CreateStubObject
  73:   End if
  74: End Function
  75:  
  76: Sub ReadObjectMap(ObjectMapExcelFile, Sheet)
  77:   Set ObjectMapStorage = Sys.OleObject("scripting.dictionary")
  78:   Set DDTDriver = DDT.ExcelDriver(ObjectMapExcelFile, Sheet)
  79:   While not DDTDriver.EOF
  80:     Dim Obj
  81:     Set Obj = new ObjectMap
  82:     Obj.TestObject = DDTDriver.Value("Object_Name")
  83:     Obj.ObjectReference = DDTDriver.Value("Object_Reference")
  84:     Obj.ParentObject = DDTDriver.Value("Parent_Object") 
  85:     Obj.ObjectInfo = DDTDriver.Value("Description")    
  86:     DDTDriver.Next
  87:   WEND
  88: End Sub
  89:  
  90:  
  91: Sub TestObjectMap
  92:  
  93:    Set ObjectMapStorage = Sys.OleObject("scripting.dictionary")
  94:  
  95:    Dim Obj
  96:    
  97:    Set Obj = new ObjectMap
  98:    Obj.ObjectReference = "Sys.Process(""Notepad"")"
  99:    Obj.TestObject = "Notepad"
 100:    
 101:    
 102:    
 103:    Set Obj1 = new ObjectMap
 104:    Obj1.ObjectReference = "Window(""Notepad"", ""*"", 1)"
 105:    Obj1.TestObject = "Notepad_Main_Window"
 106:    Obj1.ParentObject = "Notepad"
 107:    
 108:    
 109:    
 110:    Dim ObjChild
 111:    Set ObjChild = new ObjectMap
 112:    ObjChild.ObjectReference = "Window(""Edit"")"
 113:    ObjChild.TestObject = "Notepad_Edit"
 114:    ObjChild.ParentObject = "Notepad_Main_Window"
 115:    
 116:    Set Temp = ObjChild.GetTestCompleteObject
 117: End Sub
 118:  
 119:  
 120:  
 121: Sub TestReadObjectMap
 122:  Call  ReadObjectMap(Files.FileNameByName("ObjectMap.xls"),"Sheet1")
 123:   GetTestCompleteObject("Editor").Keys("TestComplete")
 124:   GetTestCompleteObject("Dummy")
 125: End Sub  
 

TestComplete Project Keyword Framework

 

del.icio.us Tags: ,