You may face this question Where you have applied OOPs concept in Automation Framework? in almost all the Selenium Interviews. Let's learn OOP’s concept in Java before going further.
In this post, we will discuss how and where we applied all OOPs concepts in an Automation Framework.
Abstraction is a methodology of hiding the implementation and displaying the functionality to end users.
Let’s understand with an example:
In Page Object Model design pattern, we write locators (such as Id, Name, Xpath, etc. ) and the methods in a Page class. Then we utilize these locators and methods in tests but we can’t see the implementation of the methods.
In Java, abstraction is achieved by interfaces and abstract classes. Using interfaces, we can achieve 100% abstraction.
We all are aware of this statement
WebDriver driver = new FirefoxDriver();
Here WebDriver is an Interface. In the above statement, we are initializing the Firefox browser using Selenium WebDriver (Interface).
It means we are creating a reference variable (driver) of the interface (WebDriver) and creating an object of FirefoxDriver class.
Note: An interface looks similar to a class but actually both different concepts. An interface can have methods and variables just like the class but the methods declared in the interface are by default abstract.
Note: We can achieve 100% abstraction and multiple inheritance in Java with Interface.
Mechanism by which one class acquires the properties (instance variables) and functionalities of another class is known as Inheritance.
Base Class in the Automation Framework is used 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.
Polymorphism allows us to perform a task in multiple ways.
A combination of overloading and overriding is known as Polymorphism.
Lets understand overloading and overriding in details.
We use Implicit wait in Selenium. The 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 are called Method Overloading.
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.
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.
This will definitely help you in understanding how and where we applied all OOPs concepts in an Automation Framework.