from time import sleep from appium.webdriver.common.appiumby import AppiumBy as By from helpers.exceptions import ElementShouldNotExistError from helpers.platform.ios.locators import ( ios_other_by_name, ios_static_text_by_name) from page_objects.base_screen import BaseScreen from page_objects.mixins.header_info_mixin import HeaderInfoMixin from page_objects.mixins.playlists_mixin import PlaylistsMixin class SoundRecordingScreen(BaseScreen, HeaderInfoMixin, PlaylistsMixin): header = '(//XCUIElementTypeScrollView)[2]' all_time_streams = 'allTimeStreams' all_time_streams_amount = '' streaming_trend_graph = 'streamingTrend' playlist_section = 'soundRecordingPlacementList' top_markets_section = 'topMarkets' hit_a_snag_msg = '' data_failed_to_load_msg = '' top_playlists_title = 'Top Playlists' top_playlists_i_icon = 'informationIcon' one_day_streams_btn = 'streamsSort1Day' seven_days_streams_btn = 'streamsSort7Days' most_recent_btn = 'addedSort' followers_btn = 'followersSort' see_all_playlists_btn = ios_other_by_name('showAllButton', index=2) playlist_store_icon = ios_other_by_name('storeIcon') playlist_card_title = ios_other_by_name('playlistCardTitleContainer') playlist_card_type = ios_static_text_by_name('playlistCardType') playlist_country_label = ios_other_by_name('metrics') playlist_bottom_tile = ios_other_by_name('songTile') def assert_track_and_artist_names(self, track_name, artist_name): track_name = ('//XCUIElementTypeStaticText[@name="SONG"]/' 'following-sibling::XCUIElementTypeStaticText[1]') artist_name = ('//XCUIElementTypeStaticText[@name="SONG"]/' 'following-sibling::XCUIElementTypeOther[1]') track_name_text = self.driver.find_element(By.XPATH, track_name).text artist_name_text = self.driver.find_element(By.XPATH, artist_name).text assert track_name_text == track_name assert artist_name_text == artist_name def assert_all_sections(self, context): # TODO: Temporarily disabled behind flag GO-4730 # self.assert_all_time_streams() self.assert_element(By.ID, self.streaming_trend_graph, 60) self.scroll_and_assert(By.ID, self.playlist_section, 20, small_scroll=True) if "sme" not in context.app_name: self.scroll_and_assert(By.ID, self.top_markets_section, 20, small_scroll=True) else: try: self.scroll_and_assert(By.ID, self.top_markets_section) raise ElementShouldNotExistError( f'"{self.top_markets_section}" should not be present ' f'for app "{context.app_name}"' ) except AssertionError: pass def assert_all_time_streams(self): self.assert_element(By.ID, self.all_time_streams, 90) def verify_streaming_trend_main_elements(self): self.assert_element(By.ID, self.streaming_trend_graph, 90) def click_streaming_trend_tab(self, tab): # TODO: Need to create locators pass def get_all_values_from_total_column_in_streaming_trend(self): # TODO: Need to create locators pass def tap_top_playlists_i_icon(self): sleep(1) self.scroll_and_assert(By.ACCESSIBILITY_ID, self.top_playlists_i_icon, small_scroll=True) self.click_with_retry(10, By.ACCESSIBILITY_ID, self.top_playlists_i_icon) def verify_top_playlists_popup_content(self): bottom_sheet = ios_other_by_name('Bottom Sheet', index=2) self.waiter(20, By.IOS_CLASS_CHAIN, bottom_sheet) self.swipe_back() self.wait_for_element_invisibility( By.IOS_CLASS_CHAIN, bottom_sheet) def verify_top_playlists_section_content(self): self.scroll_and_assert(By.ACCESSIBILITY_ID, self.seven_days_streams_btn, small_scroll=True, max_scrolls=20) self.waiter(10, By.ACCESSIBILITY_ID, self.top_playlists_title) self.waiter(3, By.ACCESSIBILITY_ID, self.top_playlists_i_icon) self.waiter(3, By.ACCESSIBILITY_ID, self.seven_days_streams_btn) self.waiter(3, By.ACCESSIBILITY_ID, self.most_recent_btn) self.waiter(3, By.ACCESSIBILITY_ID, self.followers_btn) def verify_see_all_playlists_button(self): self.scroll_and_assert(By.IOS_CLASS_CHAIN, self.see_all_playlists_btn, max_scrolls=20, small_scroll=True) def verify_top_playlists_cards_content(self, context): sleep(5) if context.screen_location != 'Playlists tab': self.waiter(20, By.IOS_CLASS_CHAIN, self.playlist_store_icon) self.waiter(3, By.IOS_CLASS_CHAIN, self.playlist_card_title) self.waiter(3, By.IOS_CLASS_CHAIN, self.playlist_card_type) self.waiter(3, By.IOS_CLASS_CHAIN, self.playlist_country_label) self.waiter(3, By.IOS_CLASS_CHAIN, self.playlist_bottom_tile) def assert_number_of_displayed_playlists(self, context, number): if "sme" not in context.app_name: actual_num_of_playlists = \ (len(self.waiter( 10, By.IOS_CLASS_CHAIN, self.playlist_card_title, multiple=True))) assert actual_num_of_playlists == int(number), \ (f"Expected {number} playlists, " f"but found {actual_num_of_playlists}") def assert_number_of_displayed_playlists_exceeds(self, number): sleep(3) actual_num_of_playlists = ( len(self.waiter(10, By.IOS_CLASS_CHAIN, self.playlist_card_title, multiple=True))) assert actual_num_of_playlists > int(number), \ (f"Expected more than {number} playlists, " f"but found {actual_num_of_playlists}") def select_top_playlists_filter(self, filter_by): filter_btns = \ {'1d Streams': self.one_day_streams_btn, '7d Streams': self.seven_days_streams_btn, 'Most Recent': self.most_recent_btn, 'Followers': self.followers_btn} self.waiter(3, By.ACCESSIBILITY_ID, filter_btns[filter_by]).click() def tap_see_all_playlists_btn(self): self.scroll_and_assert(By.IOS_CLASS_CHAIN, self.see_all_playlists_btn, small_scroll=True) self.click_with_retry(3, By.IOS_CLASS_CHAIN, self.see_all_playlists_btn) self.wait_for_element_invisibility(By.IOS_CLASS_CHAIN, self.see_all_playlists_btn)