David的测试技术空间,收藏好文档和分享我的技术理解。5年的数通产品测试和安全产品测试经验,3年Web产品测试和多年测试管理和测试工具开发经验。目前关注性能分析调优、Jmeter和TestNG+WebDriver+Hamcrest的培训推广。Welcome沟通交流,请留言或者发邮件到daviwang_2004 at soguo.com。
Get the Browser associated with any Test Object
上一篇 /
下一篇 2007-10-09 10:31:03
/ 个人分类:QTP
copy from:http://www.softwareinquisition.com/2006/03/quicktest-pro-get-the-browser-associated-with-any-test-object
QuickTest Pro: Get the Browser associated with any Test ObjectMarch 9, 2006
It is pretty
common for me to write
QTP functions that take a Frame as an argument
and only operate within that frame. This works out pretty well until I
have to address the browser where the frame resides. I can always set a
local oBrowser object to the frame's GetTOProperty("parent"), but what
if I am working with a table that resides within a frame within a
Browser? What if I don't know how many levels up the tree the browser
is. I wrote a small function that will return the browser object from
the tree of any object no matter how deeply nested.
PublicFunctionWebObjectGetBrowser(oWebObject)
SetoWebObject2 = oWebObject
WhileNotoWebObject2.GetROProperty("micclass")="Browser"
SetoWebObject2 = oWebObject2.GetTOProperty("parent")
Wend
SetWebObjectGetBrowser = oWebObject2
EndFunction
Now, with the WebObjectGetBrowser function if I am operating on a
table and need to do a sync before the next operation to keep an
exist(0) from failing, I can use code like this.
'...operating on the object oTable...
SetōBrowser = WebObjectGetBrowser(oTable)
oBrowser.Sync
'...continue working with oTable...
This works, but it is still one line too long and creates the
oBrowser object that isn't otherwise necessary. I do a lot of syncing,
so I wrote another function and registered it to WebTable, Frame and
several other classes.
PublicFunctionWebObjectSync(oWebObject)
SetōBrowser = WebObjectGetBrowser(oWebObject)
oBrowser.Sync
EndFunction
RegisterUserFunc"Frame","Sync","WebObjectSync"
RegisterUserFunc"Image","Sync","WebObjectSync"
'...more register entries
Now my previous two lines can be reduced to one.
收藏
举报
TAG:
QTP