So In this blog, we will discuss how and where we have actually applied the below OOPs concepts in our Automation Framework.
- METHOD OVERLOADING
- METHOD OVERRIDING
Java Object Oriented Concepts in Selenium Automation Framework
An interface in the Java programming language is an abstract type that is used to specify a behavior that classes must implement. An interface also contains methods and variables just like the class but the methods declared in the interface are by default abstract.
To understand this the very basic statement we write in Selenium
WebDriver driver = new Chromedriver();
In this case, WebDriver itself is an Interface. So based on this statement, WebDriver driver = new Chromedriver(); 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.
As we are aware, Abstraction is a process of hiding the implementation details from the user and showing only relevant details to them. It also helps to reduce programming complexity and effort.
In our Automation Framework whenever we Use the Page object Model, we write all the locators in the page class and use this locator in our test it means we are hiding our implementation from the user this is a simple example of using abstraction in the framework.
The process by which one class acquires the properties (instance variables) and functionalities of another class are called inheritance.
When We create a Base Class in our automation Framework to initialize WebDriver interface, waits, loggers, reports, etc., and when we extend this Base Class in other classes such as Tests and Utility Class. In this case, extending one class into another class is an example of implementing Inheritance.
Encapsulation is a mechanism of wrapping data (variables) and code together as a single unit. All the classes which we write in our automation framework are an example of Encapsulation.
For e.g In Page object model classes, in which we declare the WebElement locator using @FindBy and initialization of this data members will be done using Constructor to utilize those in test methods.
Polymorphism means having many forms. Polymorphism allows us to perform a single action in different ways. In Java polymorphism can be achieved in two ways:
If a class has multiple methods having the same name but different in parameters, it is known as Method Overloading.
In Implicit wait when we use different time stamps such as SECONDS, MINUTES, HOURS, etc is one of the possible examples of method overloading.
If the subclass or child class has the same method as declared in the parent class, it is known as method overriding in Java.
Whenever we use a method that was already implemented/written in another class by changing its parameters this is the example of method overriding.
Explore more blogs on Development, Testing and DevOps follow the link
10+ years of Diversified experience in Information and communications technology (ICT), specializing in Solution Architect, Software Quality Assurance with proficiency in deployment and development, testing on Client/Server and Web-based applications.
- Working knowledge in Java8, AWS, GCP, Junit, Mockito, Cobertura, Findbugs, Sonarqube, PMD.
- Experience in CI/CD using Azure DevOps, Jenkins Pipeline, Github, Nexus, Docker, Kubernetes.
- Experience in fixing security vulnerability issues using Checkmarx code scanner.
- Proficient in writing the automation scripts using TestNG, Cucumber, Silk4j
- Conduct performance test using Silk Performer, Jmeter and SoapUI
- Experience in finding and fixing JVM memory leak issue using Jmeter, VisualVm.
- Very good team player with the ability to work in a fast-paced agile development environment as well as an individual contributor.