0% found this document useful (0 votes)
11 views5 pages

Bank Guru

The document contains Java code defining user interface elements and page objects for a web application using Selenium. It includes classes for various pages such as Login, New Customer, Edit Customer, and New Account, each with specific UI elements defined using XPath. The code also includes methods for interacting with these elements, such as entering text, clicking buttons, and retrieving information from the UI.

Uploaded by

tannv.ytcvn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Bank Guru

The document contains Java code defining user interface elements and page objects for a web application using Selenium. It includes classes for various pages such as Login, New Customer, Edit Customer, and New Account, each with specific UI elements defined using XPath. The code also includes methods for interacting with these elements, such as entering text, clicking buttons, and retrieving information from the UI.

Uploaded by

tannv.ytcvn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

package pageUI.

User;

public class BaseUI {


public static final String REGISTER_URL = "xpath=//span[text()='Steps To
Generate Access']/parent::h4/following-sibling::div//a[text()='here']";
public static final String LEFT_MENU_ITEM_BY_TEXT =
"xpath=//ul[@class='menusubnav']//a[text()='%s']";
public static final String DYNAMIC_TEXTBOX_BY_LABEL =
"xpath=//td[text()='%s']/following-sibling::td//input";
public static final String SUBMIT_BUTTON = "xpath=//input[@value='Submit']";
public static final String GOOGLE_IFRAME =
"xpath=//iframe[contains(@id,'google_ads_iframe')]";
public static final String CLOSE_IFRAME = "xpath=//div[@id='dismiss-
button']";
}

package pageUI.User;

public class EditCustomerPageUI {


public static final String CUSTOMER_ID_TEXTBOX = "xpath=//td[text()='Customer
ID']//following-sibling::td/input";
public static final String ADDRESS_TEXTAREA =
"xpath=//td[text()='Address']/following-sibling::td//textarea";
public static final String TITLE_PAGE = "xpath=//p[text()='Edit Customer']";
}

package pageUI.User;

public class LoginPageUI {


public static final String USER_ID_TEXTBOX = "xpath=//input[@name='uid']";
public static final String PASSWORD_TEXTBOX =
"xpath=//input[@name='password']";
public static final String LOGIN_BUTTON = "xpath=//input[@name='btnLogin']";
}

package pageUI.User;

public class NewAccountPageUI {


public static final String TITLE_PAGE = "xpath=//p[text()='Add new account
form']";
public static final String ACCOUNT_TYPE_DEFAULT_DROPDOW ="xpath=//td[text()='
Account type']//following-sibling::td/select";
}

package pageUI.User;

public class NewCustomerPageUI {


public static final String ADDRESS_TEXTAREA =
"xpath=//td[text()='Address']/following-sibling::td//textarea";
public static final String SUBMIT_BUTTON = "xpath=//input[@value='Submit']";
public static final String SUCCESS_MESSAGE =
"xpath=//table[@id='regmsg']//p[@class='heading3']";
public static final String DYNAMIC_CUSTOMER_INFO =
"xpath=//td[text()='%s']//following-sibling::td";
}
package PageObjects;

import org.openqa.selenium.WebDriver;

import commons.BasePage;
import pageUI.User.NewCustomerPageUI;

public class NewCustomerPageObject extends BasePage {


private WebDriver driver;

public NewCustomerPageObject(WebDriver driver) {


super(driver);
this.driver = driver;
}

public void enterToAddressTextarea(String value) {


waitForElementVisible(NewCustomerPageUI.ADDRESS_TEXTAREA);
sendkeyToElement(NewCustomerPageUI.ADDRESS_TEXTAREA, value);
}

public String getTextSuccessMessage() {


waitForElementVisible(NewCustomerPageUI.SUCCESS_MESSAGE);
return getTextElement(NewCustomerPageUI.SUCCESS_MESSAGE);
}

public String getTextCustomerInfoByLabel(String label) {


waitForElementVisible(NewCustomerPageUI.DYNAMIC_CUSTOMER_INFO, label);
return getTextElement(NewCustomerPageUI.DYNAMIC_CUSTOMER_INFO, label);
}

}
package PageObjects;

import org.openqa.selenium.WebDriver;

import commons.BasePage;
import pageUI.User.NewAccountPageUI;

public class NewAccountPageObject extends BasePage {


private WebDriver driver;

public NewAccountPageObject(WebDriver driver) {


super(driver);
this.driver = driver;
}

public boolean isAddNewAccountTitlePageDisplayed() {


waitForElementVisible(NewAccountPageUI.TITLE_PAGE);
return isElementDisplayed(NewAccountPageUI.TITLE_PAGE);
}

public void selectItemInAccountTypeDropdown(String expectedValue) {


waitForElementVisible(NewAccountPageUI.ACCOUNT_TYPE_DEFAULT_DROPDOW);

selectItemInDefautDropdown(NewAccountPageUI.ACCOUNT_TYPE_DEFAULT_DROPDOW,
expectedValue);
}

}
package PageObjects;

import org.openqa.selenium.WebDriver;

import commons.BasePage;
import commons.PageGeneralManager;
import pageUI.User.BaseUI;
import pageUI.User.LoginPageUI;

public class LoginPageObject extends BasePage {


private WebDriver driver;

public LoginPageObject(WebDriver driver) {


super(driver);
this.driver = driver;
}

public RegisterPageObject clickToVisitUrl() {


waitForElementClickable(BaseUI.REGISTER_URL);
clickToElement(BaseUI.REGISTER_URL);
return PageGeneralManager.getRegisterPageObject(driver);
}

public void enterToUserIdTextbox(String value) {


waitForElementVisible(LoginPageUI.USER_ID_TEXTBOX);
sendkeyToElement(LoginPageUI.USER_ID_TEXTBOX, value);
}

public void enterToPasswordTextbox(String value) {


waitForElementVisible(LoginPageUI.PASSWORD_TEXTBOX);
sendkeyToElement(LoginPageUI.PASSWORD_TEXTBOX, value);

public DashboardPageObject clickToLoginButton() {


waitForElementClickable(LoginPageUI.LOGIN_BUTTON);
clickToElement(LoginPageUI.LOGIN_BUTTON);
return PageGeneralManager.getDashboardPageObject(driver);
}

}
package PageObjects;

import org.openqa.selenium.WebDriver;

import commons.BasePage;
import pageUI.User.BaseUI;
import pageUI.User.EditCustomerPageUI;
import pageUI.User.NewCustomerPageUI;

public class EditCustomerPageObject extends BasePage{

private WebDriver driver;

public EditCustomerPageObject(WebDriver driver) {


super(driver);
this.driver = driver;
}
public void enterToCustomerIDTextbox(String customID) {
waitForElementVisible(EditCustomerPageUI.CUSTOMER_ID_TEXTBOX);
sendkeyToElement(EditCustomerPageUI.CUSTOMER_ID_TEXTBOX, customID);
}

public boolean isEditCustomerTitlePageDisplayed() {


waitForElementVisible(EditCustomerPageUI.TITLE_PAGE);
return isElementDisplayed(EditCustomerPageUI.TITLE_PAGE);
}

public void turnOffAlert() {


waitAlertPresence();
acceptAlert();
}

public void enterToAddressTextarea(String value) {


waitForElementVisible(EditCustomerPageUI.ADDRESS_TEXTAREA);
sendkeyToElement(EditCustomerPageUI.ADDRESS_TEXTAREA, value);
}

public String getTextCustomerInfoByLabel(String label) {


waitForElementVisible(NewCustomerPageUI.DYNAMIC_CUSTOMER_INFO, label);
return getTextElement(NewCustomerPageUI.DYNAMIC_CUSTOMER_INFO, label);
}

public String getAttributeValueByLabel(String label) {


waitForElementVisible(BaseUI.DYNAMIC_TEXTBOX_BY_LABEL,label);
return getAttributeValue(BaseUI.DYNAMIC_TEXTBOX_BY_LABEL, "value",
label);
}

public String getTextTextarea() {


waitForElementVisible(EditCustomerPageUI.ADDRESS_TEXTAREA);
return getTextElement(EditCustomerPageUI.ADDRESS_TEXTAREA);
}

}
package PageObjects;

import org.openqa.selenium.WebDriver;

import commons.BasePage;
import commons.PageGeneralManager;
import pageUI.User.BaseUI;

public class DashboardPageObject extends BasePage {

private WebDriver driver;

public DashboardPageObject(WebDriver driver) {


super(driver);
this.driver = driver;
}

package commons;
import java.io.File;

public class GlobalConstants {


public static final int LONG_TIME = 15;
public static final int SHORT_TIME = 5;
public static final String PROJECT_PATH = System.getProperty("user.dir");
public static final String FILE_UPLOAD_PATH= PROJECT_PATH + File.separator +
"upload" + File.separator;
public static final String USER_ID = "mngr502739";
public static final String USER_PASSWORD = "tudYzAb";
}

public BasePage openLeftMenuItemByPageName(String pageName) {


waitForElementClickable(BaseUI.LEFT_MENU_ITEM_BY_TEXT,pageName);
clickToElement(BaseUI.LEFT_MENU_ITEM_BY_TEXT, pageName);
switch (pageName) {
case "New Customer":
return PageGeneralManager.getNewCustomerPageObject(driver);
case "Edit Customer":
return PageGeneralManager.getEditCustomerPageObject(driver);
case "New Account":
if (isElementDisplayed(BaseUI.GOOGLE_IFRAME) == true) {
waitForAllELementsVisible(BaseUI.GOOGLE_IFRAME);
swtichToFrameIframe(BaseUI.GOOGLE_IFRAME);
waitForElementClickable(BaseUI.CLOSE_IFRAME);
clickToElement(BaseUI.CLOSE_IFRAME);
switchToDefautContent();
}
return PageGeneralManager.getNewAccountPageObject(driver);
default:
throw new RuntimeException(pageName + " is not exit");
}
}

public void enterToTextboxByLabel(String label, String value) {


waitForElementVisible(BaseUI.DYNAMIC_TEXTBOX_BY_LABEL, label);
sendkeyToElement(BaseUI.DYNAMIC_TEXTBOX_BY_LABEL, value, label);
}

public void clickToSubmitButton() {


waitForElementClickable(BaseUI.SUBMIT_BUTTON);
clickToElement(BaseUI.SUBMIT_BUTTON);
}

You might also like