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.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 RecentSearchTest(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.trackPage = TrackPage(self.driver, authorized_api) self.starredPage = StarredPage(self.driver, authorized_api) self.fake = Faker() @allure.story("https://data-analytics.atlassian.net/browse/AG-4758") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Recent Searches list after opening tracks from ApolloGo") @allure.description("User should be able to see tracks from the recent searches") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-2264," "https://data-analytics.atlassian.net/browse/AG-2297") @pytest.mark.smoke def test_recent_searches_list(self): first_query = self.fake.word() second_query = self.fake.word() self.loginPage.login_as_regular_user() last_track_name = self.searchPage.get_result_track_title(20) self.searchPage.search_for(first_query) first_track_name = self.searchPage.get_result_track_title(1) self.searchPage.open_track_page_from_results(1).click_back_button() self.searchPage.clear_search_field() first_track_recent = self.searchPage.get_result_track_title(1) last_track_name_updated = self.searchPage.get_result_track_title(20) assert_that(last_track_name_updated, "Last track in the list is updated").is_not_equal_to(last_track_name) assert_that(first_track_recent, "First track in the list is updated¬").is_equal_to(first_track_name) self.searchPage.search_for(second_query) second_track_name = self.searchPage.get_result_track_title(1) self.searchPage.open_track_page_from_results(1).click_back_button() self.searchPage.clear_search_field() second_track_recent = self.searchPage.get_result_track_title(1) assert_that(second_track_recent, "Second track in the list is updated").is_equal_to(second_track_name) # Last opened track should be the first in the search list old_first_track_title = self.searchPage.get_result_track_title(1) old_second_track = self.searchPage.get_result_track_title(2) self.searchPage.open_track_page_from_results(2).click_back_button() new_first_track_title = self.searchPage.get_result_track_title(1) assert_that(new_first_track_title, "First track in the list is updated").is_not_equal_to(old_first_track_title) assert_that(new_first_track_title, "Second track in the list is updated").is_equal_to(old_second_track) @allure.story("https://data-analytics.atlassian.net/browse/AG-4758") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Starring in recent searches") @allure.description("User should be able to star/unstar tracks in recent searches") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-2255") @pytest.mark.smoke def test_star_unstar(self): self.loginPage.login_as_regular_user() track_name = self.searchPage.get_result_track_title(1) self.searchPage.swipe_track_on_search_results_by_name(track_name).star_track_on_search_results_by_name(track_name).select_starred_tracks_tab() assert_that(self.starredPage.is_track_starred(track_name), "Verified track is added to the starred tracks screen").is_true() self.starredPage.select_search_tab() self.searchPage.swipe_track_on_search_results_by_name(track_name).unstar_track_on_search_results_by_name(track_name).select_starred_tracks_tab() assert_that( self.starredPage.is_track_unstarred(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("Cancellation of starring track") @allure.description("User should be able to open another track even if starring icon shown for different tracks") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-2254") @pytest.mark.regression def test_starring_cancellation(self): self.loginPage.login_as_regular_user() track_1 = self.searchPage.get_result_track_title_full(1) track_1_title = self.searchPage.get_result_track_title(1) track_2 = self.searchPage.get_result_track_title_full(2) self.searchPage.swipe_track_on_search_results(1) assert_that(self.searchPage.is_star_icon_displayed(track_1), "Verified star icon is displayed").is_true() self.searchPage.swipe_right_track_on_search_results(1) assert_that(self.searchPage.is_star_icon_closed(track_1), "Verified star icon is NOT displayed").is_true() self.searchPage.swipe_track_on_search_results(1) assert_that(self.searchPage.is_star_icon_displayed(track_1), "Verified star icon is displayed").is_true() self.searchPage.swipe_track_on_search_results(2) assert_that(self.searchPage.is_star_icon_closed(track_1), "Verified star icon is NOT displayed").is_true() assert_that(self.searchPage.is_star_icon_displayed(track_2), "Verified star icon is displayed").is_true() self.searchPage.open_track_page_from_results(2) assert_that(self.searchPage.is_star_icon_closed(track_2), "Verified star icon is NOT displayed").is_true() self.searchPage.open_track_page_from_results(1) assert_that(self.trackPage.is_track_page_opened(track_1_title), "Verified appropriate track page is opened").is_true() @allure.story("https://data-analytics.atlassian.net/browse/AG-7447") @allure.severity(allure.severity_level.NORMAL) @allure.title("Recent search API/UI integration") @allure.description("API and UI data for recent search list should match") @pytest.mark.smoke def test_recent_search_api_integration(self): spotify_ids = self.api.common.get_spotify_search_history_auth0("7C5f1595867c4a0f00130f9e20")["body"]["items"] ids = [item["uri"].split(":")[2] for item in spotify_ids] api_tracks = self.api.dsp.get_spotify_tracks(",".join(ids))["body"]["tracks"] self.loginPage.login_as_regular_user() ui_data = self.searchPage.get_search_results() self.log.info(api_tracks) for i in range(len(api_tracks)): if len(api_tracks[i]["artists"]) < 2: assert_that( any(api_tracks[i]["artists"][0]["name"] in element for element in ui_data), f"Artist name not in recent searches, artist {api_tracks[i]['album']['artists'][0]['name']} no " f"in {ui_data}", ).is_true() else: assert_that( any(api_tracks[i]["artists"][1]["name"] in element for element in ui_data), f"Artist name not in recent searches, artist {api_tracks[i]['album']['artists'][0]['name']} no " f"in {ui_data}", ).is_true() assert_that( any(api_tracks[i]["name"] in element for element in ui_data), f"Track names don't match, track: {api_tracks[i]['name']} not in: {ui_data}", ).is_true()