import logging from contextlib import suppress import allure from ui_automation_framework.utils import logger as cl from ui_automation_framework.core.base_page import BasePage from waiting import TimeoutExpired 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.navigation_locators import NavigationLocators class NavigationPage(BasePage): log = cl.Logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver @property def bn_library_tab(self): return ButtonUIElement(self.driver, NavigationLocators.LIBRARY_TAB_BTN, "Library tab") @property def bn_artist_tab(self): return ButtonUIElement(self.driver, NavigationLocators.ARTIST_TAB_BTN, "Artist tab") @property def bn_globe_tab(self): return ButtonUIElement(self.driver, NavigationLocators.GLOBE_TAB_BTN, "Globe tab") @property def bn_settings_tab(self): return ButtonUIElement(self.driver, NavigationLocators.SETTINGS_TAB_BTN, "Settings tab") @property def bn_artist_selection(self): return ButtonUIElement(self.driver, NavigationLocators.SWITCH_ARTIST_BTN, "Artist selection button") @property def bn_webview_done(self): return ButtonUIElement(self.driver, NavigationLocators.DONE_BN, "Web View Done button") @property def bn_time_period(self): return ButtonUIElement(self.driver, NavigationLocators.TIME_PERIOD_LB, "Time Period Selector") @property def bn_back(self): return ButtonUIElement(self.driver, NavigationLocators.BACK_BTN, "Back") @property def bn_dismiss(self): return ButtonUIElement(self.driver, NavigationLocators.DISMISS_BTN, "Dismiss") @property def bn_search(self): return ButtonUIElement(self.driver, NavigationLocators.SEARCH_BTN, "Search") @property def dots_menu(self): return ButtonUIElement(self.driver, NavigationLocators.DOTS_MENU, "3 dots menu") @property def dots_menu_from_track(self): return ButtonUIElement(self.driver, NavigationLocators.DOTS_MENU_FROM_TRACK, "3 dots menu") @allure.step("Scrolling to the end of the page") def scroll_down(self): self.driver.execute_script("mobile: scroll", {"direction": "down"}) return self def go_to_search(self): self.bn_search.click() return self def open_dots_menu(self): self.dots_menu.click() return self @allure.step("Swiping up") def swipe_up(self): self.driver.execute_script("mobile: swipe", {"direction": "up"}) return self @allure.step("Go Back") def click_back(self): self.bn_back.click() return self @allure.step("Click Dismiss [X]") def click_dismiss(self): self.bn_dismiss.click() return self @allure.step("Go to Library tab") def click_library_tab(self): self.bn_library_tab.click() return self @allure.step("Go to Artist tab") def click_artist_tab(self): self.bn_artist_tab.click() return self @allure.step("Go to Globe tab") def click_globe_tab(self): self.bn_globe_tab.click() return self @allure.step("Go to Settings tab") def click_settings_tab(self): self.bn_settings_tab.click() return self def click_to_hide_keyboard(self): size = self.driver.get_window_size() self.driver.tap(positions=[(size["width"] - 406, size["height"] / 2)]) def press_return_to_hide_keyboard(self): self.driver.hide_keyboard('return') return self def close_web_view(self): self.bn_webview_done.click() return self @allure.step("Open Artist Selection") def open_artist_selection(self): self.bn_artist_selection.click() return self @allure.step("Expand Time Interval") def expand_time_interval(self): self.bn_time_period.click() return self def get_time_interval_value(self): return self.bn_time_period.text.split(',')[1].strip() @allure.step("Select Last 1 year period") def select_period_last_1_year(self): self.expand_time_interval() size = self.driver.get_window_size() self.log.info("Blind double tapping") self.driver.tap(positions=[(size["width"] / 2, size["height"] - 70)]) if self.get_time_interval_value() != 'Last 1 year': self.driver.tap(positions=[(size["width"] / 2, size["height"] - 70)]) return self