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.album_view_locators import AlbumViewLocators 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.common_page import CommonPage class AlbumViewPage(CommonPage): log = cl.Logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver @property def lb_album_image(self): return LabelUIElement(self.driver, AlbumViewLocators.ALBUM_IMAGE, "Album image") @property def bn_album_compare_tracks(self): return ButtonUIElement(self.driver, AlbumViewLocators.COMPARE_TRACKS, "Album Compare Tracks") @property def list_album_tracks(self): return ListUIElement(self.driver, all_elements_locator=AlbumViewLocators.ALBUM_TRACKS_LIST, by_position_locator=AlbumViewLocators.ALBUM_TRACKS_LIST_BY_POSITION, by_text_locator=AlbumViewLocators.ALBUM_TRACKS_LIST_BY_TEXT) @allure.step("Check Album image presence") def is_album_image_present(self): with suppress(TimeoutExpired): is_image = self.lb_album_image.is_visible print("Video image is {}".format(self.lb_album_image.attr_name)) return wait(is_image) return False @allure.step("Check Album name presence") def is_album_name_present(self, album_name): name = album_name.split(' ')[0].strip() return self.is_element_displayed("**/XCUIElementTypeStaticText[`label BEGINSWITH \"{}\"`]".format(name), "class-chain") @allure.step("Check that Album contains tracks") def is_album_contains_tracks(self): album = self.list_album_tracks.texts print("Album contains tracks: {}".format(album)) print("Tracks in album = {}".format(len(album))) print("Last track number = {}".format(album[-1][0])) return len(album) == int(album[-1].split(' ')[0]) and album[-1][-1] == "%"