本文共 10363 字,大约阅读时间需要 34 分钟。
http://www.softwaretestinghelp.com/qtp-tutorial-23-miscellaneous-qtp-concepts/
Object Identification is the core of UFT. You should understand it thoroughly before you try to work on any automation testing projects. In the earlier tutorial we discussed the . We discussed various stages of object identification namely Learned Description, Visual Relation Identifiers (VRI), Smart Identification and Ordinal Identifiers. In this tutorial, we will discuss the 3rd stage in detail – Smart Identification
If UFT is unable to identify any object that matches the learned object description, or if it finds more than one object that fits the description, then UFT ignores the learned description, and uses Visual Relation Identifiers (VRI) to identify an object uniquely. If VRI is not defined or VRI is not able to identify the object uniquely, UFT invokes the Smart Identification mechanism and try to identify the object.
While the Smart Identification mechanism is more complex, it is more flexible. Therefore, if configured logically, a Smart Identification definition can probably help UFT identify an object, if it is present, even when the learned description fails.
The Smart Identification mechanism uses two types of properties:
a
to any other value, you could no longer call it the same object.If UFT activates the Smart Identification mechanism during a run session (because it was unable to identify an object based on its learned description and VRI), it follows the following process to identify the object:
If, after completing the Smart Identification elimination process, UFT still cannot identify the object, then there are two possibilities:
If the combined learned description and ordinal identifier are not sufficient to identify the object, then UFT stops the run session and displays a Run Error message.
If the learned description and VRI does not enable UFT to identify a specified object in a step, and a Smart Identification definition is defined (and enabled) for the object, then UFT tries to identify the object using the Smart Identification mechanism.
If UFT successfully uses Smart Identification to find an object after no object matches the learned description, the Test Results receive a warning status and indicate that the Smart Identification mechanism was used.
If the Smart Identification mechanism cannot successfully identify the object and VRI is not defined, UFT uses the learned description + the ordinal identifier to identify the object. If the object is still not identified, the test fails and a normal failed step is displayed in the results.
The following example walks you through the object identification process for an object.
Suppose you have the following statement in your test:
Browser("LearnQTP").Page("LearnQTP").WebEdit("userName").Set "mercury"
When you created your test, UFT learned the following object description for the UserName edit box:
However, at some point after you created your test, a second UserName edit box was added to the bottom of the page, so the Web designer changed the original UserName edit box name tag to: userName1
The default description for edit box objects (type, name, html tag) works for most edit boxes in your site, but it no longer works for the UserName edit box, because that edit box name property no longer matches the learned description. Therefore, when you run your test, UFT is unable to identify the UserName edit box based on the learned description. However, UFT succeeds in identifying the UserName edit box using its Smart Identification definition.
The explanation below describes the process that UFT uses to find the UserName edit box object using Smart Identification:
1. According to the Smart Identification definition for WebEdit objects, UFT learned the values of the following properties when you recorded the click on the UserName edit box:
2. UFT begins the Smart Identification process by identifying the two objects on the web page that match the base filter properties definition (html tag = INPUT
and type = text
). UFT considers these to be the object candidates and begins checking the object candidates against the Optional Filter Properties list.
3. UFT checks the name property of each of the object candidates, but none have the name property value userName, so UFT ignores this property and moves on to the next one.
4. UFT checks the html id property of the two object candidates. Only one of them has the value loginbox, so UFT correctly concludes that it has found the first username edit box and enters the required value in it.
You use the Smart Identification Properties dialog box, accessible from the Object Identification dialog box, to configure the Smart Identification definition for a test object class.
1. Choose Tools > Object Identification. The Object Identification dialog box opens.
2. Select the appropriate environment in the Environment list on the top left. The test object classes associated with the selected environment are displayed in the Test object classes list.
The environments included in the Environment list are those that correspond to the loaded add-in in the .
3. Select the test object class you want to configure.
4. Click the Configure button next to the Enable Smart Identification check box. The Configure button is enabled only when the Enable Smart Identification option is selected. The Smart Identification Properties dialog box opens:
5. In the Base Filter Properties list, click Add/Remove. The Add/Remove Properties dialog box for base filter properties opens.
6. Select the properties you want to include in the Base Filter Properties list and/or clear the properties you want to remove from the list.
Note: You CANNOT include the same property in both the base and optional property lists.
For all environments except Web, you can specify a new property by clicking New and specifying a valid property name in the displayed dialog box.
For web objects, you can add property names to the set of available properties using the attribute/<PropertyName>
notation. To do this, click New. The New Property dialog box opens. Enter a valid property in the format attribute/<PropertyName>
and click OK. The new property is added to the Base Filter Properties list. For example, to add a property called MyColor
, enter attribute/MyColor
.
7. Click OK to close the Add/Remove Properties dialog box. The updated set of base filter properties is displayed in the Base Filter Properties list.
8. In the Optional Filter Properties list, click Add/Remove. The Add/Remove Properties dialog box for optional filter properties opens.
9. Select the properties you want to include in the Optional Filter Properties list and/or clear the properties you want to remove from the list.
Note: You cannot include the same property in both the base and optional property lists.
For all environments except Web, you can specify a new property by clicking New and specifying a valid property name in the displayed dialog box.
For web objects, you can add property names to the set of available properties using the attribute/<PropertyName>
notation. To do this, click New. The New Property dialog box opens. Enter a valid property in the format attribute/<PropertyName>
and click OK. The new property is added to the Base Filter Properties list. For example, to add a property called MyColor
, enter attribute/MyColor
.
10. Click OK to close the Add/Remove Properties dialog box. The properties are displayed in the Optional Filter Properties list.
11. Use the up ⇧ and down ⇩ arrows to set your preferred order for the optional filter properties. When UFT uses the Smart Identification mechanism, it checks the remaining object candidates against the optional properties one-by-one according to the order you set in the Optional Filter Properties list until it filters the object candidates down to one object.
That’s all about Smart Identification in UFT (QTP). In the next tutorial we will learn in detail about Visual Relation Identifier.
If you have any questions around Smart Identification, please comment below. You can refer earlier tutorials in the series at this link .
If you have not already done so, make sure you enter your name and address below to receive the next tutorial as soon as it is ready.
转载地址:http://sqrmi.baihongyu.com/