google搜索 51Testing站内搜索                    软件测试门户 | 软件测试培 训 | 文章资料精选 | 软件测试论坛 | 软件测试博客 | 测试招聘求职 
打印

[求助] 请教DP高手看是否QTP的BUG或其他用法错误

请教DP高手看是否QTP的BUG或其他用法错误


ChildObjects方法的参数中是一个properties对象,此处必须使用描述性编程的方法定义对象。
如果在value里使用了正则表达式,我发现怎么弄都不生效,childObjects取不到对象。

以下是代码,我打开一个notepad做测试
第一段是使用了正则表达式,找到的notepad窗体总是为0
第二段是没有用到正则表达式,可以找到notepad窗体数量为1
请教高手看是否有什么错误。
谢谢。
=========================
Set oDesc = Description.Create()
oDesc("text").Value = "U.*Notepad$"
oDesc("text").RegularExpression = True
Set OpenedNotepadWindows=Desktop.ChildObjects(oDesc)
msgbox OpenedNotepadWindows.Count ' you get 0
Window(oDesc).Close 'it always works
Set oDesc = Nothing

=========================
Set oDesc = Description.Create()
oDesc("text").Value = "Untitled - Notepad"
oDesc("text").RegularExpression = True
Set OpenedNotepadWindows=Desktop.ChildObjects(oDesc)
msgbox OpenedNotepadWindows.Count ' you get 1
Window(oDesc).Close 'it always works
Set oDesc = Nothing

TOP

初步判断是 oDesc("text").Value = "U.*Notepad$"引起的。
1,你的QTP版本是?
2, 仔细检查一下 这个正则表达式是否可以达到你要的效果。
实践是检验真理的唯一标准。

TOP

替代方案:oDesc("regexpwndclass").Value = "Notepad"

Desktop好像有点问题,普通的根对象用这种方法没问题。期待正解

[ 本帖最后由 jackymail 于 2008-1-10 02:03 编辑 ]
http://www.abfun.cn 北京测试圈
http://www.abfun.cn 北京测试圈

TOP

引用:
原帖由 walker1020 于 2008-1-10 01:08 发表
初步判断是 oDesc("text").Value = "U.*Notepad$"引起的。
1,你的QTP版本是?
2, 仔细检查一下 这个正则表达式是否可以达到你要的效果。
版主要带好头,不要为了没啥意义的积分灌白开水

TOP

引用:
原帖由 jackymail 于 2008-1-10 01:48 发表
替代方案:oDesc("regexpwndclass").Value = "Notepad"

Desktop好像有点问题,普通的根对象用这种方法没问题。期待正解
看来是Desktop对象有问题。
打开notepda的font设置,运行下面代码,可以找到font对话框
Set oDesc = Description.Create()
oDesc("regexpwndtitle").Value = ".*t$"
oDesc("regexpwndtitle").RegularExpression = True
Set OpenedNotepadWindows=Window("regexpwndclass:=Notepad").ChildObjects(oDesc)
msgbox OpenedNotepadWindows.Count ' you get 1
Set oDesc = Nothing

没有其他办法的话,只好用GetROProperty绕过去了。

以下是国外论坛上找到的同样问题,有回复如下:

http://www.sqaforums.com/showfla ... PSESSID=#Post446909

==============================
Re: Newbie QTP Regular Expression Difficulties  [Re:  gy21st]
      #447101 - 01/09/08 08:31 AM        
Edit post Edit           Reply to this post Reply           Reply to this post Quote           Quick Reply Quick Reply  

ChildObject implementation is not always reliable and as per my recent SR with HP they told me that RE might not always work for some properties. And i doubt that Desktop.ChildObject would be as good as Browser().Page().ChildObjects

Because Desktop is not a TestObject but a reserved object.

--------------------
Tarun

TOP

确实应该是Desktop.ChildObject 的问题,在帮助中也能看出它的一丝特殊性,估计还是mercury(HP)设计考虑不够周全
路漫漫其修远兮,吾需努力再努力

欢迎加我MSN共同讨论QTP疑难杂症~加好友时请注明51testing~

TOP

 
当前时区 GMT+8, 现在时间是 2008-10-12 02:28Copyright(C)上海博为峰软件技术有限公司 2001-2007 电话:021-64471599-8017
当您在访问网站、论坛及博客过程中遇到问题时可发送email:webmaster@51testing.com或发送论坛短信至管理员风在吹