from allure import step from playwright.sync_api import Page from src.ui_elements.base_ui_element import BaseUIElement from src.pages.artist_page import ArtistPage, return_rounded_with_suffix from src.locators.track_locators import TrackLocators class TrackPage(ArtistPage): def __init__(self, page: Page): super().__init__(page) self.page = page self.entity_type = 'track' self.url = f'/{self.entity_type}' self.embed_widget_player = BaseUIElement(self.page, TrackLocators.EMBED_PLAYER, 'Embed Widget player') self.track_released_date = BaseUIElement(self.page, TrackLocators.TRACK_RELEASE, 'Track Released date') self.track_artist = BaseUIElement(self.page, TrackLocators.TRACK_ARTIST, 'Track\'s Artist') @step("Check TikTok discovery data stats for Track") def check_discovery_data_stats_tiktok(self, network_response): discovery_result = network_response.value.json() creations_n = discovery_result['tiktok']['posts_latest'] mentions_n = discovery_result['tiktok']['mentions'] comments_n = discovery_result['tiktok']['comments'] self.discovery_stats_title.contain_text(f"{return_rounded_with_suffix(creations_n)} Creations") self.discovery_stats_secondary.get_by(1).contain_text(f"Mentions{return_rounded_with_suffix(mentions_n)}") self.discovery_stats_secondary.get_by(2).contain_text(f"Comments{return_rounded_with_suffix(comments_n)}") @step("Check YouTube discovery data stats for Track") def check_discovery_data_stats_youtube(self, network_response): discovery_result = network_response.value.json() videos_n = discovery_result['youtube']['videos'] comments_n = discovery_result['youtube']['comments'] latest_release_date = discovery_result['youtube']['latest_release_date'] self.discovery_stats_title.contain_text(f"{return_rounded_with_suffix(videos_n)} Videos Released") self.check_stats_latest_release(latest_release_date) self.discovery_stats_secondary.get_by(1).contain_text(f"Comments{return_rounded_with_suffix(comments_n)}") @step("Check Spotify discovery data stats for Track") def check_discovery_data_stats_spotify(self, network_response): discovery_result = network_response.value.json() playlists_n = discovery_result['spotify']['playlists'] popularity_n = discovery_result['spotify']['popularity'] if playlists_n == 1: self.discovery_stats_title.contain_text("1 Playlist") else: self.discovery_stats_title.contain_text(f"{return_rounded_with_suffix(playlists_n)} Playlists") self.discovery_stats_secondary.get_by(1).contain_text(f"Popularity{popularity_n}") @step("Check SoundCloud discovery data stats for Track") def check_discovery_data_stats_soundcloud(self, network_response): discovery_result = network_response.value.json() likes_n = discovery_result['soundcloud']['likes'] comments_n = discovery_result['soundcloud']['comments'] self.discovery_stats_secondary.get_by(1).contain_text(f"Likes{return_rounded_with_suffix(likes_n)}") self.discovery_stats_secondary.get_by(2).contain_text(f"Comments{return_rounded_with_suffix(comments_n)}")