Where you applied OOPs in Automation Testing?

Author: neptune | 11th-Dec-2022 | Views: 523
#Interview #Java

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.


1. ABSTRACTION

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.


What is INTERFACE?

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.


2. INHERITANCE

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.


3. POLYMORPHISM

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.

1. METHOD OVERLOADING

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.


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.


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.


This will definitely help you in understanding how and where we applied all OOPs concepts in an Automation Framework.

 





Related Blogs
How to use wait commands in Selenium WebDriver in Java ?
Author: neptune | 22nd-Feb-2022 | Views: 1612
#Selenium #Testing #Java
We are going to explore different types of waits in Selenium WebDriver. Implicit wait, Explicit wait, and Fluent wait with examples...

Mostly asked Python Interview Questions - 2022.
Author: neptune | 25th-May-2022 | Views: 1161
#Python #Interview
Python interview questions for freshers. These questions asked in 2022 Python interviews...

Top 50+ Selenium Interviews Questions 2022 based on Years of Experience
Author: neptune | 31st-May-2022 | Views: 1143
#Selenium #Testing #Interview
Every interview difficulty is based on how many years of experience you have in that field. For the Selenium Automation Tester I have divided the question on the number of years of experience...

25 Basic Java interview questions.
Author: neptune | 30th-May-2022 | Views: 793
#Interview #Java
We will explore 25 basic Java interview questions...

Core Python Syllabus for Interviews
Author: neptune | 11th-Jun-2022 | Views: 680
#Python #Interview
STRING MANIPULATION : Introduction to Python String, Accessing Individual Elements, String Operators, String Slices, String Functions and Methods...

Best way to reverse a String for beginners in Java.
Author: neptune | 02nd-Oct-2022 | Views: 540
#Java
We will explore How to reverse a String in Java using simple way. If you are beginner in Java then you are at the right place...

20 TestNG Interview Questions
Author: neptune | 17th-Dec-2022 | Views: 322
#Selenium #Interview
There is always more than one test or method in the class. If we do not prioritize these tests or methods, then the methods are selected alphabetically and executed while execution...

Java Script Interview Questions
Author: neptune | 09th-May-2022 | Views: 316
#JavaScript #Interview
Basic JavaScript questions asked in interviews : 1. What are the different data types present in javascript? 2. Difference between "==" and "===" operators...

How would one explain object-oriented programming to a beginner, using a layman language?
Author: neptune | 29th-Oct-2022 | Views: 308
#Java
In 1994 Rolling Stone interview, Steve Jobs explains What is object-oriented programming?..

Top 10 Selenium Interview Questions.
Author: neptune | 03rd-Jun-2022 | Views: 276
#Selenium #Interview
Locator is a command that tells Selenium IDE which GUI elements (like Text Box, Buttons, Check Boxes etc) we are going to use or perform some automation task...

30+ SQL Interview Questions
Author: neptune | 05th-Jan-2023 | Views: 251
#Interview #SQL
Data Definition Language (DDL) – It allows end-users to CREATE, ALTER, and DELETE database objects...

Torch and Bridge | Puzzle
Author: neptune | 11th-Dec-2022 | Views: 167
#Interview #Puzzle
One Torch and 4 person needs to cross the bridge, but can't crossed without the torch. Two persons can walk on the bridge at any time, find minimum time to cross the bridge...

Difference b/w String, StringBuffer, and StringBuilder
Author: neptune | 23rd-Sep-2022 | Views: 148
#Java
String is a sequence of characters in Java. String is a class in the java.lang package. String objects are immutable in nature...

Static Import Concept in Java
Author: neptune | 31st-Dec-2022 | Views: 134
#Java
If you overuse the static import feature, it makes the program unreadable and unmaintainable...

View More