top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-
kll94538

OOPS concepts in Java, where you have applied OOPS in Automation Framework.

OOPS Stands for Object Oriented Programming System.

Object-Oriented Programming Concepts are very important for programming. Without having an idea about OOPS concepts, you will not be able to design systems in the object-oriented programming model.



The object-oriented programming model revolves around the concept of Objects.

What is an Object?

An object is an instance of a Class. It contains properties and functions. They are like real-world objects. For example, your car, house, laptop, etc. are all objects. They have some specific properties and methods to perform some action.

What is a Class?

The Class defines the blueprint of Objects. They define the properties and functionalities of the objects. For example, a Laptop is a class and your laptop is an instance of it.


Core OOPS concepts are:


  1. Abstraction

  2. Encapsulation

  3. Polymorphism

  4. Inheritance

  5. Association

  6. Aggregation

  7. Composition






Now we will discuss how and where we applied the following OOPS concepts in an Automation Framework.


1. ABSTRACTION


Abstraction is the methodology of hiding the implementation of internal details and showing the functionality to the users.

Let’s see an example of data abstraction in the Selenium Automation Framework.

In the Page Object Model design pattern, we write locators (such as id, name, XPath, etc.,) and the methods in a Page Class. We utilize these locators in tests but we can’t see the implementation of the methods. We hide the implementations of the locators from the tests.

In Java, abstraction is achieved by interfaces and abstract classes. Using interfaces, we can achieve 100% abstraction.


2. INTERFACE


The basic statement we all know in Selenium is WebDriver driver = new FirefoxDriver();

WebDriver itself is an Interface. So based on the above statement WebDriver driver = new FirefoxDriver(); we are initializing Firefox browser using Selenium WebDriver. It means we are creating a reference variable (driver) of the interface (WebDriver) and creating an Object. Here WebDriver is an Interface as mentioned earlier and FirefoxDriver is a class.

An interface in Java looks similar to a class but both the interface and class are two different concepts. An interface can have methods and variables just like the class but the methods declared in the interface are by default abstract. We can achieve 100% abstraction and multiple inheritance in Java with Interface.



3. INHERITANCE


The mechanism in Java by which one class acquires the properties (instance variables) and functionalities of another class is known as Inheritance.

We create a Base Class in the Automation Framework to initialize the WebDriver interface, WebDriver waits, Property files, Excels, etc., in the Base Class.

We extend the Base Class to other classes such as Tests and Utility Class.

Here we extend one class (Base Class like WebDriver Interface) into another class (like Tests, Utility Class) is known as Inheritance.




4. POLYMORPHISM


Polymorphism allows us to perform a task in multiple ways.

A combination of overloading and overriding is known as Polymorphism. We will see both overloading and overriding below.


1. METHOD OVERLOADING


We use Implicit Wait in Selenium. Implicit wait is an example of overloading. In Implicit wait, we use different time stamps such as SECONDS, MINUTES, HOURS, etc.,



Action class in TestNG is also an example of overloading.

Assert class in TestNG is also an example of overloading.

A class having multiple methods with the same name but different parameters is called a Method Overloading


2. METHOD OVERRIDING


We use a method that was already implemented in another class by changing its parameters. To understand this you need to understand Overriding in Java.

Declaring a method in a child class that is already present in the parent class is called Method Overriding. Examples are getting and navigating methods of different drivers in Selenium.


5. ENCAPSULATION


All the classes in a framework are an example of Encapsulation. In POM classes, we declare the data members using @FindBy and initialization of data members will be done using Constructor to utilize those in methods.

Encapsulation is a mechanism of binding code and data (variables) together in a single unit.



Thanks for reading!





1,550 views0 comments

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page