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.track_view_locators import TrackViewLocators 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 TrackViewPage(CommonPage): log = cl.Logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver @property def bn_favorite_heart(self): return ButtonUIElement(self.driver, TrackViewLocators.FAVORITE_HEART_BTN, "Heart") @property def list_playlist(self): return ListUIElement(self.driver, all_elements_locator=TrackViewLocators.PLAYLIST_LIST, by_position_locator=TrackViewLocators.PLAYLIST_LIST_BY_POSITION) @property def lb_track_explicit(self): return LabelUIElement(self.driver, TrackViewLocators.LB_EXPLICIT, "Explicit label") @property def lb_source_total(self): return LabelUIElement(self.driver, TrackViewLocators.LB_SOURCE_TOTAL, "Total streams data") @property def lb_track_no_playlists(self): return LabelUIElement(self.driver, TrackViewLocators.LB_NO_PLAYLISTS, "Track is not in playlists") @property def bn_playlist_sort_streams(self): return ButtonUIElement(self.driver, TrackViewLocators.PLAYLIST_SORT_STREAMS, "Playlist sort by streams") @property def bn_playlist_sort_date_added(self): return ButtonUIElement(self.driver, TrackViewLocators.PLAYLIST_SORT_DATE_ADDED, "Playlist sort by date added") @property def bn_playlist_sort_date_dropped(self): return ButtonUIElement(self.driver, TrackViewLocators.PLAYLIST_SORT_DATE_DROPPED, "Playlist sort by date dropped") @property def bn_playlist_sort_position(self): return ButtonUIElement(self.driver, TrackViewLocators.PLAYLIST_SORT_POSITION, "Playlist sort by position") @property def bn_playlist_filter_status(self): return ButtonUIElement(self.driver, TrackViewLocators.PLAYLIST_FILTER_STATUS, "Filter by status - menu") @property def bn_compare(self): return ButtonUIElement(self.driver, TrackViewLocators.COMPARE, "Compare on Track page") def click_compare(self): self.bn_compare.click() return self def click_favorite_heart(self): self.bn_favorite_heart.click() return self @allure.step("Sort playlist by Streams") def sort_playlist_by_streams(self): self.bn_playlist_sort_streams.click() is_highlighted = self.bn_playlist_sort_streams.enabled assert is_highlighted == "true" return self @allure.step("Sort playlist by Date Added") def sort_playlist_by_date_added(self): self.bn_playlist_sort_date_added.click() is_highlighted = self.bn_playlist_sort_date_added.enabled assert is_highlighted == "true" return self @allure.step("Sort playlist by Position") def sort_playlist_by_position(self): self.bn_playlist_sort_position.click() is_highlighted = self.bn_playlist_sort_position.enabled assert is_highlighted == "true" return self @allure.step("Open Filter playlist bu status menu") def open_filter_menu_by_status(self): self.bn_playlist_filter_status.click() return self @allure.step("Filter playlist by Past Playlists") def select_past_playlists_filter(self): self.open_filter_menu_by_status() size = self.driver.get_window_size() self.log.info("Blind tapping") self.driver.tap(positions=[(size["width"]/2, size["height"] - 70)]) if self.bn_playlist_filter_status.value != 'menu, Past': self.driver.tap(positions=[(size["width"]/2, size["height"] - 70)]) is_highlighted = self.bn_playlist_sort_date_dropped.enabled assert is_highlighted == "true" return self @allure.step("Filter playlist by Current Playlists") def select_current_playlists_filter(self): self.open_filter_menu_by_status() size = self.driver.get_window_size() self.log.info("Blind tapping") self.driver.tap(positions=[(size["width"]/2, size["height"] - 120)]) if self.bn_playlist_filter_status.value != 'menu, Current': self.driver.tap(positions=[(size["width"]/2, size["height"] - 120)]) is_highlighted = self.bn_playlist_sort_date_added.enabled assert is_highlighted == "true" return self @allure.step("Check Track has no playlists") def is_track_has_no_playlists(self): with suppress(TimeoutExpired): return wait(self.lb_track_no_playlists.is_visible) return False @allure.step("Check Favorite Heart state") def is_favorite(self): return int(self.bn_favorite_heart.value) == 1 @allure.step("Check Track Explicit label presence") def is_track_explicit_label_present(self): with suppress(TimeoutExpired): return wait(self.lb_track_explicit.is_visible) return False # for internal use to see all chart elements on the page def print_all_track_charts_on_page(self): track_charts = self.charts_list.elements for el in track_charts: print(el.text) def print_all_playlist_items(self): playlist = self.list_playlist.elements for el in playlist: print(el.text) @allure.step("Check sources data presence") def is_source_data_present(self): with suppress(TimeoutExpired): return wait(self.lb_source_total.is_visible) return False