Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.org.opi.jsa.ui.pages;
- import org.openqa.selenium.*;
- import org.openqa.selenium.support.ui.ExpectedConditions;
- import org.openqa.selenium.support.ui.FluentWait;
- import pl.org.opi.jsa.ui.Config.ConfigProfiles;
- import pl.org.opi.jsa.ui.pages.commons.DialogWindow;
- import pl.org.opi.jsa.ui.user.User;
- import pl.org.opi.jsa.ui.excepctions.AuthorizationException;
- import pl.org.opi.utils.selenium.*;
- import java.io.File;
- import java.time.Duration;
- import java.util.concurrent.TimeUnit;
- import java.util.concurrent.atomic.AtomicReference;
- @SuppressWarnings("unchecked")
- public class MainPage extends Page {
- static final By BROKER_ALERT_MESSAGE = By.xpath("//*[@test-broker-message]");
- static final By CLOSE_BROKER_ALERT_BAR = By.xpath("//*[@test-close-broker-bar]");
- static final By CLOSE_COOKIE_BAR = By.xpath("//*[@test-close-cookie-bar]");
- static final By LOGGED_USER = By.xpath("//*[@test-login-user]");
- static final By LOG_OUT_BUTTON = By.xpath("//*[@test-logout-btn]");
- private static final By POLON_LOGIN_BUTTON = By.xpath("//*[@test-polon-login-btn]");
- private static final By LOGIN_INPUT = By.xpath("//*[@test-login-input]");
- private static final By PASSWORD_INPUT = By.xpath("//*[@test-password-input]");
- private static final By LOGIN_BUTTON = By.xpath("//*[@test-login-button]");
- private static final By LOGIN_CONTEXT = By.xpath("//*[@test-choice-context]");
- private static final String LOGIN_CONTEXT_VALUE = "//*[@test-choice-context-value]//span[contains(text(),'%s')]";
- private static final By LOGIN_CONTEXT_SUBMIT_BUTTON = By.xpath("//*[@test-choice-context-btn]");
- private static final By ACCEPT_REGULATION_BUTTON = By.xpath("//*[@test-accept-regulation-btn]");
- private static final By CONTEXT_LIST = By.xpath("//*[@test-context-list]");
- private static final By CURRENT_CONTEXT = By.xpath("//*[@test-context-value]");
- private static final By LOGIN_ERROR_MESSAGE = By.xpath("//*[@test-login-error]");
- private By PERSON = By.xpath("//*[@test-choice-person]");
- private static final String PERSON_VALUE = "//*[@test-choice-person-value]//span[contains(text(),'%s')]";
- //////////TO DO !!!!!!!!!!!!!////////////////////////////////
- static final By JSA_LOGO = By.xpath("//img[@alt='Logo - Jednolity System Antyplagiatowy']");
- static final By HOME_BUTTON = By.xpath("//*[@class='jsa__navbar__menu']//a[@href='/home']");
- static final By NEWS_BUTTON = By.xpath("//div[@class='jsa__navbar__menu']//a[@href='/news']");
- static final By HELP_CENTER_BUTTON = By.xpath("//div[@id='generalnavbar']//a[@href='/help-center']");
- static final By HELP_CENTER_FAQ = By.xpath("");
- static final By HELP_CENTER_KNOWLEDGE = By.xpath("");
- static final By HELP_CENTER_HEPL = By.xpath("");
- static final By USER_PANEL_MENU = By.xpath("//*[@test-user-panel-menu-btn]");
- static final By USER_PANEL_USERS = By.xpath("//*[@test-users-panel]");
- static final By USER_PANEL_PERMISSIONS = By.xpath("//*[@test-users-permissions]");
- static final By USER_PANEL_CONTRACTS = By.xpath("//*[@test-users-contracts]");
- static final By USER_PANEL_REPORTS = By.xpath("//*[@test-users-reports]");
- static final By USER_PANEL_SETTINGS = By.xpath("//*[@test-users-settings]");
- static final By USER_PANEL_PROFILE = By.xpath("//*[@test-users-profiles]");
- //STRONA USTAWIENIA HASŁA PO PO RAZ PIERWSZY
- static final By SAVE_PASSWORD_BUTTON = By.xpath("//*[@test-save-button]");
- static final By NEW_PASSWORD = By.xpath("//*[@test-password]");
- static final By REPEAT_NEW_PASSWORD = By.xpath("//*[@test-repeat-password]");
- static final By NEW_USERNAME = By.xpath("//*[@test-username]");
- //STRONA PRZYPOMNIJ HASŁO
- static final By REMINDER_PASSWORD = By.xpath("//*[@test-remind-password]");
- static final By EMAIL_INPUT_REMINDER_PASSWORD = By.xpath("//*[@test-remind-password]");
- static final By SPINNER = By.xpath("//*[@test-spinner]");
- MainPage(TestProfile testProfile, Browser browser, AtomicReference<Page> reference) {
- super(ConfigProfiles.getString("test.url"), testProfile, browser, reference);
- }
- MainPage(WebDriver webDriver, TestProfile testProfile, Browser browser, AtomicReference<Page> reference) {
- super(webDriver, testProfile, browser, reference);
- }
- public static MainPage newInstance(TestProfile testProfile, Browser browser, AtomicReference<Page> reference) {
- return new MainPage(testProfile, browser, reference);
- }
- public static MainPage instance(WebDriver webDriver, TestProfile testProfile, Browser browser, AtomicReference<Page> reference) {
- MainPage instance = SeleniumObject.get(webDriver, MainPage.class);
- return instance != null ? instance : new MainPage(webDriver, testProfile, browser, reference);
- }
- protected void waitForPageLoad() {
- sleep(1000);
- wait.forJS();
- }
- public <T extends MainPage> T closeCookiebar() {
- perform.click(CLOSE_COOKIE_BAR);
- wait.forInvisibility(CLOSE_COOKIE_BAR);
- return (T) this;
- }
- public ContractsPage login(User user) {
- fillLoginAndPassword(user);
- clickLoginButton();
- selectContext(user);
- return ContractsPage.instance(webDriver, testProfile, browser, reference);
- }
- public ContractsPage loginPolon(User user) {
- perform.click(POLON_LOGIN_BUTTON);
- fillLoginAndPassword(user);
- clickLoginButton();
- return ContractsPage.instance(webDriver, testProfile, browser, reference);
- }
- public ContractsPage loginHD(User userHD, String person) {
- fillLoginAndPassword(userHD);
- clickLoginButton();
- selectContext(userHD);
- perform.clearAndSendKeys(PERSON, person);
- perform.click(By.xpath(String.format(PERSON_VALUE, person)));
- clickLoginContextButton();
- return ContractsPage.instance(webDriver, testProfile, browser, reference);
- }
- private void fillLoginAndPassword(User user) {
- waitForPageLoad();
- perform.clearAndSendKeys(LOGIN_INPUT, user.getLogin());
- perform.clearAndSendKeys(PASSWORD_INPUT, user.getPassword());
- }
- private void clickLoginButton() {
- perform.click(LOGIN_BUTTON);
- waitForPageLoad();
- }
- private void clickLoginContextButton() {
- perform.click(LOGIN_CONTEXT_SUBMIT_BUTTON);
- waitForPageLoad();
- }
- private void selectContext(User user) {
- waitForPageLoad();
- if (is.present(LOGIN_CONTEXT_SUBMIT_BUTTON)) {
- perform.click(LOGIN_CONTEXT);
- perform.click(By.xpath(String.format(LOGIN_CONTEXT_VALUE, user.getContext())));
- perform.click(LOGIN_CONTEXT_SUBMIT_BUTTON);
- waitForPageLoad();
- }
- acceptRegulation();
- }
- private void acceptRegulation() {
- if (is.visible(ACCEPT_REGULATION_BUTTON)) {
- perform.click(ACCEPT_REGULATION_BUTTON);
- }
- }
- public boolean isLoggedIn() {
- wait.forVisibility(LOG_OUT_BUTTON);
- boolean isLogged = is.visible(LOGGED_USER);
- if (isLogged) {
- return true;
- } else {
- throw new AuthorizationException("Only logged in user has access to this page.");
- }
- }
- public MainPage logout() {
- if (!isLoggedIn()) throw new AuthorizationException("Only logged in user can log out.");
- perform.click(LOG_OUT_BUTTON);
- return MainPage.instance(webDriver, testProfile, browser, reference);
- }
- public UsersPage goToUsersPage() {
- isLoggedIn();
- wait.forVisibility(USER_PANEL_USERS);
- perform.click(USER_PANEL_USERS);
- return UsersPage.instance(webDriver, testProfile, browser, reference);
- }
- public PermissionsPage goToPermissionsPage() {
- isLoggedIn();
- perform.click(USER_PANEL_PERMISSIONS);
- return PermissionsPage.instance(webDriver, testProfile, browser, reference);
- }
- public ContractsPage goToContractsPage() {
- isLoggedIn();
- perform.click(USER_PANEL_CONTRACTS);
- return ContractsPage.instance(webDriver, testProfile, browser, reference);
- }
- public SettingsPage goToSettingsPage() {
- isLoggedIn();
- perform.click(USER_PANEL_SETTINGS);
- return SettingsPage.instance(webDriver, testProfile, browser, reference);
- }
- public ProfilePage goToProfilePage() {
- isLoggedIn();
- perform.click(USER_PANEL_PROFILE);
- return ProfilePage.instance(webDriver, testProfile, browser, reference);
- }
- public ProfilePage goTo() {
- // perform.click();
- return ProfilePage.instance(webDriver, testProfile, browser, reference);
- }
- void sleep(int millis) {
- try {
- Thread.sleep(millis);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- void waitForSpinner() {
- sleep(1500);
- }
- public String getDialogMessage() {
- return new DialogWindow(webDriver).getDialogMessage();
- }
- public String getLoginErrorMessage() {
- return get.text(LOGIN_ERROR_MESSAGE);
- }
- public <T extends MainPage> T clickDialogOK() {
- new DialogWindow(webDriver).clickDialogOK();
- waitForPageLoad();
- return (T) this;
- }
- public boolean isDialogSuccess() {
- return new DialogWindow(webDriver).isDialogSuccess();
- }
- public boolean isDaialogUnsuccess() {
- return new DialogWindow(webDriver).isDaialogUnsuccess();
- }
- public void clickBackButtonDialog() {
- new DialogWindow(webDriver).clickBackButtonDialog();
- }
- public String getCurrentURL() {
- return webDriver.getCurrentUrl();
- }
- public MainPage setPassword(User user) {
- user.setLogin(get.value(NEW_USERNAME));
- System.out.println(get.text(NEW_USERNAME));
- perform.clearAndSendKeys(NEW_PASSWORD, user.getPassword());
- perform.clearAndSendKeys(REPEAT_NEW_PASSWORD, user.getPassword());
- perform.click(SAVE_PASSWORD_BUTTON);
- new DialogWindow(webDriver).clickDialogOK();
- return MainPage.instance(webDriver, testProfile, browser, reference);
- }
- public MainPage reminderPassword(String email) {
- String[] emailName = email.split("@");
- String emailMessage = "https://preview.putsbox.com/p/" + emailName[0] + "/last";
- perform.click(REMINDER_PASSWORD);
- perform.clearAndSendKeys(EMAIL_INPUT_REMINDER_PASSWORD,emailName[0]);
- new DialogWindow(webDriver).clickDialogOK();
- return MainPage.instance(webDriver, testProfile, browser, reference);
- }
- @Override
- protected void beforeQuit() {
- if (isLoggedIn()) logout();
- }
- public void waitForFile(long timeout, File file) {
- wait.forAny(timeout, webDriver -> file.exists());
- }
- }
Add Comment
Please, Sign In to add comment