Monday, January 9, 2012

QTP : Object Identification

The process of uniquely identifying an object from the application window is known as Object Identification. QTP uses two modes object identification. to recognize the object uniquely.

  • Normal Identification mode
  • Smart Identification mode
  • Ordinal  Identifiers
Normal Identification
QTP has two lists of properties based on which it will identify the object uniquely. The first list is the list of mandatory properties. QTP learns these default property values and checks if any object matches the description. If no object in the application is identified uniquely it adds properties from the second list called as assistive properties. All the properties in the assistive list are added one by one till a unique object is identified.

Ordinal IdentifiersEven after using mandatory and assistive properties if the object is not uniquely identified then QTP uses the ordinal identifiers to identify the object uniquely.There are three types of ordinal identifiers :

  1. Index: This identifier indicates the order in which the object appears in the application code. This order is unique even though identical objects are present.
  2. Location: This identifier indicates the order in which the object appears within the window, frame or dialog box irrespective of objects with identical description.
  3. Creation Time: This identifier is applicable only to web applications. This identifier indicates a unique id in the order in which the browser were opened. This identifier is handy in identifying the browser to be worked on when a group of identical browsers are open.
Smart Identification
When normal identification fails to identify a unique object. QTP switches to next mode of identification called smart identification, the smart identification mode must be enabled for the test. The smart identification mechanism uses two lists of properties:
  • Base Filter Properties: The list of properties contain the most fundamental properties of a particular test object class whose values cannot be changed without changing the original object. 
  • Optional Filter Properties: Other properties that can help identify objects of a particular class as they are unlikely to change on a regular basis, but which can be ignored if they are no longer applicable.
Configuring Object Identification
When QTP learns an object, it learns a set of properties and values that uniquely describe the object within the object hierarchy. If you expect the values of the properties in the object description may change frequently, you can configure the way that QTP learns and identifies objects.

Steps to configure mandatory and assistive properties
Select Tools>Object Identification, The Object Identification dialog box opens up as shown below
  1. Select the appropriate environment in the in the Environment list.
  2. In the Test Object classes list, select the test object class you want to configure.
  3. In the Mandatory Properties list, click Add/Remove. From the Add/Remove properties dialog opened select the properties you want to include. Click OK to close the Add/Remove Properties dialog box. You can also add new properties by clicking New button.
  4. In the Assistive Properties list, Click Add/Remove. Select the properties you want to include in the assistive properties.
  5. Use the Up and Down  arrows   to set your preferred order for the assistive properties. Click OK to close the Add/Remove properties dialog box. The properties are displayed in the Assistive Properties list.
Steps to configure smart identification properties
  1. Select Tools>Object Identification. Select the appropriate environment from the Environment list.
  2. Select the test object class you want to configure.
  3. Click the Configure button next to the Enable Smart Identification check box. The Smart Identification Properties dialog box appears as below:

  4. In the Base Filter Properties List, Click Add/Remove. The Add/Remove Properties dialog box opens,  Select the properties you want to include in the Base Filter Properties. Click OK to close the ADD/Remove properties dialog box.
  5. In the Optional Filter Properties list, click Add/Remove. The Add/Remove Properties dialog box for optional filter properties opens. Select the properties you want to include in the Optional Filter Properties list.
  6. Use the up and down arrows   to set your preferred order for the optional filter properties. Click OK to close the Add/Remove Properties dialog box.
NOTE: Smart Identification uses one by one filter properties during the test run and if any one property matches , it considers that object as the object to work with. sometimes this may lead to wrong object identification. let's say we use  Height and Width as optional filter properties to identify  an object A. Let's say developer change A object's Height and creates a new object Y with the same Height of X. Now Tool recognizes Y as the object to work instead of X and performs operation on that.

Object Identification Work Flow
Let us consider a step which clicks on Images link from the Bing Home Page.
In the above step QTP must identify Images link before it performs the click operation . In order to do so QTP follows the three steps approach as shown below:

Step 1: Map Logical name of the object in the script with Logical name of the object in Repository. If the Logical name is not found in the object repository, an error dialog box appears indicating the object was not found in the repository.

Step 2: Here QTP reads Test Object Description which is nothing but all the properties required to identify the Test Object. For the Images link on the Bing search page, below is the Test Object description in the Object Repository:
Step 3: Using the above properties, QTP goes to application and tries to recognize a unique object which is matching the test object description. If the object was not found the error dialog box opens up indicating the object was not found in the application with the specified properties of the object in the repository. In case smart identification is enabled QTP will go to smart identification and try to recognize the object using smart identification mechanism.

Logical NameLogical name is the name given by QTP to the Test Object. This logical name is used in QTP script and Object Repository to map test object from script to Object Repository. It is important to note that Logical name of all objects of a particular class under a particular parent must be unique. The advantage of logical name is it can be changed for better readability of the script and also it helps in better maintenance of the script for application changes.

Custom to Standard Mapping
If the application under test contains objects that do not belong to a particular class type, such objects are recorded as WinObjects and are called custom objects.Such custom objects can be mapped to an existing standard windows class.

Steps to map a Custom class to a Standard Window class
  1. Choose Tools>Object Identification. The object identification dialog box opens.
  2. Select Standard Windows in the Environment box. The User-Defined button becomes enabled.
  3. Click User-Defined. the Object Mapping dialog box opens as shown below.
  4. Click the pointing hand and then click the object whose class you want to add as a user-defined class.  The name of the user defined object is displayed in the Class Name box.
  5. In the Map to box, select the standard object class to which you want to map to your  user-defined object class and click Add. The class name and mapping is added to the object mapping list.
  6. If you want to map additional objects to standard classes, repeat steps 4 & 5 for each object.
  7. Click OK. The object mapping dialog box closes and your object is added to the list of Standard Windows test object classes as a user defined test object.

1 comment: