import json import random import re from allure import step from assertpy import assert_that from playwright.sync_api import Page from playwright.sync_api import expect from src import config from src.locators.discovery_locators import DiscoveryLocators from src.ui_elements.base_ui_element import BaseUIElement from src.ui_elements.slider_ui_element import SliderUIElement from src.ui_elements.dropdown_ui_element import DropDownUIElement from src.ui_elements.discovery_panel_ui_element import DiscoveryPanelUIElement from src.ui_elements.checkbox_ui_element import CheckboxUIElement from src.ui_elements.switch_ui_element import SwitchUIElement from src.pages.discovery_results_page import DiscoveryResultsPage from src.pages.home_page import HomePage from src.helpers import api_helper class DiscoveryPage(HomePage): def __init__(self, page: Page): super().__init__(page) self.page = page self.url = '/discovery' self.api_artist_total_count = config.TARGET_API_URL + api_helper.api_total_count.format('artist') self.api_track_total_count = config.TARGET_API_URL + api_helper.api_total_count.format('track') self.api_artist_discovery = config.TARGET_API_URL + api_helper.api_discovery.format('artist') self.api_track_discovery = config.TARGET_API_URL + api_helper.api_discovery.format('track') self.title_discovery = BaseUIElement(self.page, DiscoveryLocators.TITLE_DISCOVERY, 'Discovery page title') self.bn_discovery = BaseUIElement(self.page, DiscoveryLocators.BN_DISCOVERY, 'Discovery button') self.results_expected = BaseUIElement(self.page, DiscoveryLocators.RESULTS_EXPECTED, 'Results Expected') self.dsp_tiktok = BaseUIElement(self.page, DiscoveryLocators.DSP_TIKTOK, 'DSP TikTok') self.dsp_youtube = BaseUIElement(self.page, DiscoveryLocators.DSP_YOUTUBE, 'DSP YouTube') self.dsp_spotify = BaseUIElement(self.page, DiscoveryLocators.DSP_SPOTIFY, 'DSP Spotify') self.dsp_soundcloud = BaseUIElement(self.page, DiscoveryLocators.DSP_SOUNDCLOUD, 'DSP SoundCloud') self.dsp_apple = BaseUIElement(self.page, DiscoveryLocators.DSP_APPLE, 'DSP Apple') self.bn_scope_artists = BaseUIElement(self.page, DiscoveryLocators.BN_SCOPE_ARTISTS, 'Artis Scope') self.bn_scope_tracks = BaseUIElement(self.page, DiscoveryLocators.BN_SCOPE_TRACKS, 'Tracks Scope') # ================================ FILTERS ==================================================================== self.filter_country = BaseUIElement(self.page, DiscoveryLocators.FILTER_COUNTRY, 'Country filter') self.filter_country_list = BaseUIElement(self.page, DiscoveryLocators.FILTER_COUNTRY_LIST, 'Country filter list') self.filter_country_value = BaseUIElement(self.page, DiscoveryLocators.FILTER_COUNTRY_VALUE, 'Country filter value') self.filter_country_search_input = BaseUIElement(self.page, DiscoveryLocators.FILTER_COUNTRY_SEARCH_INPUT, 'Country filter search input') self.filter_country_search_close_btn = BaseUIElement(self.page, DiscoveryLocators.FILTER_COUNTRY_SEARCH_CLOSE, 'Country filter search close button') self.filter_country_item_by_n = self.page.locator(DiscoveryLocators.FILTER_COUNTRY_ITEM_BY_N) self.filter_country_item = CheckboxUIElement(self.page, DiscoveryLocators.FILTER_COUNTRY_ITEM, 'Country filter item') self.filter_country_all = CheckboxUIElement(self.page, DiscoveryLocators.FILTER_COUNTRY_ALL, 'Country filter All') self.filter_country_favorite_switch = SwitchUIElement( self.page, DiscoveryLocators.FILTER_COUNTRY_FAVORITE_SWITCH, 'Country filter Favorite Switch') self.filter_country_item_star_btn = BaseUIElement( self.page, DiscoveryLocators.FILTER_COUNTRY_ITEM_STAR_BTN, 'Country filter item from all - Star button') self.filter_genre = BaseUIElement(self.page, DiscoveryLocators.FILTER_GENRE, 'Genre filter') self.filter_genre_list = BaseUIElement(self.page, DiscoveryLocators.FILTER_GENRE_LIST, 'Genre filter list') self.filter_genre_value = BaseUIElement(self.page, DiscoveryLocators.FILTER_GENRE_VALUE, 'Genre filter value') self.filter_genre_search_input = BaseUIElement(self.page, DiscoveryLocators.FILTER_GENRE_SEARCH_INPUT, 'Genre filter search input') self.filter_genre_search_close_btn = BaseUIElement(self.page, DiscoveryLocators.FILTER_GENRE_SEARCH_CLOSE, 'Genre filter search close button') self.filter_genre_item_by_n = self.page.locator(DiscoveryLocators.FILTER_GENRE_ITEM_BY_N) self.filter_genre_item = CheckboxUIElement(self.page, DiscoveryLocators.FILTER_GENRE_ITEM, 'Genre filter item') self.filter_genre_all = CheckboxUIElement(self.page, DiscoveryLocators.FILTER_GENRE_ALL, 'Genre filter All') self.filter_genre_favorite_switch = SwitchUIElement( self.page, DiscoveryLocators.FILTER_GENRE_FAVORITE_SWITCH, 'Genre filter Favorite Switch') self.filter_genre_item_star_btn = BaseUIElement( self.page, DiscoveryLocators.FILTER_GENRE_ITEM_STAR_BTN, 'Genre filter item from all - Star button') # ================================ PANELS ====================================================================== self.audience_block = self.page.locator(DiscoveryLocators.AUDIENCE_BLOCK) self.audience_block_collapse = BaseUIElement(self.page, DiscoveryLocators.AUDIENCE_BLOCK_COLLAPSE, 'Audience Collapsable Block') self.audience_block_title = DiscoveryPanelUIElement(self.page, DiscoveryLocators.AUDIENCE_BLOCK_TITLE, 'Audience Block Title') self.audience_tiktok_followers_min = SliderUIElement(self.page, DiscoveryLocators.AUDIENCE_TIKTOK_FOLLOWERS_0, 'Audience TikTok Followers Min') self.audience_tiktok_followers_max = SliderUIElement(self.page, DiscoveryLocators.AUDIENCE_TIKTOK_FOLLOWERS_1, 'Audience TikTok Followers Max') self.audience_youtube_subscribers_min = SliderUIElement(self.page, DiscoveryLocators.AUDIENCE_YOUTUBE_SUBSCRIBERS_0, 'Audience YouTube Subscribers Min') self.audience_youtube_subscribers_max = SliderUIElement(self.page, DiscoveryLocators.AUDIENCE_YOUTUBE_SUBSCRIBERS_1, 'Audience YouTube Subscribers Max') self.audience_spotify_followers_min = SliderUIElement(self.page, DiscoveryLocators.AUDIENCE_SPOTIFY_FOLLOWERS_0, 'Audience Spotify Followers Min') self.audience_spotify_followers_max = SliderUIElement(self.page, DiscoveryLocators.AUDIENCE_SPOTIFY_FOLLOWERS_1, 'Audience Spotify Followers Max') self.audience_soundcloud_followers_min = SliderUIElement(self.page, DiscoveryLocators.AUDIENCE_SOUNDCLOUD_FOLLOWERS_0, 'Audience SoundCloud Followers Min') self.audience_soundcloud_followers_max = SliderUIElement(self.page, DiscoveryLocators.AUDIENCE_SOUNDCLOUD_FOLLOWERS_1, 'Audience SoundCloud Followers Max') self.audience_tiktok_views_min = SliderUIElement(self.page, DiscoveryLocators.AUDIENCE_TIKTOK_VIEWS_0, 'Audience TikTok Views Min') self.audience_tiktok_views_max = SliderUIElement(self.page, DiscoveryLocators.AUDIENCE_TIKTOK_VIEWS_1, 'Audience TikTok Views Max') self.audience_spotify_listeners_min = SliderUIElement(self.page, DiscoveryLocators.AUDIENCE_SPOTIFY_LISTENERS_0, 'Audience Spotify Listeners Min') self.audience_spotify_listeners_max = SliderUIElement(self.page, DiscoveryLocators.AUDIENCE_SPOTIFY_LISTENERS_1, 'Audience Spotify Listeners Max') self.audience_soundcloud_genre = DropDownUIElement(self.page, DiscoveryLocators.AUDIENCE_SOUNDCLOUD_GENRE, 'Audience SoundCloud Genre') self.releases_block = self.page.locator(DiscoveryLocators.RELEASES_BLOCK) self.releases_block_collapse = BaseUIElement(self.page, DiscoveryLocators.RELEASES_BLOCK_COLLAPSE, 'Releases Collapsable Block') self.releases_block_title = DiscoveryPanelUIElement(self.page, DiscoveryLocators.RELEASES_BLOCK_TITLE, 'Releases Block Title') self.releases_tiktok_min_creations = SliderUIElement(self.page, DiscoveryLocators.RELEASES_TIKTOK_MIN_CREATIONS, 'Releases TikTok Min. Creations') self.releases_tiktok_creation_duration_min = SliderUIElement( self.page, DiscoveryLocators.RELEASES_TIKTOK_CREATION_DURATION_0, 'Releases TikTok Creation Duration Min') self.releases_tiktok_creation_duration_max = SliderUIElement( self.page, DiscoveryLocators.RELEASES_TIKTOK_CREATION_DURATION_1, 'Releases TikTok Video Duration Max') self.releases_youtube_min_videos = SliderUIElement(self.page, DiscoveryLocators.RELEASES_YOUTUBE_MIN_VIDEOS, 'Releases YouTube Min. Videos') self.releases_spotify_min_tracks = SliderUIElement(self.page, DiscoveryLocators.RELEASES_SPOTIFY_MIN_TRACKS, 'Releases Spotify Min. Tracks') self.releases_soundcloud_min_tracks = SliderUIElement(self.page, DiscoveryLocators.RELEASES_SOUNDCLOUD_MIN_TRACKS, 'Releases SoundCloud Min. Tracks') self.performance_block = self.page.locator(DiscoveryLocators.PERFORMANCE_BLOCK) self.performance_block_collapse = BaseUIElement(self.page, DiscoveryLocators.PERFORMANCE_BLOCK_COLLAPSE, 'Performance Collapsable Block') self.performance_block_title = DiscoveryPanelUIElement(self.page, DiscoveryLocators.PERFORMANCE_BLOCK_TITLE, 'Performance Block Title') self.performance_tiktok_mentions_min = SliderUIElement(self.page, DiscoveryLocators.PERFORMANCE_TIKTOK_MENTIONS_0, 'Performance TikTok Mentions Min') self.performance_tiktok_mentions_max = SliderUIElement(self.page, DiscoveryLocators.PERFORMANCE_TIKTOK_MENTIONS_1, 'Performance TikTok Mentions Max') self.performance_tiktok_likes_min = SliderUIElement(self.page, DiscoveryLocators.PERFORMANCE_TIKTOK_LIKES_0, 'Performance TikTok Likes Min') self.performance_tiktok_likes_max = SliderUIElement(self.page, DiscoveryLocators.PERFORMANCE_TIKTOK_LIKES_1, 'Performance TikTok Likes Max') self.performance_youtube_views_min = SliderUIElement(self.page, DiscoveryLocators.PERFORMANCE_YOUTUBE_VIEWS_0, 'Performance YouTube Views Min') self.performance_youtube_views_max = SliderUIElement(self.page, DiscoveryLocators.PERFORMANCE_YOUTUBE_VIEWS_1, 'Performance YouTube Views Max') self.performance_soundcloud_plays_min = SliderUIElement(self.page, DiscoveryLocators.PERFORMANCE_SOUNDCLOUD_0, 'Performance SoundCloud Plays Min') self.performance_soundcloud_plays_max = SliderUIElement(self.page, DiscoveryLocators.PERFORMANCE_SOUNDCLOUD_1, 'Performance SoundCloud Plays Max') self.performance_spotify_streams_min = SliderUIElement(self.page, DiscoveryLocators.PERFORMANCE_SPOTIFY_STREAMS_0, 'Performance Spotify Streams Min') self.performance_spotify_streams_max = SliderUIElement(self.page, DiscoveryLocators.PERFORMANCE_SPOTIFY_STREAMS_1, 'Performance Spotify Streams Max') self.performance_spotify_playlists_min = SliderUIElement(self.page, DiscoveryLocators.PERFORMANCE_SPOTIFY_PLAYLISTS_0, 'Performance Spotify Playlists Min') self.performance_spotify_playlists_max = SliderUIElement(self.page, DiscoveryLocators.PERFORMANCE_SPOTIFY_PLAYLISTS_1, 'Performance Spotify Playlists Max') self.engagement_block = self.page.locator(DiscoveryLocators.ENGAGEMENT_BLOCK) self.engagement_block_collapse = BaseUIElement(self.page, DiscoveryLocators.ENGAGEMENT_BLOCK_COLLAPSE, 'Engagement Collapsable Block') self.engagement_block_title = DiscoveryPanelUIElement(self.page, DiscoveryLocators.ENGAGEMENT_BLOCK_TITLE, 'Engagement Block Title') self.engagement_tiktok_likes_min = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_TIKTOK_LIKES_0, 'Engagement TikTok Likes Min') self.engagement_tiktok_likes_max = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_TIKTOK_LIKES_1, 'Engagement TikTok Likes Max') self.engagement_tiktok_comments_min = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_TIKTOK_COMMENTS_0, 'Engagement TikTok Comments Min') self.engagement_tiktok_comments_max = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_TIKTOK_COMMENTS_1, 'Engagement TikTok Comments Max') self.engagement_tiktok_mentions_min = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_TIKTOK_MENTIONS_0, 'Engagement TikTok Mentions Min') self.engagement_tiktok_mentions_max = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_TIKTOK_MENTIONS_1, 'Engagement TikTok Mentions Max') self.engagement_youtube_likes_min = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_YOUTUBE_LIKES_0, 'Engagement YouTube Likes Min') self.engagement_youtube_likes_max = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_YOUTUBE_LIKES_1, 'Engagement YouTube Likes Max') self.engagement_youtube_comments_min = SliderUIElement( self.page, DiscoveryLocators.ENGAGEMENT_YOUTUBE_COMMENTS_0, 'Engagement YouTube Comments Min') self.engagement_youtube_comments_max = SliderUIElement( self.page, DiscoveryLocators.ENGAGEMENT_YOUTUBE_COMMENTS_1, 'Engagement YouTube Comments Max') self.engagement_spotify_listeners_min = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_SPOTIFY_LISTENERS_0, 'Engagement Spotify Listeners Min') self.engagement_spotify_listeners_max = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_SPOTIFY_LISTENERS_1, 'Engagement Spotify Listeners Max') self.engagement_spotify_popularity_min = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_SPOTIFY_POPULARITY_0, 'Engagement Spotify Popularity Min') self.engagement_spotify_popularity_max = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_SPOTIFY_POPULARITY_1, 'Engagement Spotify Popularity Max') self.engagement_soundcloud_comments_min = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_SOUNDCLOUD_COMMENTS_0, 'Engagement SoundCloud Comments Min') self.engagement_soundcloud_comments_max = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_SOUNDCLOUD_COMMENTS_1, 'Engagement SoundCloud Comments Max') self.engagement_soundcloud_likes_min = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_SOUNDCLOUD_LIKES_0, 'Engagement SoundCloud Likes Min') self.engagement_soundcloud_likes_max = SliderUIElement(self.page, DiscoveryLocators.ENGAGEMENT_SOUNDCLOUD_LIKES_1, 'Engagement SoundCloud Likes Max') self.freshest_release_block = self.page.locator(DiscoveryLocators.FRESHEST_RELEASE_BLOCK) self.freshest_release_block_collapse = BaseUIElement(self.page, DiscoveryLocators.FRESHEST_RELEASE_BLOCK_COLLAPSE, 'Freshest Release Collapsable Block') self.freshest_release_block_title = DiscoveryPanelUIElement(self.page, DiscoveryLocators.FRESHEST_RELEASE_BLOCK_TITLE, 'Freshest Release Block Title') self.freshest_release_tiktok = DropDownUIElement(self.page, DiscoveryLocators.FRESHEST_RELEASE_TIKTOK, 'TikTok Latest Release') self.freshest_release_youtube = DropDownUIElement(self.page, DiscoveryLocators.FRESHEST_RELEASE_YOUTUBE, 'YouTube Latest Release') self.freshest_release_spotify = DropDownUIElement(self.page, DiscoveryLocators.FRESHEST_RELEASE_SPOTIFY, 'Spotify Latest Release') self.freshest_release_soundcloud = DropDownUIElement(self.page, DiscoveryLocators.FRESHEST_RELEASE_SOUNDCLOUD, 'SoundCloud Latest Release') self.sparkline_block = self.page.locator(DiscoveryLocators.SPARKLINE_BLOCK) self.sparkline_block_collapse = BaseUIElement(self.page, DiscoveryLocators.SPARKLINE_BLOCK_COLLAPSE, 'Sparkline Collapsable Block') self.sparkline_block_title = DiscoveryPanelUIElement(self.page, DiscoveryLocators.SPARKLINE_BLOCK_TITLE, 'Sparkline Release Block Title') self.sparkline_tiktok = DropDownUIElement(self.page, DiscoveryLocators.SPARKLINE_TIKTOK, 'Sparkline TikTok') self.sparkline_youtube = DropDownUIElement(self.page, DiscoveryLocators.SPARKLINE_YOUTUBE, 'Sparkline YouTube') self.sparkline_spotify = DropDownUIElement(self.page, DiscoveryLocators.SPARKLINE_SPOTIFY, 'Sparkline Spotify') self.sparkline_soundcloud = DropDownUIElement(self.page, DiscoveryLocators.SPARKLINE_SOUNDCLOUD, 'Sparkline SoundCloud') @step("Discovery page is loaded") def is_page_loaded(self): self.title_discovery.exists() self.intercom.exists() @step("Return Results Expected value") def results_expected_value(self): result = self.results_expected.get_text() print(f'Results Expected = {result}') return result # =========================== SCOPE @step("Search scope is selected to ARTISTS") def check_search_scope_is_artists(self): self.bn_scope_artists.is_active() @step("Search scope is selected to TRACKS") def check_search_scope_is_tracks(self): self.bn_scope_tracks.is_active() @step("Switch Search to Artists") def switch_scope_to_artists(self): self.bn_scope_artists.click() self.check_search_scope_is_artists() @step("Switch Search to Tracks") def switch_scope_to_tracks(self): self.bn_scope_tracks.click() self.check_search_scope_is_tracks() # =========================== DSP @step("Switch TikTok DSP filter to - {state}") def dsp_tiktok_on(self, state): self.dsp_tiktok.click() self.dsp_tiktok.is_selected(state) @step("Switch YouTube DSP filter to - {state}") def dsp_youtube_on(self, state): self.dsp_youtube.click() self.dsp_youtube.is_selected(state) @step("Switch Spotify DSP filter to - {state}") def dsp_spotify_on(self, state): self.dsp_spotify.click() self.dsp_spotify.is_selected(state) @step("Switch SoundCloud DSP filter to - {state}") def dsp_soundcloud_on(self, state): self.dsp_soundcloud.click() self.dsp_soundcloud.is_selected(state) # =========================== FILTER COUNTRY @step("Count countries in all filter") def filter_country_items_count_all(self): return self.filter_country_item_by_n.count() @step("Verify all Country filter sorting") def all_filter_country_sorting_verification(self): for i in range(self.filter_country_items_count_all()-1): country_prev = self.filter_country_item_by_n.nth(i).text_content() country_next = self.filter_country_item_by_n.nth(i + 1).text_content() self.log.info(f"{country_prev} < {country_next}") assert_that(country_prev < country_next).is_true() return @step("Verify all Country filter items are unchecked") def all_filter_country_items_unchecked(self): for i in range(self.filter_country_items_count_all()): expect(self.filter_country_item_by_n.nth(i)).not_to_have_class(re.compile(r"checkbox--checked")) return @step("Verify all Country filter items are checked") def all_filter_country_items_are_checked(self): for i in range(self.filter_country_items_count_all()): expect(self.filter_country_item_by_n.nth(i)).to_have_class(re.compile(r"checkbox--checked")) return # =========================== FILTER GENRE @step("Count genres in all filter") def filter_genre_items_count_all(self): return self.filter_genre_item_by_n.count() @step("Verify all Genre filter sorting") def all_filter_genre_sorting_verification(self): for i in range(self.filter_genre_items_count_all() - 1): genre_prev = self.filter_genre_item_by_n.nth(i).text_content() genre_next = self.filter_genre_item_by_n.nth(i + 1).text_content() self.log.info(f"{genre_prev} < {genre_next}") assert_that(genre_prev < genre_next).is_true() return @step("Verify all Genre filter items are unchecked") def all_filter_genre_items_unchecked(self): for i in range(self.filter_genre_items_count_all()): expect(self.filter_genre_item_by_n.nth(i)).not_to_have_class(re.compile(r"checkbox--checked")) return @step("Verify all Genre filter items are checked") def all_filter_genre_items_are_checked(self): for i in range(self.filter_genre_items_count_all()): expect(self.filter_genre_item_by_n.nth(i)).to_have_class(re.compile(r"checkbox--checked")) return # =========================== AUDIENCE @step("Expand Audience block") def expand_audience_block(self): self.audience_block.click() self.audience_block_collapse.is_hidden(False) return self @step("Collapse Audience block") def collapse_audience_block(self): self.audience_block.click() self.audience_block_collapse.is_hidden(True) # =========================== RELEASES @step("Expand Releases block") def expand_releases_block(self): self.releases_block.click() self.releases_block_collapse.is_hidden(False) @step("Collapse Releases block") def collapse_releases_block(self): self.releases_block.click() self.releases_block_collapse.is_hidden(True) # =========================== PERFORMANCE @step("Expand Performance block") def expand_performance_block(self): self.performance_block.click() self.performance_block_collapse.is_hidden(False) @step("Collapse Performance block") def collapse_performance_block(self): self.performance_block.click() self.performance_block_collapse.is_hidden(True) # =========================== ENGAGEMENT @step("Expand Engagement block") def expand_engagement_block(self): self.engagement_block.click() self.engagement_block_collapse.is_hidden(False) @step("Collapse Engagement block") def collapse_engagement_block(self): self.engagement_block.click() self.engagement_block_collapse.is_hidden(True) # =========================== FRESHEST RELEASE @step("Expand Freshest Release block") def expand_freshest_release_block(self): self.freshest_release_block.click() self.freshest_release_block_collapse.is_hidden(False) return self @step("Collapse Freshest Release block") def collapse_freshest_release_block(self): self.freshest_release_block.click() self.freshest_release_block_collapse.is_hidden(True) # =========================== SPARKLINE @step("Expand Sparkline block") def expand_sparkline_block(self): self.sparkline_block.click() self.sparkline_block_collapse.is_hidden(False) return self @step("Collapse Sparkline block") def collapse_sparkline_block(self): self.sparkline_block.click() self.sparkline_block_collapse.is_hidden(True) # =========================== PAYLOAD COMPARISON @step("Check that Total Count == Discovery") def check_discovery_payload(self, total_request, discovery_request, expected): total_count = total_request.value.post_data_json discovery = discovery_request.value.post_data_json assert_that(discovery["error_rate"]).is_equal_to(0.05) assert_that(discovery["limit"]).is_equal_to(60) assert_that(discovery["offset"]).is_equal_to(0) discovery.pop("limit") discovery.pop("offset") discovery.pop("error_rate") discovery.pop("trend_period") if 'countries' in total_count: if 'n-a' in total_count['countries']: total_count['countries'].remove('n-a') discovery['countries'].remove('n-a') if 'genres' in total_count: if 'n-a' in total_count['genres']: total_count['genres'].remove('n-a') discovery['genres'].remove('n-a') # with open('src/data/discovery_payload_default.json') as default_file: # default = json.load(default_file) # for dsp in expected.keys(): # # default[dsp].update(expected[dsp]) # pass for dsp in discovery.keys(): assert_that(dsp in expected.keys()) print('Payload Expected \n{}'.format(expected[dsp])) print('Payload TotalCount \n{}'.format(total_count[dsp])) print('Payload Discovery \n{}'.format(discovery[dsp])) assert_that(total_count[dsp]).is_equal_to(discovery[dsp]).is_equal_to(expected[dsp]) @step("Click Discovery button and verify PAYLOADS") def click_discovery_and_compare_payloads_with_diff_and_return(self, scope, total_request, expected): if self.results_expected_value() == '0': self.bn_discovery.is_enabled(False) self.page.reload() else: discovery_api = None if scope == 'artist': discovery_api = self.api_artist_discovery elif scope == 'track': discovery_api = self.api_track_discovery with self.page.expect_request(discovery_api) as discovery_request: self.bn_discovery.click() self.check_discovery_payload(total_request, discovery_request, expected) DiscoveryResultsPage(self.page).bn_edit_discovery.click() @step("Run random tiktok change for artist") def random_artist_tiktok_changes(self, func=None): if func is None: func = random.choice(range(1, 11)) print('Chosen function# {}'.format(func)) if func == 1: self.audience_tiktok_followers_min.slide(direction='Right', times=random.choice(range(1, 5))) elif func == 2: self.audience_tiktok_followers_max.slide(direction='Left', times=random.choice(range(1, 5))) elif func == 3: self.releases_tiktok_min_creations.slide(direction='Right', times=random.choice(range(1, 4))) elif func == 4: self.releases_tiktok_creation_duration_min.slide(direction='Right', times=random.choice(range(1, 4))) elif func == 5: self.releases_tiktok_creation_duration_max.slide(direction='Left', times=random.choice(range(1, 4))) elif func == 6: self.performance_tiktok_mentions_min.slide(direction='Right', times=random.choice(range(1, 4))) elif func == 7: self.performance_tiktok_mentions_max.slide(direction='Left', times=random.choice(range(1, 3))) elif func == 8: self.engagement_tiktok_likes_min.slide(direction='Right', times=random.choice(range(1, 4))) elif func == 9: self.engagement_tiktok_likes_max.slide(direction='Left', times=random.choice(range(1, 4))) elif func == 10: self.expand_freshest_release_block().freshest_release_tiktok.select_option( random.choice(['1 Week', '4 Weeks', '8 Weeks', '12 Weeks'])) @step("Run random youtube change for artist") def random_artist_youtube_changes(self, func=None): if func is None: func = random.choice(range(1, 7)) print('Chosen function# {}'.format(func)) if func == 1: self.audience_youtube_subscribers_min.slide(direction='Right', times=random.choice(range(1, 5))) elif func == 2: self.audience_youtube_subscribers_max.slide(direction='Left', times=random.choice(range(1, 5))) elif func == 3: self.releases_youtube_min_videos.slide(direction='Right', times=random.choice(range(1, 4))) elif func == 4: self.performance_youtube_views_min.slide(direction='Right', times=random.choice(range(1, 5))) elif func == 5: self.performance_youtube_views_max.slide(direction='Left', times=random.choice(range(1, 5))) elif func == 6: self.expand_freshest_release_block().freshest_release_youtube.select_option( random.choice(['1 Week', '4 Weeks', '8 Weeks', '12 Weeks'])) @step("Run random spotify change for artist") def random_artist_spotify_changes(self, func=None): if func is None: func = random.choice(range(1, 9)) print('Chosen function# {}'.format(func)) if func == 1: self.audience_spotify_followers_min.slide(direction='Right', times=random.choice(range(1, 6))) elif func == 2: self.audience_spotify_followers_max.slide(direction='Left', times=random.choice(range(1, 6))) elif func == 3: self.releases_spotify_min_tracks.slide(direction='Right', times=random.choice(range(1, 4))) elif func == 4: self.engagement_spotify_listeners_min.slide(direction='Right', times=random.choice(range(1, 6))) elif func == 5: self.engagement_spotify_listeners_max.slide(direction='Left', times=random.choice(range(1, 6))) elif func == 6: self.engagement_spotify_popularity_min.slide(direction='Right', times=random.choice(range(1, 5))) elif func == 7: self.engagement_spotify_popularity_max.slide(direction='Left', times=random.choice(range(1, 5))) elif func == 8: self.expand_freshest_release_block().freshest_release_spotify.select_option( random.choice(['1 Week', '4 Weeks', '8 Weeks', '12 Weeks'])) @step("Run random soundcloud change for artist") def random_artist_soundcloud_changes(self, func=None): if func is None: func = random.choice(range(1, 11)) print('Chosen function# {}'.format(func)) if func == 1: self.audience_soundcloud_followers_min.slide(direction='Right', times=random.choice(range(1, 6))) elif func == 2: self.audience_soundcloud_followers_max.slide(direction='Left', times=random.choice(range(1, 6))) elif func == 3: self.releases_soundcloud_min_tracks.slide(direction='Right', times=random.choice(range(1, 4))) elif func == 4: self.performance_soundcloud_plays_min.slide(direction='Right', times=random.choice(range(1, 5))) elif func == 5: self.performance_soundcloud_plays_max.slide(direction='Left', times=random.choice(range(1, 5))) elif func == 6: self.engagement_soundcloud_likes_min.slide(direction='Right', times=random.choice(range(1, 4))) elif func == 7: self.engagement_soundcloud_likes_max.slide(direction='Left', times=random.choice(range(1, 4))) elif func == 8: self.engagement_soundcloud_comments_min.slide(direction='Right', times=random.choice(range(1, 4))) elif func == 9: self.engagement_soundcloud_comments_max.slide(direction='Left', times=random.choice(range(1, 4))) elif func == 10: self.expand_freshest_release_block().freshest_release_soundcloud.select_option( random.choice(['1 Week', '4 Weeks', '8 Weeks', '12 Weeks'])) @step("Run random tiktok change for track") def random_track_tiktok_changes(self, func=None): if func is None: func = random.choice(range(1, 10)) print('Chosen function# {}'.format(func)) if func == 1: self.audience_tiktok_views_min.slide(direction='Right', times=random.choice(range(1, 4))) elif func == 2: self.audience_tiktok_views_max.slide(direction='Left', times=random.choice(range(1, 4))) elif func == 3: self.releases_tiktok_min_creations.slide(direction='Right', times=random.choice(range(1, 7))) elif func == 4: self.performance_tiktok_likes_min.slide(direction='Right', times=random.choice(range(1, 4))) elif func == 5: self.performance_tiktok_likes_max.slide(direction='Left', times=random.choice(range(1, 4))) elif func == 6: self.engagement_tiktok_comments_min.slide(direction='Right', times=random.choice(range(1, 3))) elif func == 7: self.engagement_tiktok_comments_max.slide(direction='Left', times=random.choice(range(1, 3))) elif func == 8: self.engagement_tiktok_mentions_min.slide(direction='Right', times=random.choice(range(1, 3))) elif func == 9: self.engagement_tiktok_mentions_max.slide(direction='Left', times=random.choice(range(1, 3))) @step("Run random youtube change for track") def random_track_youtube_changes(self, func=None): if func is None: func = random.choice(range(1, 9)) print('Chosen function# {}'.format(func)) if func == 1: self.releases_youtube_min_videos.slide(direction='Right', times=random.choice(range(1, 6))) elif func == 2: self.performance_youtube_views_min.slide(direction='Right', times=random.choice(range(1, 5))) elif func == 3: self.performance_youtube_views_max.slide(direction='Left', times=random.choice(range(1, 5))) elif func == 4: self.engagement_youtube_likes_min.slide(direction='Right', times=random.choice(range(1, 5))) elif func == 5: self.engagement_youtube_likes_max.slide(direction='Left', times=random.choice(range(1, 5))) elif func == 6: self.engagement_youtube_comments_min.slide(direction='Right', times=random.choice(range(1, 4))) elif func == 7: self.engagement_youtube_comments_max.slide(direction='Left', times=random.choice(range(1, 4))) elif func == 8: self.expand_freshest_release_block().freshest_release_youtube.select_option( random.choice(['1 Week', '4 Weeks', '8 Weeks', '12 Weeks'])) @step("Run random spotify change for track") def random_track_spotify_changes(self, func=None): if func is None: func = random.choice(range(1, 9)) print('Chosen function# {}'.format(func)) if func == 1: self.audience_spotify_listeners_min.slide(direction='Right', times=random.choice(range(1, 6))) elif func == 2: self.audience_spotify_listeners_max.slide(direction='Left', times=random.choice(range(1, 6))) elif func == 3: self.performance_spotify_streams_min.slide(direction='Right', times=random.choice(range(1, 5))) elif func == 4: self.performance_spotify_streams_max.slide(direction='Left', times=random.choice(range(1, 5))) elif func == 5: self.performance_spotify_playlists_min.slide(direction='Right', times=random.choice(range(1, 4))) elif func == 6: self.performance_spotify_playlists_max.slide(direction='Left', times=random.choice(range(1, 4))) elif func == 7: self.engagement_spotify_popularity_min.slide(direction='Right', times=random.choice(range(1, 5))) elif func == 8: self.engagement_spotify_popularity_max.slide(direction='Left', times=random.choice(range(1, 5))) @step("Run random soundcloud change for track") def track_soundcloud_change(self, func): print('Chosen function# {}'.format(func)) if func == 1: self.audience_soundcloud_followers_min.slide(direction='Right', times=random.choice(range(1, 6))) elif func == 2: self.audience_soundcloud_followers_max.slide(direction='Left', times=random.choice(range(1, 6))) elif func == 3: self.performance_soundcloud_plays_min.slide(direction='Right', times=random.choice(range(1, 5))) elif func == 4: self.performance_soundcloud_plays_max.slide(direction='Left', times=random.choice(range(1, 5))) elif func == 5: self.engagement_soundcloud_likes_min.slide(direction='Right', times=random.choice(range(1, 4))) elif func == 6: self.engagement_soundcloud_likes_max.slide(direction='Left', times=random.choice(range(1, 4))) elif func == 7: self.engagement_soundcloud_comments_min.slide(direction='Right', times=random.choice(range(1, 4))) elif func == 8: self.engagement_soundcloud_comments_max.slide(direction='Left', times=random.choice(range(1, 4))) elif func == 9: self.expand_freshest_release_block().freshest_release_soundcloud.select_option( random.choice(['1 Week', '4 Weeks', '8 Weeks', '12 Weeks'])) @step("Run several random soundcloud changes for track") # approach to run several random unique changes def random_track_soundcloud_changes(self, count=1): func_set = random.choices(range(1, 10), k=count) for func in func_set: self.track_soundcloud_change(func)