import logging import unittest import allure import pytest from assertpy import assert_that from faker import Faker from ui_automation_framework.utils import logger as cl from app.src.helpers.api_data_provider import ApiDataProvider from app.src.helpers.data_formaters import DataFormatter from app.src.pages.login_page import LoginPage from app.src.pages.search_page import SearchPage from app.src.pages.starred_page import StarredPage from app.src.pages.track_page import TrackPage @pytest.mark.usefixtures("set_up", "one_time_set_up", "authorized_api") class StarredTracksTest(unittest.TestCase): log = cl.Logger(logging.DEBUG) @pytest.fixture(autouse=True) def classSetup(self, authorized_api): self.api = authorized_api self.loginPage = LoginPage(self.driver, authorized_api) self.searchPage = SearchPage(self.driver, authorized_api) self.starredPage = StarredPage(self.driver, authorized_api) self.trackPage = TrackPage(self.driver, authorized_api) self.data_provider = ApiDataProvider(authorized_api) self.fake = Faker() @allure.story("https://data-analytics.atlassian.net/browse/AG-4758") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Un-starring track") @allure.description("User should be able to unstar track from the starred screen") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-222") @pytest.mark.smoke def test_unstarring_track(self): query = "KKK Took My Baby" self.loginPage.login_as_regular_user() self.searchPage.search_for(query) search_track_name = self.searchPage.get_result_track_title(1) self.searchPage.swipe_track_on_search_results(1).star_on_search_results(1).select_starred_tracks_tab() assert_that(self.starredPage.is_track_starred(search_track_name), "Verified track is added to the starred tracks screen").is_true() self.starredPage.unstar_track(search_track_name) assert_that( self.starredPage.is_track_unstarred(search_track_name), "Verified track is removed from the starred tracks screen", ).is_true() @allure.story("https://data-analytics.atlassian.net/browse/AG-4758") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Navigation to Track details screen") @allure.description("User should be able to open the track page from the starred screen") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-220") @pytest.mark.smoke def test_track_page_opening(self): query = "i wanna be sedated" self.loginPage.login_as_regular_user() self.searchPage.search_for(query) search_track_name = self.searchPage.get_result_track_title(1) self.searchPage.swipe_track_on_search_results(1).star_on_search_results(1).select_starred_tracks_tab() assert_that(self.starredPage.is_track_starred(search_track_name), "Verified track is added to the starred tracks screen").is_true() self.starredPage.click_on_starred_track(search_track_name) assert_that(self.trackPage.is_track_page_opened(search_track_name), "Verifying valid track page is opened").is_true() self.trackPage.click_back_button() self.starredPage.unstar_track(search_track_name) @allure.story("https://data-analytics.atlassian.net/browse/AG-4758") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Navigation to Track details screen") @allure.description("User should be able to open the track page from the starred screen") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-220") @pytest.mark.smoke def test_infinite_scroll(self): self.loginPage.login_as_notifications_user() self.searchPage.select_starred_tracks_tab() last_starred_track = self.starredPage.get_starred_track_title(19) self.starredPage.scroll_on_the_starred_tracks() new_last_starred_track = self.starredPage.get_starred_track_title(19) assert_that(new_last_starred_track, "Page scrolling").is_not_equal_to(last_starred_track) @allure.story("https://data-analytics.atlassian.net/browse/AG-6511") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Back to the beginning") @allure.description("User should be directed back to the beginning by tap on header") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-229") @pytest.mark.regression def test_back_to_the_beginning(self): self.loginPage.login_as_notifications_user() self.searchPage.select_starred_tracks_tab() self.starredPage.scroll_on_the_starred_tracks().click_on_header() assert_that(self.starredPage.is_7_days_title_displayed(), "Verified screen is on beginning").is_true() @allure.story("https://data-analytics.atlassian.net/browse/AG-6511") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Correctness of streams for starred tracks") @allure.description("Streams number should be the same as on the track page") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-2950") @pytest.mark.regression def test_streams_info(self): self.loginPage.login_as_notifications_user().select_starred_tracks_tab() streams_sum_starred_tracks = self.starredPage.get_streams_number(1) self.starredPage.click_on_starred_track_by_position(1) streams_sum_track_page = self.trackPage.get_global_market_card_content()[15] assert_that(streams_sum_track_page, "Verified streams sum on starred tracks and tracks page match").is_equal_to(streams_sum_starred_tracks) @allure.story("https://data-analytics.atlassian.net/browse/AG-6511") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Correctness of primary sorting by streams. Empty State") @allure.description("Primary sorting is by streams count. Search for tracks button redirects to page on empty state") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-233" "https://data-analytics.atlassian.net/browse/AG-212 " "https://data-analytics.atlassian.net/browse/AG-4300") @pytest.mark.regression def test_tracks_sorting(self): # list contains two positions with streams numbers and two for alphabetical sorting tracks = ["Watermelon Sugar", "Say So", "After Party", "YAYA"] 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_starred_tracks_tab() self.starredPage.unstar_all() assert_that(self.starredPage.is_search_for_tracks_button_displayed(), "Empty state is present").is_true() self.starredPage.click_search_for_tracks_btn() assert_that(self.searchPage.is_recent_search_displayed(), "User is redirected to the search screen").is_true() for track in tracks: self.searchPage.search_for(track).swipe_track_on_search_results(1).star_on_search_results(1).clear_search_field() self.searchPage.select_starred_tracks_tab() for i in range(len(tracks)): track_name = self.starredPage.get_starred_track_title(i + 1) assert_that(track_name).contains(tracks[i]) @allure.story("https://data-analytics.atlassian.net/browse/AG-6511") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Correctness of dates") @allure.description("Checking dates format and calculation") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-2964" "https://data-analytics.atlassian.net/browse/AG-2967") @pytest.mark.regression def test_dates_format(self): track_data = self.data_provider.get_top_charts_spotify_track_data() track_name = track_data[0] isrc = track_data[1] try: self.loginPage.login_as_regular_user() self.searchPage.search_for(track_name).swipe_track_on_search_results(1).star_on_search_results(1).select_starred_tracks_tab() api_dates = self.data_provider.get_dates_range_from_api_formatted(isrc) track_dates = self.starredPage.get_dates_range(track_name) assert_that(track_dates, "Verified dates are matching and in correct format").is_equal_to(api_dates) finally: self.api.apollo.delete_v1_starred_tracks(isrc) @allure.story("https://data-analytics.atlassian.net/browse/AG-7447") @allure.severity(allure.severity_level.NORMAL) @allure.title("Starred tracks API/UI integration") @allure.description("API and UI data for starred tracks should match") @pytest.mark.smoke def test_starred_tracks_api_integration(self): tracks = ["Dakiti", "Dynamite"] api_data_with_uris = self.api.apollo.get_starred_tracks()["body"] try: self.loginPage.login_as_regular_user().select_search_tab() for track in tracks[:-1]: self.searchPage.search_for(track).swipe_track_on_search_results(1).star_on_search_results(1).clear_search_field() else: self.searchPage.search_for(tracks[-1]).swipe_track_on_search_results(1).star_on_search_results(1) self.searchPage.select_starred_tracks_tab() ui_data = self.starredPage.get_starred_tracks_data() for item in api_data_with_uris: assert item["uri"] != "undefined", "Wrong uri for a starred track" api_data = self.api.apollo.get_starred_tracks_detailed("amazon,apple,spotify", "global", 0, 20)["body"]["items"] isrcs = [i["isrc"] for i in api_data] for i in range(len(api_data)): assert api_data[i]["extra_data"]["artists"][0]["name"] in ui_data[i], "Artist name don't match with API" assert api_data[i]["extra_data"]["name"] in ui_data[i], "Track name don't match with API" if DataFormatter.round_streams(api_data[i]["streams"]) == "0": assert_that(ui_data[i], "Streams are matching with API").contains("N/A") else: assert_that(ui_data[i], "Streams are matching with API").contains(DataFormatter.round_streams(api_data[i]["streams"]).upper()) finally: for isrc in isrcs: self.api.apollo.delete_v1_starred_tracks(f"{isrc}")