Wednesday, 23 November 2011

How QTP Recognises Objects

Before going to the details of how QTP recognises an Object, let's have a brief idea about what an Object is. As we have covered (with the assumption of all have covered) Object Oriented Programming Concept(OOPS), all must have known that an Object is a run time entity (though all must have jaded with this definition) which has a physical existence. Same applies to QTP Objects. Some examples of QTP objects for let say a web application may be Check Box,Radio Button,Web Button,Combo Box etc.

There are two types of object in QTP such as Test Objects and Run Time Objects. Test Objects are those objects which are stored in the repository during a recording session. All the properties (along with their values) associated with an object are stored during recording session in the object repository. Properties of an object may be, for instance Name, Title, Value, HTML Tag etc. Run Time Objects, on the other hand are the actuals objects in the application which QTP encounters during a run session on which methods are performed. Property values of a Test Object are matched with the Propery values of the corresponding Run Time to identify an Object.

For each object class, QuickTest learns a set of properties when it records and it uses this description to identify the object when it runs the test. For example, by default, QTP learns the HTML Tag, Name, and Type of each Web Button on which we record an operation. If the above three Mandatory properties values are not sufficient to uniquely identify the Web Button within its parent object, QuickTest adds some assistive properties and/or an ordinal identifier to create a unique description. Assistive property for the Web Button may be Value, Innertext, Outertext etc. An ordinal identifier may be the Index or Location.

Now, for explaining how QTP recognises an object having some of its properties values stored in the repository, let us correlate how we human being recognise a person we have met before. Suppose you have met Mr. X some years ago. At that time you had marked some of his physical appearance or structure like his approximate height, complexion, eye color, hair style, voice, facial appearance etc. Here your gray matter works as the repository where you stored all the attributes of Mr. X. Now if you have to identify Mr. X from a group of say 50 people, you will try to recall all the attributes that you have marked during your previous meeting. Since you are meeting after a long gap, Mr. X might have lost all his hair and hence you cann't identify him by just recalling his hair style or there may be more than one person whose height and complexion match with that of Mr. X and hence it is diffucult for you to recognise him by the attribute height and complexion. But now, atleast you have a rough idea about who may be Mr. X among 50 people, though you are not sure. When you recall his facial appearance and listen to his voice you are able to recognise Mr. X easily.

This is what exactly happens when QTP has to recognise an object. It reads the property values stored in the repository, and tries to identify it. If QTP does not able to identify an object by the property values stored in the repository, it invokes a mechanism called Smart Identification Mechanism (SIM) which further checks with some more properties values. If still it can not identify the object, it throws an error saying Object can not be identified.

No comments:

Post a Comment