Professional Documents
Culture Documents
Oops
Oops
Abstraction is the methodology of hiding the implementation of internal details and showing the
functionality to the users.
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.
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")
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:
else:
print('Hello')
obj = Person()
obj.Hello()
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.