Understanding the application of OOPs concepts in Selenium

Understanding the application of OOPs concepts in Selenium

As we already know, the Object Oriented Programming(OOPs) concepts in Java includes:

  1. Abstraction
  2. Inheritance
  3. Interface
  4. Polymorphism
  5. Encapsulation

Abstraction

It is a methodology of hiding the implementation of internal details and only showcasing the funtionalities to the users. In Java, the 100 percent abstraction is achieved by interfaces and abstract classes.

Example of implemenation of Abstraction in Selenium:

Page Object Model(POM) design pattern - In POM designs, the locators like xpaths, id , name etc and methods are written in the page class.This key values from this page classes are then used for the implemenation of methods and utilization of the locators in other java classes.This design pattern clearly uses the concept of abstraction in hiding the details like the locator paths and the method implemenation while utilising thise locators and methods in other classes without showing the internal details.

Interface

In simple terms, inetrface is a list of variables and methods that you utilise to make a class in a way of x implements y.Interface is similar to class but the concept is different.The methods declared in the interface are by deafult abstract.

Example of implementation of Interface in Selenium:

Webdriver and Webelements - Webdriver is an interface used to launch different browsers such as firefox, chrome,safari etc.Whereas, webelement is an interface used to identify the elements in a web page.

Webdriver driver = bew Firefoxdriver(); where:

driver is the reference variable pointing to the interface and creating an object.

Firefoxdriver() is the object created.

Inheritance

The mechanism in Java where the properties and the functionalities of one class is inherited or acquired by another class.The main objective of inheritance is code reusability.A child or the derived class inherits the properties of the base or the parent class.The keywords 'extends' and 'implements' to use the concept of inheritance in Java.

Example of implementation of Inheritance in Selenium:

Usually in automation framework, there is a Base class to initialize the webdriver interface, waits, property files ,excels etc.This is extended to other tests and utility which implements the concept of inheritance.

Polymorphism

Polymorphism is the concept in Java which allows to perform a task in multiple ways. It is a combination of method overloading and method overriding.

Method overloading : A class having multiple methods with the same name but different parameters is called methods overloading.

Example of implementation of Method overloading in Selenium:

Implicit wait, assert classes are the examples of method overloading which we use in Selenium.

The format of the implicit wait can be written as:

driver.manage().timeouts().implicitlyWait()(10,TimeUnit.SECONDS);

This timestamp can be seconds, minutes or hours where the webdriver implicitly wait for a particular element to appear in a web page.

Method overriding : Declaring a method in the child class which is already present in the parent class is called method overriding.

Example of implementation of Method overriding in Selenium:

get() and navigate() methods of different drivers are perfect examples of method overriding in Selenium where we use these methods in different classes irrespective of their number of occurences.

Encapsulation

Encapsulation is the mechanism of binding the code and the data(variables) into a single unit.

Example of implementation of Encapsulation in Selenium:

All the classes in a framework are example of encapsulation.Also. the POM(Page Object Model) classes where the data members are declared by @FindBy and the initialization of the same will be done using the constructors to utilize those datas in the methods.

In conclusion, the Object-Oriented Programming (OOP) concepts in Java—abstraction, inheritance, interface, polymorphism, and encapsulation—are fundamental in creating robust and efficient software applications. These concepts are seamlessly integrated into Selenium, enhancing its functionality and making it a powerful tool for automation testing.These OOP principles not only enhance code readability and maintainability but also ensure efficient and scalable test automation frameworks in Selenium.

要查看或添加评论,请登录

Bina Sheela Kumar的更多文章

  • WEB TABLES IN SELENIUM

    WEB TABLES IN SELENIUM

    Web tables serve as the structured presentation of data within web pages, exemplified by product specifications or…

社区洞察

其他会员也浏览了