[QTP]GetROProperty,GetTOProperties,GetTOProperty的区别

上一篇 / 下一篇  2011-11-24 10:12:41 / 个人分类:QTP

刚开始做QTP自动化的项目,现在还是学习的阶段。从0开始学起,吼吼~~~

GetToProperty:Returns the value of the specified property from the test object description.
GetTOProperties:Returns the collection of properties and values used to identify the object.
GetROProperty:Returns the current value of the test object property from the object in the application.
举个例子:
假设在库中有一个对象"窗口A",用于识别该对象的属性有2个,
一个属性是"text",在库中记录的值是"QQQQ".
另一个属性是"name",记录的值是"MM"
在实际运行脚本时属性"text"的值是"PPPP"而不是"QQQQ"
那么:
Window("窗口A").GetToProperty("text")返回的是:"QQQQ"
Window("窗口A").GetRoProperty("text")返回的是:"PPPP"
Window("窗口A").GetToProperties("text")返回的是用于识别"窗口A"的两个属性和值的集合

 

相关的几个函数有:

GetTOProperty():取得仓库对象的某个属性的值
GetTOProperties():取得仓库对象的所有属性的值
SetTOProperty():设置仓库对象的某个属性的值

GetROProperty():取得实际对象的某个属性的值


理解了TO的含义,你就可以自由的用SetTOProperty()定义TO,以灵活的操作RO

比如有个测试任务,窗口上有很多待检查的记录,每条记录右边都有一个Check按钮,用来检查各条记录。
记录个数不定,所以Check按钮个数也就不定,只有一个Edit显示记录个数。
我们要对每条记录进行检查,也就是要点击每个Check按钮。
但是Check按钮个数不定,不好录制,而且个数可能也很多(上百个),即使能一一录制,那也很麻烦。

那我有一个好办法,只录制一个按钮对象,它设有两个特征属性 label=OK, index=0
然后用下面的脚本,就可以完成测试

buttonNum = CInt(JavaWindow("Test").JavaEdit("Record Num").GetROProperty("value"))
For buttonIndex = 0 to buttonNum - 1
  JavaWindow("Test").JavaButton("Check").SetTOProperty("index", buttonIndex)
  JavaWindow("Test").JavaButton("Check").Click
Next


或者窗口上有New、Modify、Delete、Check等好几个按钮,要把这几个按钮一一按过去
我在对象仓库里只设置一个按钮对象AnyButton,label特征属性值填任意值,然后用下面脚本执行测试

JavaWindow("Test").JavaButton("AnyButton").SetTOProperty("label", "New")
JavaWindow("Test").JavaButton("AnyButton").Click

JavaWindow("Test").JavaButton("AnyButton").SetTOProperty("label", "Modify")
JavaWindow("Test").JavaButton("AnyButton").Click

JavaWindow("Test").JavaButton("AnyButton").SetTOProperty("label", "Delete")
JavaWindow("Test").JavaButton("AnyButton").Click

JavaWindow("Test").JavaButton("AnyButton").SetTOProperty("label", "Check")
JavaWindow("Test").JavaButton("AnyButton").Click


另外,QTP还支持脚本描述的方法来定义和访问对象,即不需要在仓库里定义,也能访问和操作实际对象
( Written by yabest,http://yabest.net
如上面两个任务,可以如下实现

1. 不需要在仓库里定义Check按钮对象,直接用下面脚本来实现测试

buttonNum = CInt(JavaWindow("Test").JavaEdit("Record Num").GetROProperty("value"))
For buttonIndex = 0 to buttonNum - 1
  JavaWindow("Test").JavaButton("label:=Check", "index:="+CStr(buttonIndex)).Click
Next

2. 不需要在仓库里定义New、Modify、Delete、Check按钮对象,直接用下面脚本来实现测试

JavaWindow("Test").JavaButton("label:=New").Click
JavaWindow("Test").JavaButton("label:=Modify").Click
JavaWindow("Test").JavaButton("label:=Delete").Click
JavaWindow("Test").JavaButton("label:=Check").Click



 


TAG:

 

评分:0

我来说两句

日历

« 2024-04-27  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 4641
  • 日志数: 7
  • 建立时间: 2011-04-19
  • 更新时间: 2012-08-20

RSS订阅

Open Toolbar