Member-only story
How Object Oriented Programming works in Test Automation Frameworks?
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 the 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.
In Java, abstraction is achieved by interfaces and abstract classes. Using interfaces, we can achieve 100% abstraction.
Example:
//Abstract class
// Abstract Page class
public abstract class Page {
protected WebDriver driver;
public Page(WebDriver driver) {
this.driver = driver;
}
// Abstract method to be implemented by child classes
public abstract WebElement getElement(By locator);
// Abstract method to be implemented by child classes