import logging import random import unittest import allure import pytest from assertpy import assert_that from faker import Faker from ui_automation_framework.utils import AppConfig from ui_automation_framework.utils import logger as cl from app.src.helpers.api_data_provider import ApiDataProvider from app.src.pages.chart_digest_page import ChartDigestPage from app.src.pages.login_page import LoginPage from app.src.pages.notifications_page import NotificationsPage from app.src.pages.profile_page import ProfilePage from app.src.pages.search_page import SearchPage from app.src.pages.starred_page import StarredPage from app.src.pages.tiktok_page import TiktokPage from app.src.pages.track_page import TrackPage from app.src.pages.track_page_info import TrackPageInfo from app.src.pages.youtube_page import YoutubePage log = cl.Logger(logging.DEBUG) @pytest.mark.usefixtures("set_up", "one_time_set_up", "authorized_api") class TrackInfoTest(unittest.TestCase): @pytest.fixture(autouse=True) def classSetup(self, authorized_api): self.api = authorized_api self.loginPage = LoginPage(self.driver, authorized_api) self.chartDigestPage = ChartDigestPage(self.driver, authorized_api) self.notificationsPage = NotificationsPage(self.driver) self.starredPage = StarredPage(self.driver, authorized_api) self.searchPage = SearchPage(self.driver, authorized_api) self.trackPage = TrackPage(self.driver, authorized_api) self.trackPageInfo = TrackPageInfo(self.driver, authorized_api) self.profilePage = ProfilePage(self.driver) self.youtubePage = YoutubePage(self.driver) self.tiktokPage = TiktokPage(self.driver) self.api_helper = ApiDataProvider(authorized_api) self.fake = Faker() @allure.story("https://data-analytics.atlassian.net/browse/AG-5263") @allure.severity(allure.severity_level.NORMAL) @allure.title("Star/Un-star spotify track") @allure.description("User should be able to star and un star track from the track page") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-1020", "https://data-analytics.atlassian.net/browse/AG-1021") @pytest.mark.smoke def test_star_unstar_spotify(self): track_position_in_full_charts = 3 self.loginPage.login_as_regular_user().select_chart_digest_tab() self.chartDigestPage.open_full_charts() track_name = self.chartDigestPage.get_full_charts_track_title(track_position_in_full_charts) self.chartDigestPage.open_track_from_full_charts(track_position_in_full_charts) assert_that(self.trackPage.is_track_page_opened(track_name), "Verified track page is opened") self.trackPage.star_track().click_back_button().click_back_button().select_starred_tracks_tab() assert_that(self.starredPage.is_track_starred(track_name), "Verified track is added to starred tracks") self.starredPage.select_chart_digest_tab() self.chartDigestPage.open_full_charts().open_track_from_full_charts(track_position_in_full_charts) self.trackPage.unstar_track().click_back_button().click_back_button().select_starred_tracks_tab() assert_that(self.starredPage.is_track_unstarred(track_name), "Verified track is removed from starred tracks") @allure.story("https://data-analytics.atlassian.net/browse/AG-5263") @allure.severity(allure.severity_level.NORMAL) @allure.title("Star/Un-star apple track") @allure.description("User should be able to star and un star track from the track page") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-961", "https://data-analytics.atlassian.net/browse/AG-962") @pytest.mark.smoke def test_star_unstar_apple(self): track_position_in_full_charts = 3 for track in self.api.apollo.get_starred_tracks()["body"]: self.api.apollo.delete_v1_starred_tracks(track["isrc"]) self.loginPage.login_as_regular_user().select_chart_digest_tab() self.chartDigestPage.select_dsp("APPLE MUSIC").open_full_charts() track_name = self.chartDigestPage.get_full_charts_track_title(track_position_in_full_charts) self.chartDigestPage.open_track_from_full_charts(track_position_in_full_charts) assert_that(self.trackPage.is_track_page_opened(track_name), "Verified track page is opened").is_true() self.trackPage.star_track().click_back_button().click_back_button().select_starred_tracks_tab() assert_that(self.starredPage.is_track_starred(track_name), "Verified track is added to starred tracks").is_true() self.starredPage.select_chart_digest_tab() self.chartDigestPage.select_dsp("APPLE MUSIC").open_full_charts().open_track_from_full_charts(track_position_in_full_charts) self.trackPage.unstar_track().click_back_button().click_back_button().select_starred_tracks_tab() assert_that(self.starredPage.is_track_unstarred(track_name), "Verified track is removed from starred tracks").is_true() @allure.story("https://data-analytics.atlassian.net/browse/AG-5263," "https://data-analytics.atlassian.net/browse/AG-9803") @allure.severity(allure.severity_level.NORMAL) @allure.title("Tap area of track info") @allure.description("User should be able to see track info") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-968," "https://data-analytics.atlassian.net/browse/AG-973," "https://data-analytics.atlassian.net/browse/AG-974," "https://data-analytics.atlassian.net/browse/AG-9784,") @pytest.mark.smoke def test_spotify_track_info(self): track_with_youtube_data_only = None track_with_tiktok_data_only = None track_with_youtube_and_tiktok = None track_without_youtube_and_tiktok = None tracklist = self.api.apollo.get_spotify_playlist_tracklist(random.choice(list(AppConfig.get("playlists_spotify").keys())), "us", "current_position", 100)["body"]["items"] for k, v in enumerate(tracklist): isrc = tracklist[k]["isrc"] youtube_data = self.api.gate.get_youtube_data( "group_by=date,video_id", "sort_by=-views", "limit=10", "views=1", "content_type=partner_uploaded,premium_ugc", "expand_to=related_isrcs", f"isrc={isrc}", )[ "body" ]["items"] tiktok_data = [market["code"] for market in self.api.gate.get_all_available_markets_tiktok(isrc)] if all([youtube_data, tiktok_data]): if not track_with_youtube_and_tiktok: track_with_youtube_and_tiktok = tracklist[k]["name"] + " " + tracklist[k]["artists"][0] log.debug(f"track_with_youtube_and_tiktok: {track_with_youtube_and_tiktok}") elif not any([youtube_data, tiktok_data]): if not track_without_youtube_and_tiktok: track_without_youtube_and_tiktok = tracklist[k]["name"] log.debug(f"track_without_youtube_and_tiktok: {track_without_youtube_and_tiktok}") elif youtube_data and not tiktok_data: if not track_with_youtube_data_only: track_with_youtube_data_only = tracklist[k]["name"] + " " + tracklist[k]["artists"][0] log.debug(f"track_with_youtube_data_only: {track_with_youtube_data_only}") elif tiktok_data and not youtube_data: if not track_with_tiktok_data_only: track_with_tiktok_data_only = tracklist[k]["name"] + " " + tracklist[k]["artists"][0] log.debug(f"track_with_tiktok_data_only: {track_with_tiktok_data_only}") elif all( [ track_with_youtube_data_only, track_with_tiktok_data_only, track_with_youtube_and_tiktok, track_without_youtube_and_tiktok, ] ): break self.loginPage.login_as_regular_user() if track_without_youtube_and_tiktok: self.searchPage.search_for(track_without_youtube_and_tiktok).open_track_page_from_results(1) assert_that(self.trackPage.is_track_page_opened(track_without_youtube_and_tiktok), "Verified track page is opened").is_true() assert_that(self.trackPage.is_youtube_and_tiktok_videos_not_available()).is_true() self.trackPage.open_track_info() assert_that(self.trackPageInfo.is_track_info_opened(), "Verified track info is opened").is_true() assert_that(self.trackPageInfo.has_label()).is_true() assert_that(self.trackPageInfo.has_released_date()).is_true() assert_that(self.trackPageInfo.bn_spotify_partner.is_visible()).is_true() assert_that(self.trackPageInfo.bn_apple_partner.is_visible()).is_true() self.trackPageInfo.close().click_back_button() if track_with_youtube_and_tiktok: self.searchPage.clear_search_field().search_for(track_with_youtube_and_tiktok).open_track_page_from_results(1) assert_that(self.trackPage.is_track_page_opened(track_with_youtube_and_tiktok), "Verified track page is opened").is_true() self.trackPage.open_track_info() assert_that(self.trackPageInfo.is_track_info_opened(), "Verified track info is opened").is_true() assert_that(self.trackPageInfo.has_label()).is_true() assert_that(self.trackPageInfo.has_released_date()).is_true() self.trackPageInfo.close() assert_that(self.trackPage.bn_youtube.is_visible()).is_true() assert_that(self.trackPage.bn_tiktok.is_visible()).is_true() self.trackPage.click_back_button() if track_with_youtube_data_only: self.searchPage.clear_search_field().search_for(track_with_youtube_data_only).open_track_page_from_results(1) assert_that(self.trackPage.is_track_page_opened(track_with_youtube_data_only), "Verified track page is opened").is_true() self.trackPage.open_track_info() assert_that(self.trackPageInfo.is_track_info_opened(), "Verified track info is opened").is_true() assert_that(self.trackPageInfo.has_label()).is_true() assert_that(self.trackPageInfo.has_released_date()).is_true() self.trackPageInfo.close() assert_that(self.trackPage.bn_youtube.is_visible()).is_true() assert_that(self.trackPage.bn_tiktok.is_visible()).is_false() self.trackPage.bn_youtube.click() assert_that(self.youtubePage.lb_main_title.is_visible()).is_true() self.youtubePage.click_back_button().click_back_button() if track_with_tiktok_data_only: self.searchPage.clear_search_field().search_for(track_with_tiktok_data_only).open_track_page_from_results(1) assert_that(self.trackPage.is_track_page_opened(track_with_tiktok_data_only), "Verified track page is opened").is_true() self.trackPage.open_track_info() assert_that(self.trackPageInfo.is_track_info_opened(), "Verified track info is opened").is_true() assert_that(self.trackPageInfo.has_label()).is_true() assert_that(self.trackPageInfo.has_released_date()).is_true() self.trackPageInfo.close() assert_that(self.trackPage.bn_youtube.is_visible()).is_false() assert_that(self.trackPage.bn_tiktok.is_visible()).is_true() self.trackPage.bn_tiktok.click() assert_that(self.tiktokPage.bn_tiktok_kpis_i_icon.is_visible()).is_true() self.tiktokPage.click_back_button().click_back_button() random_track = random.choice( [ track_with_youtube_data_only, track_with_tiktok_data_only, track_with_youtube_and_tiktok, track_without_youtube_and_tiktok, ] ) self.searchPage.clear_search_field().search_for(random_track).open_track_page_from_results(1) assert_that(self.trackPage.is_track_page_opened(random_track), "Verified track page is opened").is_true() self.trackPage.open_track_info() assert_that(self.trackPageInfo.is_track_info_opened(), "Verified track info is opened").is_true() assert_that(self.trackPageInfo.is_partner_button_clickable("spotify")).is_true() @allure.story("https://data-analytics.atlassian.net/browse/AG-5263," "https://data-analytics.atlassian.net/browse/AG-9803") @allure.severity(allure.severity_level.NORMAL) @allure.title("Tap area of track info") @allure.description("User should be able to see track info") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-968," "https://data-analytics.atlassian.net/browse/AG-973," "https://data-analytics.atlassian.net/browse/AG-974," "https://data-analytics.atlassian.net/browse/AG-9784,") @pytest.mark.smoke def test_apple_track_info(self): track_with_youtube_data = None track_without_youtube_data = None tracklist = self.api.apollo.get_v1_apple_music_playlist_tracklist(random.choice(list(AppConfig.get("playlists_apple").keys())), "us", "current_position", 100)["body"]["items"] for k, v in enumerate(tracklist): isrc = tracklist[k]["isrc"] youtube_data = self.api.gate.get_youtube_data( "group_by=date,video_id", "sort_by=-views", "limit=10", "views=1", "content_type=partner_uploaded,premium_ugc", "expand_to=related_isrcs", f"isrc={isrc}", ) if not all([track_with_youtube_data, track_without_youtube_data]): if youtube_data["body"]["items"]: track_with_youtube_data = tracklist[k]["name"] + " " + tracklist[k]["artists"][0] else: track_without_youtube_data = tracklist[k]["name"] log.debug(f"track_with_youtube_data: {track_with_youtube_data}") log.debug(f"track_without_youtube_data: {track_without_youtube_data}") self.loginPage.login_as_regular_user() if track_without_youtube_data: self.searchPage.search_for(track_without_youtube_data).open_track_page_from_results(1) assert_that(self.trackPage.is_track_page_opened(track_without_youtube_data), "Verified track page is opened").is_true() assert_that(self.trackPage.is_youtube_and_tiktok_videos_not_available()).is_true() self.trackPage.open_track_info() assert_that(self.trackPageInfo.is_track_info_opened(), "Verified track info is opened").is_true() assert_that(self.trackPageInfo.has_label()).is_true() assert_that(self.trackPageInfo.has_released_date()).is_true() assert_that(self.trackPageInfo.bn_spotify_partner.is_visible()).is_true() assert_that(self.trackPageInfo.bn_apple_partner.is_visible()).is_true() self.trackPageInfo.close().click_back_button() if not track_without_youtube_data: self.searchPage.search_for(track_with_youtube_data).open_track_page_from_results(1) else: self.searchPage.clear_search_field().search_for(track_with_youtube_data).open_track_page_from_results(1) # assert_that(self.trackPage.is_track_page_opened(track_with_youtube_data), "Verified track page is opened").is_true() self.trackPage.open_track_info() assert_that(self.trackPageInfo.is_track_info_opened(), "Verified track info is opened").is_true() assert_that(self.trackPageInfo.has_label()).is_true() assert_that(self.trackPageInfo.has_released_date()).is_true() self.trackPageInfo.close() self.trackPage.bn_youtube.click() assert_that(self.youtubePage.lb_main_title.is_visible()).is_true() self.youtubePage.click_back_button() self.trackPage.open_track_info() assert_that(self.trackPageInfo.is_partner_button_clickable("apple")).is_true() @allure.story("https://data-analytics.atlassian.net/browse/AG-6513") @allure.severity(allure.severity_level.NORMAL) @allure.title("Back to the beginning of the page") @allure.description("Page should be scrolled to the beginning by tap on header") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-1016") @pytest.mark.regression def test_back_to_the_beginning(self): self.loginPage.login_as_regular_user().select_chart_digest_tab() self.chartDigestPage.open_full_charts() track_name = self.chartDigestPage.get_full_charts_track_title(1) self.chartDigestPage.open_track_from_full_charts(1) assert_that(self.trackPage.is_track_page_opened(track_name), "Verified track page is opened").is_true() self.trackPage.scroll_down().click_header(track_name) assert_that(self.trackPage.is_track_page_top_section_displayed(), "Verified track page is at the beginning").is_true() @allure.story("https://data-analytics.atlassian.net/browse/AG-6513") @allure.severity(allure.severity_level.NORMAL) @allure.title("Return from the track page") @allure.description("User should be directed to the previous screen") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-978") @pytest.mark.regression def test_navigation_to_the_previous_page(self): self.loginPage.login_as_notifications_user().select_starred_tracks_tab() self.starredPage.click_on_starred_track_by_position(1).click_back_button() assert_that(self.starredPage.is_7_days_title_displayed(), "Starred page is opened").is_true() self.starredPage.select_chart_digest_tab() self.chartDigestPage.click_entries_track(1).click_back_button() assert_that(self.chartDigestPage.is_entries_section_displayed(), "Chart digest page is opened").is_true() self.chartDigestPage.select_notifications_tab() self.notificationsPage.click_on_notification(1).click_back_button() assert_that(self.notificationsPage.lb_title.is_present(), "Notifications page is opened").is_true() @allure.story("https://data-analytics.atlassian.net/browse/AG-6513") @allure.severity(allure.severity_level.NORMAL) @allure.title("Track info after changing market") @allure.description("Stream info should be accordingly to the market selected") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-1014") @pytest.mark.regression def test_track_data_after_changing_market(self): market_without_spotify_data = "China" market_code_without_spotify_data = "CN" tracks_witout_apple_on_china = AppConfig.get("track_info_starred_tracks") for k, v in tracks_witout_apple_on_china.items(): self.api_helper.star_track_spotify(k, v) try: self.loginPage.login_as_regular_user() self.profilePage.open_profile_screen_and_select_market(market_without_spotify_data).select_starred_tracks_tab() for i in range(1, self.starredPage.get_starred_tracks_count()): self.starredPage.click_on_starred_track_by_position(i) assert_that( self.trackPage.is_market_selected(market_code_without_spotify_data, market_without_spotify_data), "Market data isn't accordingly to the market selected", ).is_true() self.trackPage.click_back_button() finally: for k, v in tracks_witout_apple_on_china.items(): self.api_helper.unstar_track(k)