from appium.webdriver.common.appiumby import AppiumBy as By from helpers.platform.ios.locators import ios_label_equals from ..base_screen import BaseScreen from page_objects.mixins.header_info_mixin import HeaderInfoMixin class ProductScreen(BaseScreen, HeaderInfoMixin): header = '(//XCUIElementTypeScrollView)[2]' all_time_streams = 'allTimeStreams' streaming_trend_graph = 'streamingTrend' tracklist_title = 'Tracklist' tracklist_tracks = ('**/XCUIElementTypeOther' '[`name BEGINSWITH "productTrack"`]') tracklist_track_names = '' tracklist_track_artists = '' tracklist_track_stream_count = '' sources_btn = 'sourcesLink' data_source_title = ios_label_equals('DATA SOURCES') data_source_close_btn = 'closeButton' def verify_header_info(self, expected_info): self.scroll_header("left") header_info = self.header_info() for key, expected_value in expected_info.items(): actual_value = header_info.get(key) assert actual_value == expected_value, ( f"Header info mismatch for '{key}':\n" f"Expected: {expected_value}\n" f"Actual: {actual_value}\n" f"Full header info: {header_info}" ) def verify_product_tracklist_displayed(self): self.scroll_and_assert(By.ACCESSIBILITY_ID, self.tracklist_title, small_scroll=True, max_scrolls=20) tracks = self.driver.find_elements(By.IOS_CLASS_CHAIN, self.tracklist_tracks) assert len(tracks) >= 3 def assert_all_time_streams(self): self.assert_element(By.ID, self.all_time_streams, 90) def assert_streaming_trends(self): self.assert_element(By.ID, self.streaming_trend_graph, 90) def tap_song_by_number(self, context, track_number): # TODO: Need to create locators pass def navigate_to_sources(self): self.scroll_and_assert(By.ACCESSIBILITY_ID, self.sources_btn, max_scrolls=5) self.waiter(3, By.ACCESSIBILITY_ID, self.sources_btn).click() def verify_data_sources_opened(self, context): self.waiter(10, By.IOS_CLASS_CHAIN, self.data_source_title) popular_sources = ['AWA', 'Amazon Music', 'Apple Music'] for source in popular_sources: self.waiter(10, By.ACCESSIBILITY_ID, source) def close_data_sources(self): self.waiter(1, By.ACCESSIBILITY_ID, self.data_source_close_btn).click() self.scroll_and_assert(By.ACCESSIBILITY_ID, self.tracklist_title, direction='up')