from time import sleep from behave import given, when, then from page_objects.base_screen import BaseScreen from helpers.platform.ios.actions import navigate_back_in_browser # --- Home Screen --- @given("I am on the search tab") @when("I navigate to the search tab") def step_impl(context): context.home_screen.open_search_tab(context) @given("I am on the home tab") @when("I am on the home tab") def step_impl(context): context.home_screen.go_home() @when("I navigate to the home tab") def step_impl(context): context.home_screen.open_home_tab() @when('I navigate to the playlists tab') def step_impl(context): if "sme" not in context.app_name: context.screen_location = 'Playlists tab' context.home_screen.open_playlists_tab() @when("I navigate to the songs tab") def step_impl(context): context.home_screen.open_songs_tab() @when('I navigate to the products tab') @when('I navigate to the products tab in my catalog') def step_impl(context): context.home_screen.open_products_tab() @when('I navigate to the artists tab') def step_impl(context): context.home_screen.open_artists_tab() @when('I navigate to the My Favorites screen') def step_impl(context): context.home_screen.open_my_favorites_tab() @when('I navigate to the Chart Digest screen') def step_impl(context): context.home_screen.open_chart_digest_screen() @when('I navigate to the profile screen') def step_impl(context): context.home_screen.open_profile_screen(context) @when('I select top track {number}') def step_impl(context, number): context.home_screen.select_item('track', number) @when("I change the sorting option to '{sorting_option}'") def step_impl(context, sorting_option): context.home_screen.change_sorting_option(sorting_option) @when("I change the sorting option to '{sorting_option}' " "for a period of '{period}' day") @when("I change the sorting option to '{sorting_option}' " "for a period of '{period}' days") @when("I change the sorting option to '{sorting_option}' " "for a period of '{period}' time") def step_impl(context, sorting_option, period): context.home_screen.change_sorting_option(sorting_option, period) @when('I reset all filters') def step_impl(context): context.home_screen.reset_filters() @when('I reset all applied filters using the filters panel') def step_impl(context): context.home_screen.reset_filters_via_panel() @when('I star another product from My Catalog') def step_impl(context): context.home_screen.star_another_product_from_my_catalog(context) @when('I star another artist from My Catalog') def step_impl(context): context.starred_artist_names = getattr(context, 'starred_artist_names', []) context.home_screen.star_another_artist_from_my_catalog(context) @when('I unstar the product starred from My Catalog') def step_impl(context): context.home_screen.open_product_starred_from_my_catalog(context) context.product_screen.unstar_current_product(context) # --- Search Screen --- @then('Tapping product {product} with id ' '{product_id} takes me to the product page') @when('Tapping product {product} with id ' '{product_id} takes me to the product page') def step_impl(context, product, product_id): context.search_screen.tap_product(product_id) # TODO: Temporarily disabled behind flag GO-4730 # context.product_screen.assert_all_time_streams() context.product_screen.assert_streaming_trends() @when('Tapping artist {artist} with id' ' {artist_id} takes me to the artist page') @then('Tapping artist {artist} with id' ' {artist_id} takes me to the artist page') def step_impl(context, artist, artist_id): context.artist_name = artist context.search_screen.tap_artist(artist, artist_id) @when('Tapping song {song} with id' ' {song_id} takes me to the song page') @then('Tapping song {song} with id' ' {song_id} takes me to the song page') def step_impl(context, song, song_id): context.search_screen.tap_song(song, song_id) @when('I tap the "See all" option in the Artists section') def step_impl(context): context.search_screen.tap_see_all_button(section='Artists') @when('I tap the "See all" option in the Songs section') def step_impl(context): context.search_screen.tap_see_all_button(section='Songs') @when('I tap the "See all" option in the Products section') def step_impl(context): context.search_screen.tap_see_all_button(section='Products') @when('I tap on the last artist result card') def step_impl(context): context.search_screen.tap_last_artist_result_card_button(context) @when('I tap on the last song result card') def step_impl(context): context.search_screen.tap_last_song_result_card_button(context) @when('I tap on the last product result card') def step_impl(context): context.search_screen.tap_last_product_result_card_button(context) # --- Sound Recording Screen --- @given('The active screen is the song screen') def step_impl(context): context.active_screen = 'Song Screen' @when('I tap on artist {artist} button') def step_impl(context, artist): context.sound_recording_screen.tap_artist(artist) @when('I inspect the Streaming Trend section') def step_impl(context): context.sound_recording_screen.go_to_section(context, 'Streaming Trend') @when('I inspect the POT section') def step_impl(context): context.sound_recording_screen.inspect_pot_section() @when('I filter DSoS by store "{store_name}"') def step_impl(context, store_name): context.sound_recording_screen.filter_dsos_by_store(store_name) @when('I inspect the POT table period switcher') def step_impl(context): context.sound_recording_screen.inspect_pot_period_switcher() @when('I set the POT table period to "{period_type}"') def step_impl(context, period_type): context.sound_recording_screen.select_table_period(period_type) @when('I switch the POT view to "{tab_name}"') @when('I switch the DSoS view to "{tab_name}"') def step_impl(context, tab_name): context.sound_recording_screen.switch_pot_view(context, tab_name) @when("I inspect the POT stores list") def step_impl(context): context.sound_recording_screen.verify_pot_rows_count(amount=10) @when('I tap the "Show All Items" button in the POT section') def step_impl(context): context.sound_recording_screen.tap_show_all_items_button() @when('I tap the "Show Less Items" button in the POT section') def step_impl(context): context.sound_recording_screen.tap_show_less_items_button() @when("I select a random store from the POT list that has data") @when('I select a random country from the POT list') def step_impl(context): context.sound_recording_screen.select_random_pot_store(context) @when("I select a random store from the POT list that has no data") def step_impl(context): (context.sound_recording_screen. select_random_pot_store_without_data(context)) @when('I select the "Total Streams" row from the POT list') def step_impl(context): context.sound_recording_screen.select_total_streams_in_pot_list(context) @when('I tap the store status button') def step_impl(context): context.sound_recording_screen.tap_store_status_button() @when('I inspect the TikTok Creations section') def step_impl(context): context.sound_recording_screen.go_to_section(context, 'TikTok Creations') @when('I tap the "SEE ALL TIKTOK DATA" button') def step_impl(context): context.sound_recording_screen.tap_see_all_tiktok_data_button() @when('I switch to the UGC/PGC tab') def step_impl(context): context.sound_recording_screen.tap_ugc_pgc_tab() @when('I toggle the chart to display only UGC data') def step_impl(context): context.sound_recording_screen.toggle_chart_to_ugc_only() @when('I toggle the chart to display only PGC data') def step_impl(context): context.sound_recording_screen.toggle_chart_to_pgc_only() @when('I navigate to the UGC/PGC Views section by scrolling down') def step_impl(context): context.sound_recording_screen.scroll_to_ugc_pgc_views_section() @when('I switch to the Country tab') def step_impl(context): context.sound_recording_screen.tap_country_tab() @when('I inspect the Top Playlists section') def step_impl(context): context.sound_recording_screen.go_to_section(context, 'Top Playlists') @when('I inspect the Top Markets section') def step_impl(context): if "sme" not in context.app_name: context.sound_recording_screen.go_to_section(context, 'Top Markets') @when('I inspect the Top Charts section') def step_impl(context): context.sound_recording_screen.go_to_section(context, 'Top Charts') @when("I select '{filter}' in the playlists filter") def step_impl(context, filter): context.sound_recording_screen.select_top_playlists_filter(filter) @when('I tap the information icon next to the Top Playlists title') def step_impl(context): context.sound_recording_screen.tap_top_playlists_i_icon() @when('I tap the information icon next to the Top Charts title') def step_impl(context): context.sound_recording_screen.tap_top_charts_i_icon() @when('I tap the \'SEE ALL\' button to open all playlists') def step_impl(context): context.sound_recording_screen.tap_see_all_playlists_btn() @when('I change the playlists sorting option to \'{sorting_option}\'') def step_impl(context, sorting_option): (context.sound_recording_screen. change_playlists_sorting_option(sorting_option)) @when('I filter playlists with the following criteria') @when('I filter artists with the following criteria') @when('I filter products with the following criteria') @when('I filter songs with the following criteria') def step_impl(context): context.sound_recording_screen.tap_filter_playlists_button() sleep(1) for row in context.table: action = row['Action'].strip() values = row['Values'].strip().split(", ") match action: case 'Selecting store' | 'Deselecting store': context.sound_recording_screen.filter_playlists_by_store( values) case 'Selecting types' | 'Deselecting types': context.sound_recording_screen.filter_playlists_by_types( values) case 'Markets' | 'Countries': context.sound_recording_screen.filter_playlists_by_markets( values) case 'Labels': context.sound_recording_screen.filter_playlists_by_labels( values) case 'Artists': context.sound_recording_screen.filter_playlists_by_artists( values) case _: raise ValueError(f'Unknown action: {action}') @when('I reset the playlist filters') def step_impl(context): context.sound_recording_screen.reset_playlist_filters() @when("I swipe through the spotify chart cards back to the first one") def step_impl(context): context.sound_recording_screen.swipe_back_through_spotify_chart_cards() @when('I tap the first Spotify Top Charts card') def step_impl(context): context.sound_recording_screen.tap_first_spotify_top_charts_card() @when('I tap the first Apple Top Charts card') def step_impl(context): context.sound_recording_screen.tap_first_apple_top_charts_card() @when("I change the charts sorting option to {charts_sort_option}") def step_impl(context, charts_sort_option): (context.sound_recording_screen. change_top_charts_sorting_to(charts_sort_option)) @when('I tap the information icon next to the Spotify Charts title') def step_impl(context): context.sound_recording_screen.tap_spotify_charts_i_icon() @when('I tap the information icon next to the Apple Charts title') def step_impl(context): context.sound_recording_screen.tap_apple_charts_i_icon() @when('I change Spotify Charts category to {charts_name}') def step_impl(context, charts_name): bullet_count = context.visible_chart_bullets allowed_names = ['Daily Top 200', 'Weekly Top 200'] is_two_with_allowed = bullet_count == 2 and charts_name in allowed_names valid_combo = bullet_count == 3 or is_two_with_allowed if not valid_combo: return context.sound_recording_screen.change_top_charts_category_to(context, charts_name) # --- Artist Screen --- @given('The active screen is the artist screen') def step_impl(context): context.active_screen = 'Artist Screen' @when('I tap the share button') def step_impl(context): context.artist_screen.tap_share_button() @when('I inspect the Social Followers section on the Artist screen') def step_impl(context): context.artist_screen.go_to_section(context, 'Social Followers') @when('I inspect the Top Songs section on the Artist screen') def step_impl(context): context.artist_screen.go_to_section(context, 'Top Songs') @when('I inspect the Top Playlists section on the Artist screen') def step_impl(context): context.artist_screen.go_to_section(context, 'Top Playlists') @when("I change Top Songs sorting to '{sorting_option}'") def step_impl(context, sorting_option): context.artist_screen.change_top_songs_sorting_to(sorting_option) @when("I tap the 'SEE ALL' button to open all songs") def step_impl(context): context.artist_screen.tap_see_all_songs_button() @when("I tap the Filter icon on the Top Songs page") def step_impl(context): context.artist_screen.tap_filter_icon() @when('I select the country filter option') def step_impl(context): context.artist_screen.select_country_filter() @when('I reset the filter') def step_impl(context): context.artist_screen.reset_filter() @when('I select the following countries from the market selector') def step_impl(context): countries = [row["Name"] for row in context.table] (context.artist_screen. select_countries_from_market_selector(countries)) @when('I tap on the Social Followers section on the Artist screen') def step_impl(context): context.artist_screen.open_social_followers_from_artist_screen() @when("I tap on the 'Fan Conversion Ratio' metric") def step_impl(context): context.artist_screen.tap_fan_conversion_metric() @when("I tap on the 'MANAGE LINKED ACCOUNTS' button") def step_impl(context): context.artist_screen.tap_manage_linked_accounts_button() # --- Product Screen --- @given('The active screen is the product screen') def step_impl(context): context.active_screen = 'Product Screen' @when('I inspect the Top Playlists section on the Product screen') def step_impl(context): context.product_screen.go_to_section(context, 'Top Playlists') @when('I inspect the Tracklist section on the Product screen') def step_impl(context): context.product_screen.go_to_section(context, 'Tracklist') @when('I tap on a track from the tracklist by the number {track_number}') def step_impl(context, track_number): context.product_screen.tap_song_by_number(context, int(track_number)) @then('I should be able to close the Data sources page ' 'by tapping the cross icon') def step_impl(context): context.product_screen.close_data_sources() @when('I tap Sources at the bottom of the product page') def step_impl(context): context.product_screen.navigate_to_sources() @then('I star current product') def step_impl(context): context.product_screen.star_current_product(context) @then('I unstar current product') @when('I unstar current product') def step_impl(context): context.product_screen.unstar_current_product(context) @then('I star current artist') def step_impl(context): context.starred_artist_names = getattr(context, 'starred_artist_names', []) context.artist_screen.star_current_artist(context) @then('I unstar current artist') @when('I unstar current artist') def step_impl(context): context.artist_screen.unstar_current_artist(context) # --- My Favorites --- @when('I navigate to the Songs tab on the My Favorites screen') def step_impl(context): context.home_screen.open_songs_tab() @when('I navigate to the Products tab on the My Favorites screen') def step_impl(context): context.home_screen.open_products_tab() @when('I navigate to the Artists tab on the My Favorites screen') def step_impl(context): context.home_screen.open_artists_tab() @when('I navigate to the Labels tab on the My Favorites screen') def step_impl(context): if "sme" not in context.app_name: context.home_screen.open_labels_tab() # --- Profile Screen --- @when('I tap on the Privacy Policy button') def step_impl(context): context.profile_screen.tap_privacy_policy(context) @when('I tap on the Terms and Conditions button') def step_impl(context): context.profile_screen.tap_terms_and_conditions() @when('I tap on the Notifications button and choose Songs in My Favorites') def step_impl(context): context.profile_screen.tap_notifications_and_select('songs') @when('I select a random language different from the current one') def step_impl(context): (context.profile_screen. select_random_language_different_from_current(context)) @when('I revert the app language to the default') def step_impl(context): context.profile_screen.select_default_language(context) # --- Charts Digest Screen --- @when("I tap on the '{chart_name}' chart card") def step_impl(context, chart_name): context.charts_digest_screen.tap_chart_card(chart_name) @when("I tap the information icon next to the Charts filter") def step_impl(context): context.charts_digest_screen.tap_information() @when('I tap on the market selector') def step_impl(context): context.charts_digest_screen.tap_market_selector() @when("I select '{country}' from the market selector") def step_impl(context, country): context.charts_digest_screen.select_country(country) @when("I tap on a song card number {song_number}") def step_impl(context, song_number): context.artist_screen.tap_song_number(context, int(song_number)) @when("I tap the bottom part of playlist card number {number}") def step_impl(context, number): (context.artist_screen. tap_on_bottom_part_of_playlist_card(context, int(number))) @when("I select '{chart_type_name}' chart type") def step_impl(context, chart_type_name): context.charts_digest_screen.select_chart_type(chart_type_name) @when("I scroll through the song list {times} times") def step_impl(context, times): context.charts_digest_screen.scroll_through_the_song_list(int(times)) @when("I scroll to the top of the chart screen") def step_impl(context): context.charts_digest_screen.scroll_to_the_top() @when("I filter songs by 'My Catalog'") def step_impl(context): context.charts_digest_screen.filter_songs_by_my_catalog() @when('I filter by brand {brand} in the Charts filter') def step_impl(context, brand): context.charts_digest_screen.filter_songs_by_brand(brand) # --- General --- @when('I return to the app from the browser') def step_impl(context): navigate_back_in_browser(context) @then('I should be able to navigate back to the product page ' 'by tapping the back button') @then('I should be able to navigate back to the charts page ' 'by tapping the back button') @when('I navigate back from the artist screen') @when('I navigate back to the artist screen') @when('I navigate back from the song screen') @when('I navigate back from the product screen') @then('I navigate back from the artist screen') @then('I navigate back from the playlists screen') @then('I navigate back from the product screen') @then('I navigate back to the song screen') @then('I navigate back to the charts placements') @then('I navigate back to the charts screen') @then('I should be able to navigate back') def step_impl(context): BaseScreen(context.driver).press_back_button() @when('I restart the app') def step_impl(context): BaseScreen(context.driver).restart_app() # --- My Favorites Screen --- @when('I star a product from the Recommended Products section') def step_impl(context): context.starred_product_names = getattr( context, 'starred_product_names', []) context.my_favorites_screen.star_product_from_recommended_products(context) @when('I star the first label from the Recommended Labels section') def step_impl(context): context.starred_label_names = getattr(context, 'starred_label_names', []) (context.my_favorites_screen. star_first_label_from_recommended_labels(context)) @when('I unstar all labels in My Favorites') def step_impl(context): context.my_favorites_screen.unstar_all_labels(context) @when('I unstar the first product in My Favorites and tap Undo') def step_impl(context): context.my_favorites_screen.unstar_first_product(context, undo=True) @when('I unstar the first product in My Favorites') def step_impl(context): context.my_favorites_screen.unstar_first_product(context) @when('I unstar the first artist in My Favorites and tap Undo') def step_impl(context): context.my_favorites_screen.unstar_first_artist(context, undo=True) @when('I unstar the first artist in My Favorites') def step_impl(context): context.my_favorites_screen.unstar_first_artist(context)