mklodoss 发表于 2009-3-11 21:17:03

谈qtp识别控件的过程

我们都知道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, 所以映射的时候要指定映射的控件和标准控件,并且映射一次后,这一类控件就都被识别成标准控件。个人见解,抛砖引玉了。

mklodoss 发表于 2009-3-11 21:34:24

继续

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

lbdy108 发表于 2009-3-11 23:31:15

我现在就遇到了这样的问题,第3方控件识别不了,不知道该怎么办?

》映射对象指的是什么?有具体的操作方法吗?:)

xln_simu 发表于 2009-3-11 23:52:54

QTP识别不了的对象,可以采用低级别录制和虚拟对象映射与虚拟类映射。
能虚拟为类映射就不要虚拟为对象映射

mklodoss 发表于 2009-3-12 07:27:32

我说的映射就是ls说的类映射了,一般在tools->object identification...

shanxi 发表于 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 编辑 ]

mklodoss 发表于 2009-3-12 11:00:10

如果我们能够自己定义控件的属性和方法并把它加到Qtp中,就好了。
.Net插件能够提供扩展,但是哪位大大有实现过,给个提示。:lol

假装不在 发表于 2009-3-12 12:44:47

:hug: 9.5支持用户自己编写控件。

heqingbluesky 发表于 2009-3-12 16:14:38

我看看谁能给个例子啊!:P

mklodoss 发表于 2009-3-12 17:07:21

下午又看了看Qtp的安装目录,发现标准控件,web控件,vb控件封装的dll, 都是com组件, 在bin目录下,文件名为**package.dll   比如WWWPackage.dll,等,而qtp加载它们应该是通过**config.xml来加载,即使不是加载也很有关系,大家可以用exescope来看一下那些dll文件,在typelib中可以发现有关函数的说明,还有一些qtp没有公开的函数哦。
比如 OnClicktext.:lol ()
页: [1]
查看完整版本: 谈qtp识别控件的过程