Understanding the OOPS is the foundation for automation. This doesn’t mean that as an automation engineer you should have very strong knowledge in OOPS like any other programmer. All you should know is very basics like Class, Object and its Method and Properties to begin with.
Most of the automation tool identifies every object (like edit box, button, and drop down) by the properties and perform action on those objects with the available methods (like Set, Click, and Select).
To begin let us start with understanding what is a class in OOPS world
It is a blue print from which we can build similar Objects, it is a container used to group related attributes (properties) and methods.
So what is an Object?
Before OOPS, code and data were kept separately. For example, in the C language, units of code are called functions and units of data are called structures. But, in object oriented programming, code and data are merged into a same, called an object.
To make it more clear,An Object is basically program hiding in a ‘box’. Almost every visual key you use in a software program is an object. Objects can be clicked, accessed via keyboard, by mouse-over, joystick, steering wheel, etc…Even the tool bar, back button of your browser is an object. Object is a box that hides program in it, and interact with user.
For us Back button is just a button, on which we can click, it takes you to previous page. But for automation tool Back button, is an object derived from class Button.We click on the back button to go to previous page, because we know that button can be clicked, but then how browser knows that on clicking Back button it should go back to previous page not to refresh page? Because back button has certain properties associated with it, which tells the browser that on click of this button do certain actions.
Method is nothing but the action that can be performed on that object
Property is the attributes or characteristics of that Object.
Hope you get some idea now, on why you need to understand OOPS for automation.
The same logic holds good when we use automation tools. The tool we use identifies and stores those object into object repository (in QTP),so when we run the script it compares the current object properties with the stored one to identify the right object on which the action needs to be performed. The Method tells what the action should to be .
The code to click on Google Search button in QTP looks
Browser (“Google”).Page (“Google”).WebButton (“Google Search”).Click
So here Browser, Page and WebButton are Class,First Google inside quotes is Object of class Browser,second Google is object of Class Page ,Google Search is object of Class Webbutton.These are stored into object repository(in QTP). Click is the method that you are going to use to click the button.
Class: It is a blue print from which you create object
Object: Almost every thing you see on the computer screen is an object
Method: Tell us the actions, which can be performed on the object
Property: Attributes that define or help to identify an object
Next to Read : Object Repository and Descriptive Programming in QTP