QTP - Object Identification
上一篇 / 下一篇 2010-12-15 20:56:41 / 个人分类:功能自动化测试
QTP通过三类属性来识别对象:a)Mandatory; b)Assistive; c)Ordinal identifiers。大部分情况下,通过对象的一些特定属性值就可以识别对象(类型a)。这些属性可以通过Tools->ObjectIdentification定义。每个测试对象类拥有一系列用于唯一确定对象的属性,这就是在这个ObjectIdentification里查看。比如我看了一下WebEdit空间的识别方式,发现它就是通过type,name和html tag来识别。
在这里列出了所有QTP能识别的控件,以及控件的识别方式。你可以给他添加X、Y坐标进行识别。或更明显的,列表中的信息,不按名称识别,而是按ID识别。这个修改可以解决一些问题,想动手试试,但是不知道从何下手……
1. Smart Identification:
http://hi.baidu.com/iooc/blog/item/37c00a4c6178e2f9d72afcd4.html
智能识别机制主要工作于测试脚本运行时(对象允许智能识别为真),当对象库中对象的强制属性(或辅助属性)与被测应用程序中对应对象的属性不一致时,智能识别机制将会启动。其主要原理为:先选择某个基本属性进行比较,若对象多于一个,再继续添加属性筛选;若添加的对象属性造成无对象匹配,则淘汰该属性,应用该方法直至找到唯一对象并对该对象执行操作。(若所有属性的添加或淘汰都无法识别唯一对象,QTP将应用ordinal identifier去识别对象。)
以上是原话,然后我的理解是:比如要识别页面上的一个webedit控件,然后这个空间有那么多的属性,qtp会根据他的属性,然后从object identification里的强制属性和辅助属性里找,假如一致,就可以识别到他就是identification机制里定义的webedit了,假如还是识别不到,就用智能识别。再不行,就用index。
在界面中可看到各种标准Windows控件对应的对象识别方法,例如,对于Dialog控件,使用的是“is child window”、“is owned window”、“nativeclass”和“text”这四个控件对象的属性来区别出一个唯一的Dilalog控件对象。可以单击“Add/Remove”按钮,选择更多的控件属性来唯一识别控件。
以下这篇帖子有部分qtp官方文档的原话,我觉得理解起来更加权威些:
http://bbs.51testing.com/thread-107505-1-1.html
When you run a test, QuickTest searches for the object that matches the
description it learned (without the ordinal identifier). If it cannot find any
object that matches the description, or if it finds more than one object that
matches, QuickTest uses the Smart Identification mechanism (if enabled) to
identify the object. In many cases, a Smart Identification definition can help
QuickTest identify an object, if it is present, even when the learned
description fails due to changes in one or more property values. The test
object description is used together with the ordinal identifier only in cases
where the Smart Identification mechanism does not succeed in narrowing
down the object candidates to a single object.
The Object Identification dialog box also enables you to configure new
user-defined classes and map them to an existing test object class so that
QuickTest can recognize objects from your user-defined classes when you
run your test.
2. Ordinal Identifier:
http://hi.baidu.com/iooc/blog/index/2
http://hi.baidu.com/iooc/blog/item/6f21fbc4573d78a98226acd6.html
QTP除了可以获取到被测对象的主属性、辅助属性值外,还可以获取到被测对象的Ordinal Identifier值。当QTP发现有多个对象具有相同的主属性值、辅助属性值而无法对它们进行唯一识别时, Ordinal Identifier会获取每个对象的序列值,以将它们区别开来。
TAG: