51Testing软件测试论坛

标题: 获取页面上所有指定属性的对象 [打印本页]

作者: qaarchitech    时间: 2008-6-17 17:00
标题: 获取页面上所有指定属性的对象
by jack
在QTP脚本编写的时候,我们可能会遇到这种检查点:比如获取checkbox的个数等等,这时会提出“获取页面上所有指定属性的对象”的需求。下面是用descrīption对象实现的一个函数,作用就是实现上述需求。
Function getItemList(PageObject,PropertyName,PropertyValue)
Dim oItemDesc
Dim n

Set ōItemDesc=descrīption.Create
If isarray(PropertyName) and isarray(PropertyValue) Then
  Dim iCountPropertyName
  Dim iCountPropertyValue
  
  iCountPropertyName = ubound(PropertyName)
  iCountPropertyValue = ubound(PropertyValue)

  If iCountPropertyName <= iCountPropertyValue Then
   For n=0 to ubound(PropertyName)
    oItemDesc(PropertyName(n)).value=PropertyValue(n)
   Next
  Else
   'lost property value
   'msgbox "lost property value"
   Exit Function
  End If
  
Else If (not isarray(PropertyName)) and (not isarray(PropertyValue)) Then
   oItemDesc(PropertyName).value=PropertyValue
  Else
   'error
   'msgbox "error"
   Exit Function
  End If
End If

Set getItemList=PageObject.childobjects(oItemDesc)
End Function
输入参数有3个,page对象,属性名,属性值;其中属性名和属性值可以为数组,应用举例:
'取出页面所有编辑框
set ōChildList = getItemList(page("51Testing软件测试网"),"micclass","WebEdit")
'编辑框数量
iCountChildList = oChildList.count
'取出页面所有name含有“测试”的链接

set ōChildList = getItemList(page("51Testing软件测试网"),array("micclass","name"),array("Link","测试.*"))
'点击第二个链接
oChildList(1).click
作者: walker1020    时间: 2008-7-31 10:00
不错,值得学习。不过,从“Set ōItemDesc=descrīption.Create” 这句话来看,是从哪个地方转载过来的。能否说明一下此文的出处?
作者: zte_boy    时间: 2008-7-31 10:37
原文就是LZ的博客上的,呵呵
LZ是阿里巴巴一个QA架构师MS
作者: kevin_swpi    时间: 2008-7-31 11:09

藏龙卧虎....

zte_boy
你知道的还不少哦
作者: fan730    时间: 2008-9-1 16:34
标题: 回复 2# 的帖子
Set ōItemDesc=descrīption.Create

这个是QTP里面的一种用法。并非是引用自别的地方。。
这个是QTP本身提供的一种Description对象。用于返回对象包含的属性。
Set ōItemDesc=descrīption.Create( )
这句话就是创建Description的一种典型的用法。




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2