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

[求助] 如何创建一个对应的object

如何创建一个对应的object


在QTP使用中遇到这样一个问题:

SystemUtil.Run "NotePad.exe"
'这个位置希望加一个WaitProperty方法,在打开NotePad后延迟5S后再关闭NotePad
SystemUtil.CloseDescendentProcesses

不知道在第二行如何创建这个对象?请帮忙,初学QTP,望各位指教,谢谢 sdlkfj2

TOP

这是帮助上的一个例子,希望对楼主有启发.
Sub CloseDescendentProcesses_Example()
'The following example uses the Run method to open a file named type.txt
'in the default text application (Notepad). It then types "happy days",
'saves the file using shortcut keys, and then closes the application.
SystemUtil.Run "C:\type.txt", "", "", ""
Window("Text:=type.txt - Notepad").Type "happy days"
Window("Text:=type.txt - Notepad").Type micAltDwn & "F" & micAltUp
Window("Text:=type.txt - Notepad").Type micLShiftDwn & "S" & micLShiftUp
Window("Text:=type.txt - Notepad").Close
End Sub

TOP

Tip: This method is useful for test run synchronization. Unlike the Exist method, the WaitProperty method enables you to synchronize the test run based on a specific object property. For example, you can instruct QuickTest to wait for a particular string to appear in a static text control:
就是说必须文本框的内容发生了改变,才可以触发WaitProperty,它一般用于synchronization
如果偏要实现也行:用WaitProperty方法,然后用robot设定好时间去改变文本框的内容,这样QTP就能捕捉到,从而触发WaitProperty事件,呵呵

TOP

十分感谢二位的解答 sdlkfj3
呵呵我确实该好好研究一下qtp自带的help了,但现在还是有个地方搞不清,这也是我开始学qtp一直困扰我的地方,就是这个object.
1、譬如例子里的window对象,是如何添加到object Reporsitory呢?
2、如果不添加到对象库里run的时候会报一个找不到对象的错误。record的方式估计是无法录制这个对象吧?
3、除了利用record的方式来添加到对象库之外,我用过手动添加对象到对象库,可没成功,是我操作不对还是其他原因导致的呢?

TOP

能不能这样处理:
while not Window("Text:=***.txt - Notepad").Exists
      wait 1
wend
wait 5
Window("Text:=***.txt - Notepad").Close

TOP

SystemUtil.Run "NotePad.exe"
Window("Text:=[a-z]* - Notepad").WaitProperty  "visible", True, 3
Wait 5
Window("Text:=[a-z]* - Notepad").Close
这个我试过可以的

TOP

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