51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 4600|回复: 9
打印 上一主题 下一主题

[原创] 谈qtp识别控件的过程

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2009-3-11 21:17:03 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
我们都知道Qtp能识别标准控件,但对于一些自定义或第三方的控件却识别不好。有的可以用映射的方法来识别。
下面是我猜想Qtp识别控件的过程: 首先,windows 的标准控件都有一个固定的类名, 如按钮控件是button, 对话框是dialog(#3270),这个是window系统指定的。所以当我们第一次录制的时候或用spy的时候,可以从 hwnd = WindowFromPoint(point) 获得当前窗口的句柄,然后通过GetClassName(hwnd)得到它的类名。比如一个标准按钮,通过这个样子就得到类名为button, qtp中就知道了它是winbutton,如果类名是dialog(#3270),那么Qtp就把它认为是dialog, 但是第三方的控件,往往它们的类名是作者自己写的,例如**button等等,这样Qtp就不能把名字对应起来。但是它的一些属性还是可以得到,所以就把它认做WinObject了。但是通过映射对象,即我们告诉Qtp当遇到类名为**button要把它认做winbutton, 所以映射的时候要指定映射的控件和标准控件,并且映射一次后,这一类控件就都被识别成标准控件。个人见解,抛砖引玉了。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

10#
 楼主| 发表于 2009-3-12 17:07:21 | 只看该作者
下午又看了看Qtp的安装目录,发现标准控件,web控件,vb控件封装的dll, 都是com组件, 在bin目录下,文件名为**package.dll   比如WWWPackage.dll,  等,而qtp加载它们应该是通过**config.xml来加载,即使不是加载也很有关系,大家可以用exescope来看一下那些dll文件,在typelib中可以发现有关函数的说明,还有一些qtp没有公开的函数哦。
比如 OnClicktext. ()
回复 支持 反对

使用道具 举报

该用户从未签到

9#
发表于 2009-3-12 16:14:38 | 只看该作者
我看看谁能给个例子啊!
回复 支持 反对

使用道具 举报

该用户从未签到

8#
发表于 2009-3-12 12:44:47 | 只看该作者
9.5支持用户自己编写控件。
回复 支持 反对

使用道具 举报

该用户从未签到

7#
 楼主| 发表于 2009-3-12 11:00:10 | 只看该作者
如果我们能够自己定义控件的属性和方法并把它加到Qtp中,就好了。
.Net插件能够提供扩展,但是哪位大大有实现过,给个提示。
回复 支持 反对

使用道具 举报

该用户从未签到

6#
发表于 2009-3-12 09:35:31 | 只看该作者

楼主主要说的是winform程序

自动化过程中需要比对才能知晓控件等是否是预期的,所以需要在录制时得到它的某些属性,在回放时比对。一般Control ID是不会变化的。

LZ说的比较全了,如果没有插件QTP只能识别控件低层次的行为,而不是有意义的行为,尤其对于定制的控件来说,可能测试对象的方法不足。下面引用.net扩展帮助里的几段话:
If you are not satisfied with the existing object identification or behavior, your .NET Windows Forms control is a candidate for .NET Add-in Extensibility, as illustrated in the following situations:
➤ A test object class already exists with more appropriate behavior for your custom .NET Windows Forms control. You can use .NET Add-in Extensibility to map the control to this test object class.
➤ QuickTest might recognize the control using a test object that does not fit your needs. You can use .NET Add-in Extensibility to instruct QuickTest to change the functionality of the test object by modifying its methods.
➤ QuickTest might identify individual sub-controls within your custom control, but not properly identify your main control. For example, if your main custom control is a digital clock with edit boxes containing the hour and minute digits, you might want changes in the time to be recognized as SetTime operations on the clock control and not as Set operations on the edit boxes. You can use .NET Add-in Extensibility to set a message filter to process messages from child controls, and record operations on the main control in response to events that occur on the controls it contains.


Java扩展:
If you are not satisfied with the existing object identification or behavior, your control is a candidate for Java Add-in Extensibility, as illustrated in the following situations:
➤ QuickTest might recognize the control using a test object class that does not fit your needs. You can use Java Add-in Extensibility to map the custom class to another existing test object class or to a new test object class that you create.
➤ The test object class mapped to the control might be satisfactory, but you would like to customize the behavior of certain test object methods or identification properties. You can use Java Add-in Extensibility to override the default implementation of these properties and methods with your own
custom implementation.
➤ You may find that the test object names QuickTest generates for all controls of a certain Java class are identical (except for a unique counter) or that the name used for the control does not clearly indicate the object it represents. You can use Java Add-in Extensibility to modify how QuickTest names test objects for that Java class.
➤ QuickTest may identify individual sub-controls within your custom control, but not properly identify your main control. For example, if your main custom control is a digital clock with edit boxes containing the hour and minute digits, you might want changes in the time to be recognized as
SetTime operations on the clock control and not as Set operations on the edit boxes. You can use Java Add-in Extensibility to treat a custom control as a wrapper object for the controls it contains. QuickTest does not learn the individual controls contained in a wrapper object.
➤ During a record session, when you perform operations or trigger events on your control, QuickTest may not record a step at all, or it may record steps that are not specific to the control’s behavior. Alternatively, QuickTest may record many steps for an event that should be considered a single operation, or it may record a step when no step should be recorded. You can use Java Add-in Extensibility to modify the events to listen for and the test steps to record for specific events.


Web扩展
If you are not satisfied with the existing object identification or behavior, your Web control is a candidate for Web Add-in Extensibility, as illustrated in the following situations:
➤ QuickTest might recognize the control using a test object class that does not fit your needs. You can use Web Add-in Extensibility to instruct QuickTest to identify the custom control as belonging to a new test object class that you create.
➤ The test object class that QuickTest uses for the control might be satisfactory, but you would like to customize the behavior of certain test object methods or identification properties. You can use Web Add-in Extensibility to create a new test object class that extends the one QuickTest uses, override the implementation of these properties and methods with your own custom implementation, and instruct QuickTest to use the new test object class.
➤ You might find that the test object names QuickTest generates for all objects of a certain control type are identical (except for a unique counter) or that the name used for the test object does not clearly indicate the control it represents. You can use Web Add-in Extensibility to create a new test object class that extends the one QuickTest uses, modify how QuickTest names test objects of your new class, and instruct QuickTest to use the new test object class.
➤ QuickTest might identify individual sub-controls within your custom control, but not properly identify your main control. For example, if your main custom control is a digital clock with edit boxes containing the hour and minute digits, you might want changes in the time to be recognized as
SetTime operations on the clock control and not as Set operations on the edit boxes. You can use Web Add-in Extensibility to modify how events that occur on child controls are treated.
➤ During a record session, when you perform operations or trigger events on your control, QuickTest might not record a step at all, or it might record steps that are not specific to the control’s behavior. Alternatively, QuickTest might record many steps for an event that should be considered a single operation, or it might record a step when no step should be recorded.

[ 本帖最后由 shanxi 于 2009-3-12 09:54 编辑 ]
回复 支持 反对

使用道具 举报

该用户从未签到

5#
 楼主| 发表于 2009-3-12 07:27:32 | 只看该作者
我说的映射就是ls说的类映射了,一般在tools->object identification...
回复 支持 反对

使用道具 举报

该用户从未签到

4#
发表于 2009-3-11 23:52:54 | 只看该作者
QTP识别不了的对象,可以采用低级别录制和虚拟对象映射与虚拟类映射。
能虚拟为类映射就不要虚拟为对象映射
回复 支持 反对

使用道具 举报

该用户从未签到

3#
发表于 2009-3-11 23:31:15 | 只看该作者
我现在就遇到了这样的问题,第3方控件识别不了,不知道该怎么办?

》映射对象  指的是什么?有具体的操作方法吗?
回复 支持 反对

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2009-3-11 21:34:24 | 只看该作者

继续

这样如果第三方控件添加了一些属性和方法,由于Qtp内部只封装了标准的控件的方法和属性,就不能够支持新增的属性和方法了。这个也可以解释为什么需要装.net插件,Java插件的问题。
但是,我们自己如何定义自己的插件,还希望高手指点。
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-8 13:53 , Processed in 0.071575 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表