TestComplete 学习笔记1_Namemapping

上一篇 / 下一篇  2008-09-21 15:12:13 / 个人分类:TestComplete学习

  1. TC没有像QTP一样的对象库以及对象库管理功能,但是对于那些“又长又臭”的代码行,可以通过Named Mappings 和Aliases 来缩短代码行,并且让测试对象的命名更加有意义,从而让录制和编写的脚本更加清晰、直观易懂。
    TestComplete provides Named Mappings and Aliases to tame extremely long object identifiers that have meaningless default names. For example:

Sys.Process("Hello").Panel1.Panel2.Container1.Container2.button1


Clearly there are numerous issues with this identifier, its long and awkward not to mention we have no clue about the purpose or identity of "Container1", "Container2" or "button1". Named Mappings allow you to rename Panel1, Panel2, Container1, Container2 and button1 to useful names like MyPanel,myInsidePanel, myTabs, myPages and btnSubmit. The issue here is that you still need to type:
NameMappings.Sys.Process("Hello").MyPanel.myInsidePanel.myTabs.myPages.btnSubmit

TestComplete lets you create an Alias to represent this long string. If you create the Alias "btnSubmit",you only need to type:
Aliases.btnSubmit

可通过两种方法实现NameMapping:

  1. Mapping an object with TestComplete’s dialogs and panels
  • To map an object’s name via theObject Browser:
    1. Switch to theObject Browserpanel.
    2. Choose the desired object in this panel and selectMap the Object Namefrom the context menu.

-- or --

  • To map an object’s name directly using theToolstoolbar:
    1. Press theOpen the Tools Windowbutton on TestComplete's toolbar or choose the menu itemTools | Tools. This will bring up theToolstoolbar.
    2. Activate the application's window that holds the onscreen object you want to map.
    3. Click theMap Object From Screenbutton (the mouse cursor will turn into theFindertool glyph), hold the mouse button down and drag the glyph over the screen. As you move, the red frame will surround onscreen objects which are under the glyth. Release the mouse button over the desired object.

 

2.Map an object from scrīpts

To map an object, use theAddNamedChildmethod of any mapped object (this method is added after the object was mapped). This method uses four parameters:

obj.AddNamedChild(SysNode,ChildName,Descrīption,Properties)

  • SysNode- Specifies the object to be mapped.
  • ChildName- Specifies the desired mapped name for an object.
  • Descrīption- Specifies the mapped item’s descrīption.
  • Properties- Holds an array of object property names that will be used for object recognition.

By calling theAddNamedChildmethod of a mapped object, you make its child object a child mapping item.

The following scrīpt code maps theSysobject and then allprocessobjects (children of Sys). We assume that theSysobject has already been mapped tosys2:

SubTestNameMapping
  
  ' Creating the property array
  Arr = CreateVariantArray(0, 1)
  Arr(0) = "ProcessName"
  Arr(1) = "Index"
  
  ' Mapping objects
  Fori = 0ToSys.ChildCount - 1
    SetProcessObj = Sys.Child(i)
    IfProcessObj.MappedName = ""Then
      ' Generating the mapped name
      s = ProcessObj.ProcessName + CStr(ProcessObj.Index)
      ' Checking if the mapped name can be used
      IfIsValidIdent(s)Then
        ' Mapping the object
        ' We assume that the Sys object is mapped to sys2.
        NameMapping.sys2.AddNamedChild ProcessObj, s, "The process object", Arr
      Else
        Log.Message "Cannot map the object " + ProcessObj.Name
      End If
    End If
  Next
End Sub   

 


TAG: TestComplete学习

引用 删除 why771023   /   2018-04-10 17:42:51
-1
Candy_Xue的个人空间 引用 删除 Candy_Xue   /   2012-07-12 17:15:05
3
 

评分:0

我来说两句

我的栏目

日历

« 2024-05-12  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 2610
  • 日志数: 3
  • 建立时间: 2008-08-27
  • 更新时间: 2008-09-22

RSS订阅

Open Toolbar