import logging from contextlib import suppress import allure from ui_automation_framework.utils import logger as cl from waiting import TimeoutExpired, ALL from src.helpers.waiting_wrapper import wait from src.locators.albums_locators import AlbumsLocators from ui_automation_framework.core.base_page import BasePage 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.ui_elements.list_ui_element import ListUIElement from src.pages.album_view_page import AlbumViewPage class AlbumsPage(BasePage): log = cl.Logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver @property def lb_all_albums(self): return LabelUIElement(self.driver, AlbumsLocators.ALL_ALBUMS_LB, "All Albums Logo") @property def lb_newest_releases(self): return LabelUIElement(self.driver, AlbumsLocators.NEWEST_RELEASES_LB, "Newest Releases Logo") @property def lb_albums_alltime(self): return LabelUIElement(self.driver, AlbumsLocators.ALBUMS_ALLTIME, "ALLTIME Logo") @property def bn_albums_beta(self): return ButtonUIElement(self.driver, AlbumsLocators.ALBUMS_BETA_BN, "BETA") @property def lb_albums_beta(self): return LabelUIElement(self.driver, AlbumsLocators.ALBUMS_BETA_LB, "Albums, EPs, & LPs BETA") @property def list_albums(self): return ListUIElement(self.driver, all_elements_locator=AlbumsLocators.ALBUMS_LIST, by_position_locator=AlbumsLocators.ALBUMS_LIST_BY_POSITION, by_text_locator=AlbumsLocators.ALBUMS_LIST_BY_TEXT) @allure.step("View All albums page is visible") def all_albums_page_visible(self): with suppress(TimeoutExpired): return wait(ALL([self.lb_all_albums.is_visible, self.lb_albums_alltime.is_visible])) return False @allure.step("Latest Uploads videos page is visible") def newest_releases_albums_page_visible(self): with suppress(TimeoutExpired): return wait(ALL([self.lb_newest_releases.is_visible, self.lb_albums_alltime.is_visible])) return False @allure.step("Selecting album by position") def select_album_by_position(self, position): self.list_albums.select_by_position(position) return AlbumViewPage(self.driver) @allure.step("Selecting album by name") def select_album_by_name(self, name): self.list_albums.select_by_text(name) return AlbumViewPage(self.driver) @allure.step("Click Album BETA") def view_albums_beta_label(self): self.bn_albums_beta.click() return self