Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

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 Selenium Automation Framework.

In 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. Literally we hide the implementations of the locators from the tests.

INHERITANCE
The mechanism 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 WebDriver interface, WebDriver
waits, & Excels, etc., in the Base Class.

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

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

POLYMORPHISM
Polymorphism allows us to perform a task in multiple ways.

Combination of overloading and overriding is known as Polymorphism.

METHOD OVERRIDING

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

class Animal:
def make_sound(self):
print("Some generic animal sound")

class Dog(Animal):
def make_sound(self):
print("Woof! Woof!")

class Cat(Animal):
def make_sound(self):
print("Meow")

# Create instances of the classes


animal = Animal()
dog = Dog()
cat = Cat()
# Demonstrate method overriding

animal.make_sound() # Output: Some generic animal sound


dog.make_sound() # Output: Woof! Woof!
cat.make_sound() # Output: Meow
In this example:

 The Animal class has a method make_sound with a generic implementation.


 The Dog class and Cat class are subclasses of Animal and both override the make_sound method with their specific
implementations.
 When you create instances of Dog and Cat and call the make_sound method, the overridden method in the respective subclass
is executed.
 If you call make_sound on an instance of the Animal class, the method from the superclass is executed.

Key points:

 Method overriding allows a subclass to provide a specialized implementation of a method defined in its superclass.
 The method in the subclass must have the same name and the same signature (number and type of parameters) as the method
in the superclass.
 Overriding enables polymorphism, where the same method name can have different implementations depending on the type of
object.

METHOD OVERLOADING

Declaring a method in child class which is already present in the parent class is called Method
Overriding. Examples are get and navigate methods of different drivers in Selenium .

class Person:

def Hello(self, name=None):

if name is not None:

print('Hello ' + name)

else:

print('Hello')

# Creating an instance of the Person class

obj = Person()

# Calling the Hello method without providing a name

obj.Hello()

# Calling the Hello method with a name


obj.Hello('Priya')
explanation : the Hello method adapts its behavior based on the number of arguments provided,
showcasing a form of overloading in Python.
In this code:

 The Hello method of the Person class is defined with a default parameter name=None. This means
that if no value is provided for name when the method is called, it defaults to None.
 Inside the method, there's a conditional check: if name is not None. This check is used to determine
whether a name was provided when calling the method.
If a name is provided, it prints a personalized greeting. If no name is provided (i.e., name is None), it
prints a generic greeting.
obj.Hello()
In this case, the Hello method is called without providing any value for name. The default parameter
name=None takes effect, and the method prints "Hello" without a personalized name. This is similar
to calling a method without a specific parameter in traditional method overloading.
obj.Hello('Priya')

Here, the Hello method is called with the argument 'Priya'. The method checks that name is not
None and prints a personalized greeting, resulting in "Hello Priya". This is similar to calling a method
with a specific parameter in traditional method overloading.

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

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.

You might also like