import logging from contextlib import suppress import allure from ui_automation_framework.utils import CoreConfig from ui_automation_framework.utils import logger as cl from waiting import TimeoutExpired, ALL from src.pages.navigation_page import NavigationPage from src.helpers.waiting_wrapper import wait from src.ui_elements.button_ui_element import ButtonUIElement from src.ui_elements.input_ui_element import InputUIElement from src.ui_elements.label_ui_element import LabelUIElement from src.locators.login_locators import LoginLocators class LoginPage(NavigationPage): log = cl.Logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver @property def lb_logo(self): return LabelUIElement(self.driver, LoginLocators.LOGO_IMG, "Logo") @property def bn_rti_log_in(self): return ButtonUIElement(self.driver, LoginLocators.LOIN_IN_RTI_BTN[CoreConfig.LANG], "Log in splash") @property def in_email(self): return InputUIElement(self.driver, LoginLocators.EMAIL_FIELD, "Email") @property def in_password(self): return InputUIElement(self.driver, LoginLocators.PASSWORD_FIELD, "Password") @property def bn_login(self): return ButtonUIElement(self.driver, LoginLocators.LOGIN_BTN, "Login button") @property def bn_forgot_password(self): return ButtonUIElement(self.driver, LoginLocators.FORGOT_PW_LINK, "Forgot password") @property def lb_wrong_creds(self): return LabelUIElement(self.driver, LoginLocators.WRONG_CREDS_MSG, "Label wrong credentials") @property def lb_email_error(self): return LabelUIElement(self.driver, LoginLocators.INVALID_EMAIL_MSG, "Email error placeholder") @property def lb_email_blank_error(self): return LabelUIElement(self.driver, LoginLocators.BLANK_EMAIL_MSG, "Blank error popup") @property def lb_password_blank_error(self): return LabelUIElement(self.driver, LoginLocators.BLANK_PW_MSG, "Blank password error") @property def lb_forgot_password(self): return LabelUIElement(self.driver, LoginLocators.FORGOT_PW_MSG, "Forgot password") @property def lb_send_password(self): return LabelUIElement(self.driver, LoginLocators.FORGOT_PW_LINK, "Send password") @property def lb_reset_password(self): return LabelUIElement(self.driver, LoginLocators.RESET_PW_LB, "Reset your password") @property def lb_login_text(self): return LabelUIElement(self.driver, LoginLocators.LOGIN_LB, "Login to your account.") def login(self, email, password): # self.lb_logo.wait(to_assert=False) self.bn_rti_log_in.click() self.in_email.wait(timeout=120, to_assert=False) self.in_email.click() self.in_email.send_text(email) self.in_password.send_password(password) self.click_to_hide_keyboard() self.bn_login.click() return self @allure.step("Navigating to the login form") def go_to_login_form(self): # self.lb_logo.wait(to_assert=False) self.bn_rti_log_in.click() self.in_email.wait() return self def enter_login_credentials(self, email, password): self.in_email.click() self.in_email.clear_text() # hack for not fully cleared email field due to @ char self.in_email.clear_text() self.in_email.send_text(email) self.in_password.click() self.in_password.clear_text() self.in_password.send_password(password) self.click_to_hide_keyboard() return self @allure.step("Clicking login button") def click_login(self): self.bn_login.click() return self @allure.step("Clicking forgot password button") def click_forgot_password(self): self.bn_forgot_password.click() return self def is_wrong_credentials_error_message_shown(self): with suppress(TimeoutExpired): return wait(self.lb_wrong_creds.is_visible) return False def are_empty_credentials_error_messages_shown(self): with suppress(TimeoutExpired): return wait(ALL([self.lb_email_blank_error.is_visible, self.lb_password_blank_error.is_visible])) return False def is_invalid_email_error_message_shown(self): with suppress(TimeoutExpired): return wait(self.lb_email_error.is_visible) return False def is_invalid_email_error_message_hidden(self): return not self.lb_email_error.is_visible() def are_forgot_password_messages_shown(self): with suppress(TimeoutExpired): return wait(ALL([self.lb_forgot_password.is_visible, self.lb_reset_password.is_visible])) return False def is_login_page_opened(self): with suppress(TimeoutExpired): return wait(self.bn_rti_log_in.is_visible) return False @allure.step("Login as Single User") def login_as_single_user(self): login = CoreConfig.SINGLEUSER_EMAIL password = CoreConfig.SUPERUSER_PASSWORD self.login(login, password) return self @allure.step("Login as Super User") def login_as_super_user(self): login = CoreConfig.SUPERUSER_EMAIL password = CoreConfig.SUPERUSER_PASSWORD self.login(login, password) return self