0% found this document useful (0 votes)
3 views

Java Abstract

Uploaded by

pdosi87
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Java Abstract

Uploaded by

pdosi87
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Abstract class:

---------------
Abstraction is the process of hiding implementation details and showing only
functionality to the user. Abstraction in Java can be achieved using
- Abstract class
- Interface

Abstract class cannot be instantiated, which means object of an abstract class


cannot be created
It can have abstract and non-abstract methods - It is not necessary for abstract
class to mandatorily have abstract methods
If an abstract class has abstract method then the class extending the abstract
class must implement the abstract method
It can have constructor and static methods
It can have final methods as well

I have created my BasePage class as abstract in Page Object Model and all the page
classes extend the BasePage class

Also, I achieved abstraction in my automation suite using Page Object Model.


I created one class for every page/every segment of the application - Which I refer
it as Page class.
Within each page class, I declared locator of that page/segment and made it private
such that those locators can be used only within that Page.
Within each page class, I create one method for every action/business functionality
that can be performed on that respective page/segment.
This way all the locators and business functionality are implemented only within
their respective page class.
The test classes or step definition classes who will be calling these methods can
call them but won't have to worry about their implementation.

Example:
public abstract class BasePage{

WebDriver driver;

public void enterData(WebElement element, String data){


//Code to enter 'data' into the 'element'
}

public void click(WebElement element){


//Code to click on 'element'
}

public void selectDropdown(WebElement element, String data){


//Code to select the 'data' from 'element' dropdown
}

public void naviagte(String sUrl){


driver.get(sUrl);
}

public String readText(WebElement element){


String message = //Code to read the message from 'element'
retrurn message;
}

}
Login Page - LoginPage.java

public class LoginPage extends BasePage{

private final By byUserIdTextbox = By.id("logonIdentifier");


private final By byPasswordTextbox = By.id("password");
private final By bySignInButton = By.id("next");
private final By byForgotPasswordLink = By.id("forgotPassword");
private final By bySignUpLink = By.id("createAccount");

public LoginPage(WebDriver wDriver){


driver = wDriver;
}

public LoginPage goToLoginPage(){


navigate("https://lowes.ca");
return this;
}

public HomePage login(String userId, Sting password){


enterData(USREID_TEXTBOX, userId);
enterData(PASSWORD_TEXTBOX, password);
//Code here to accomodate changes
click(LOGIN_BUTTON);
return new HomePage(driver);
}

public HomePage login(Sting password){


enterData(PASSWORD_TEXTBOX, password);
click(LOGIN_BUTTON);
return new HomePage(driver);
}

public ForgotPasswordPage goToForgotPasswordPage(){


click(FORGOTPASSWORD_LINK);
return new ForgotPasswordPage(driver);
}

public SignUpPage goToSignUpPage(){


click(SIGNUPPAGE_LINK);
return new SignUpPage(driver);
}

public String getErrorMessage(){


String sErrorMessaage = readText(ERRORMESSAGE_LABEL);
return sErrorMessaage;
}

Example:
public abstract class BasePage {

public abstract void openBrowser();

public void click() {


//Some code which will click on the required button
}

public void enterText(String sData) {


//Some code which will enter sData into the required textbox
System.out.println("Entering data - " + sData);
}

public class LoginPage extends BasePage{

public void Login(String sUserId, String sPassword) {


enterText(sUserId);
enterText(sPassword);
click();
}

public void openBrowser(){


//Code to implement openBrowser
}

You might also like