Classes and Objects are the essence of UFT.

This tutorial will set you on the path to learn one of the most fundamental concepts of a modern programming language. If you already have some experience with object oriented programming languages like C  or Java, you will be able to breeze through this tutorial. If you are new to the world of programming, we will make sure you understand the concepts of classes and objects by the end of this tutorial.

You will understand the meaning of classes, methods, objects, properties and how they are relevant to UFT.

What is the difference between Class and Object?

In its simplest form, Class can be defined as a blueprint or a template or a category of things having some attributes in common. An Object is an instance of a Class.

Examples:

If we consider Mobile Phone as a class, its objects can be an iPhone 7, Samsung Galaxy S8 or a Google Pixel. If we consider Shape as a class, its objects can be a circle, a rectangle or a square.

Class describes a concept while Object represents something specific that is created using that concept.

If we consider Car as a class, its objects can be BMW i8, Tesla 3 or an Audi a3.

objects-classes-uft

What is the difference between Properties and Methods?

Properties store data for an object and helps in identifying an object. Methods are actions that can be carried out on an object.

In the example above, properties of a given car can be its year of manufacture, color and whether it has a sunroof or not. Methods for a given car can be the action of accelerating, honking and turning its steering wheel.

A class holds the definition of methods and properties that are shared by all of the objects that are created from it. With the help of distinct property values, one can identify the objects uniquely. Example: In the graphic above, out of the three cars, BMW i8 can be identified by its distinct color pinkish-red and the fact that it does not have a sun roof.

What are Classes, Objects, Properties and Methods in UFT (QTP)?

Let us understand these concepts with the help of an illustration.

classes-vs-objects-uft-qtp

In the image above;

  • SIGN-ON, REGISTER, SUPPORT and CONTACT links are Objects of Class Link. SIGN-ON object can have properties like href and text using which we can uniquely identify it on a given web page. It has a method Click , using which we can reach a given location.
  • User Name and Password fields are Objects of Class WebEdit. User Name object can have properties like name and max-length using which we can uniquely identify it on a given web page. It has a method Set, using which we can enter the text in the edit box.

Essentially, all GUI elements that you see on your application are objects of a particular class. In the case of a web application, classes can be of type links, edit boxes, images, drop-downs and more. When you talk about a specific link or a specific edit box you refer to an object. In the example above, Sign-in button is an Object of Class WebButtton.

Since classes depends on the type of application, they will vary according the to the add-ins loaded in UFT.

Where can we locate Classes for a given Add-in in UFT?

As we have discussed in the earlier tutorial on add-ins in UFT, when you enable a particular add-in in UFT, you make sure UFT supports that type of application.

The Object Identification Dialog Box (Tools > Object Identification) in UFT shows all the classes available for a given add-in.

Here is an illustration for Web Add-in.

object-identification-uft

The image above shows classes available for the Web Add-in environment and the different types of properties available for a highlighted class called WebEdit.

How to locate the Properties and Method for a given object?

Object Spy.

Object spy is one of the most frequently used utilities in UFT. You can use it to identify the properties, their corresponding values & the methods associated with a given object.
Since UFT 12.5, you can even use Object Spy to add objects to Object repository.

properties-methods-objectThe image above shows properties and operations available for a SIGN-ON object of class Link. Note that on Object Spy window, UFT refers  Methods as Operations.

With this we come to the end of the tutorial. We hope you were able to understand the meaning of terms like Objects, Classes, Properties and Methods. Please chime-in with your comments below if you have any questions related to this tutorial.

Additional Reading: Class Name vs class in UFT

In the next tutorial we will discuss in detail about native and identification properties in UFT.
Make sure you enter your name and address below to receive the next tutorial as soon as it is ready.

Here is the complete set of tutorials we have covered till now in the UFT tutorial series: