top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-

JAVA OOPS Concepts - Implementation of OOPS concept In SELENIUM FRAMEWORK - Part 2

In this part of the blog, we try to understand the meaning of a frame work and implementation of OOPS concepts in our project . Hope, this will enable you to answer some of the questions in the interviews.


What is a Framework?

A framework defines a set of rules or best practices that we can follow in a systematic way to achieve the desired results. So in the Our Projects like DS-Algo, MissonHumane etc test automation frameworks deal with best practices to achieve the goals of our automation project.


What is Selenium Framework?

Selenium is an automation testing suite for web applications across different browsers and platforms. Selenium Webdriver is the most popular opensource automation tool essential used for functional testing in browsers. Selenium framework’s code structure helps you to reuse the code, reduce code maintenance, higher code readability, and allows multiple users to work on the same piece of the program. It s an integration of various tools like MAVEN for build, TestNG and Junit for unit and integration testing, Cucumber for BDD, Rest Assured for webservices, JAVA or python as programming Language and various reporting tools to complete Automation


Why do we need the Selenium Framework?

  • Easy code maintenance

  • Increase in code re-usage

  • Automated Testing is more reliable

  • Easy for compatibility testing. It enables parallel execution in combination of different OS and browser environments

  • Higher code readability

  • It is mostly used for regression testing. Supports execution of repeated test cases

  • Reduced script maintenance cost

  • Reduced tests’ time execution

  • Reduced human resources

  • Easy reporting



Page object Design Pattern

In Selenium, we call objects as locators (such as ID, Name, Class Name, Tag Name, Link Text, Partial Link Text, XPath, and CSS). Object repository is a collection of objects. One of the ways to create Object Repository is to place all the locators in a separate file (i.e., properties or a PageObject file). But the best way is to use Page Object Model. In the Page Object Model Design Pattern, each web page is represented as a class. All the objects related to a particular page of a web application are stored in a class.













1. 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.

Example : Login function of LMS portal

A page Class “LoginPage” was created to store all the objects or locators of LoginPage Module .All functions performed on the UI of Login page are stored as methods in the same Page.





Step Definitions in Login page

Here the loginpage is the object of LoginPage class and the methods are directly called. Abstraction achieved as code and locator details are hidden






2. INTERFACE

WebDriver is an Interface.


WebDriver driver = new ChromeDriver();


Here, we are initializing Chrome browser using Selenium WebDriver. It means we are creating a reference variable (driver) of the interface (WebDriver) and creating an Object. Here WebDriver is an Interface as mentioned earlier and Chromedriver is a class.









3. INHERITANCE

The mechanism in Java 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, Property files, Excels, etc., in the Base Class. We extend the Base Class in other classes such Tests and Utility Class.




4. POLYMORPHISM


Polymorphism allows us to perform a task in multiple ways.


METHOD OVERLOADING

We use Implicit wait in Selenium. 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 same name but different parameters is called Method Overloading




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.

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.


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 ode and data (variables) together in a single unit.





Thanks for reading !

764 views0 comments

Recent Posts

See All
bottom of page