import logging import time import unittest import allure import pytest from assertpy import assert_that from ui_automation_framework.core import TestStatus from ui_automation_framework.utils import AppConfig from ui_automation_framework.utils import logger as cl from app.src.pages.account_page import AccountPage from app.src.pages.album_page import AlbumPage from app.src.pages.amplitude_helper import AmplitudeHelper from app.src.pages.artist_page import ArtistPage from app.src.pages.chart_digest import ChartDigestPage from app.src.pages.global_search import GlobalSearch from app.src.pages.login_page import LoginPage from app.src.pages.spotify_playlist_page import SpotifyPlaylistPage from app.src.pages.track_page import TrackPage @pytest.mark.usefixtures("set_up", "one_time_set_up") class Amplitude(unittest.TestCase): log = cl.Logger(logging.DEBUG) SEARCH_VALUE = "top" @pytest.fixture(autouse=True) def classSetup(self): self.log = cl.Logger(logging.DEBUG) self.loginPage = LoginPage(self.driver) self.ts = TestStatus(self.driver) self.track_page = TrackPage(self.driver) self.amplitude_helper = AmplitudeHelper(self.driver) self.chart_digest = ChartDigestPage(self.driver) self.global_search = GlobalSearch(self.driver) self.spotify_playlist_page = SpotifyPlaylistPage(self.driver) self.artist_page = ArtistPage(self.driver) self.album_page = AlbumPage(self.driver) self.account_page = AccountPage(self.driver) @allure.issue("https://data-analytics.atlassian.net/browse/AP-8965") @pytest.mark.flaky(reruns=0) @allure.story("AP-2236") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-2127] Amplitude Events: top menu tracking (search and markets)") @allure.description("""TC Verifies header menu markets change and search functionality""") def test_top_header_menu_search_and_markets(self): self.loginPage.login_with_worker() self.chart_digest.is_opened() events = self.amplitude_helper.wait_and_get_amplitude_events(2) self.amplitude_helper.is_initializer_event(events[0]) self.amplitude_helper.verify_event_user_properties(events[0]) # step 1 self.track_page.select_market(AppConfig.get("market")["us"]["name"]) self.chart_digest.is_opened() events = self.amplitude_helper.wait_and_get_amplitude_events(3, False) self.amplitude_helper.verify_for_event_type(events[0], self.amplitude_helper.TOP_HEADER_MARKET["event_type"]) # step 2 self.track_page.select_market(AppConfig.get("market")["global"]["name"]) events = self.amplitude_helper.wait_and_get_amplitude_events(3, False) self.amplitude_helper.verify_for_event_type(events[0], self.amplitude_helper.TOP_HEADER_MARKET["event_type"]) # step 3 self.global_search.put_focus_to_the_search_field() self.global_search.enter_search_value(self.SEARCH_VALUE) self.global_search.verify_all_tabs_are_present() # step 4 self.global_search.open_tab(self.global_search.TRACKS) self.global_search.navigate_from_tab_to_element("track") events = self.amplitude_helper.wait_and_get_amplitude_events(2) self.amplitude_helper.verify_for_event_type(events[0], self.amplitude_helper.SEARCH_RESULTS["event_type"]) assert_that(events[0]["event_properties"]["search_result_type"]).is_equal_to(self.amplitude_helper.SEARCH_RESULTS["search_result_type_track"]) track_id = self.track_page.get_track_id_from_url() assert_that(events[0]["event_properties"]["result_id"]).is_equal_to(track_id) self.amplitude_helper.verify_for_event_type(events[1], self.amplitude_helper.TRACK_PAGE["event_type"]) assert_that(events[1]["event_properties"]["dsp_type"]).is_equal_to(self.amplitude_helper.TRACK_PAGE["dsp_type_spotify"]) # step 5 # playlist self.global_search.put_focus_to_the_search_field() self.global_search.enter_search_value(self.SEARCH_VALUE) time.sleep(10) self.global_search.open_tab(self.global_search.PLAYLISTS) self.global_search.navigate_from_tab_to_element("playlist") time.sleep(15) self.spotify_playlist_page.playlist_title_is_present() events = self.amplitude_helper.get_amplitude_events() self.amplitude_helper.verify_for_event_type(events[0], self.amplitude_helper.SEARCH_RESULTS["event_type"]) assert_that(events[0]["event_properties"]["search_result_type"]).is_equal_to(self.amplitude_helper.SEARCH_RESULTS["search_result_type_playlist"]) playlist_id = self.spotify_playlist_page.get_playlist_id_from_url() assert_that(events[0]["event_properties"]["result_id"]).is_equal_to(playlist_id) self.amplitude_helper.verify_for_event_type(events[1], self.amplitude_helper.PLAYLIST_PAGE["event_type"]) assert_that(events[1]["event_properties"]["dsp_type"]).is_equal_to(self.amplitude_helper.PLAYLIST_PAGE["dsp_type_spotify"]) # artist self.global_search.put_focus_to_the_search_field() self.global_search.enter_search_value(self.SEARCH_VALUE) time.sleep(10) self.global_search.open_tab(self.global_search.ARTISTS) self.global_search.navigate_from_tab_to_element("artist") events = self.amplitude_helper.wait_and_get_amplitude_events(2) self.amplitude_helper.verify_for_event_type(events[0], self.amplitude_helper.SEARCH_RESULTS["event_type"]) assert_that(events[0]["event_properties"]["search_result_type"]).is_equal_to(self.amplitude_helper.SEARCH_RESULTS["search_result_type_artist"]) artist_id = self.artist_page.get_artist_id_from_url() assert_that(events[0]["event_properties"]["result_id"]).is_equal_to(artist_id) self.amplitude_helper.verify_for_event_type(events[1], self.amplitude_helper.ARTIST_PAGE["event_type"]) # album self.global_search.put_focus_to_the_search_field() self.global_search.enter_search_value(self.SEARCH_VALUE) time.sleep(10) self.global_search.open_tab(self.global_search.ALBUMS) self.global_search.navigate_from_tab_to_element("album") events = self.amplitude_helper.wait_and_get_amplitude_events(2) self.amplitude_helper.verify_for_event_type(events[0], self.amplitude_helper.SEARCH_RESULTS["event_type"]) assert_that(events[0]["event_properties"]["search_result_type"]).is_equal_to(self.amplitude_helper.SEARCH_RESULTS["search_result_type_album"]) album_id = self.album_page.get_album_id_from_url() assert_that(events[0]["event_properties"]["result_id"]).is_equal_to(album_id) self.amplitude_helper.verify_for_event_type(events[1], self.amplitude_helper.ALBUM_PAGE["event_type"]) # account self.global_search.put_focus_to_the_search_field() self.global_search.enter_search_value(self.SEARCH_VALUE) time.sleep(10) self.global_search.open_tab(self.global_search.ACCOUNTS) self.global_search.navigate_from_tab_to_element("account") events = self.amplitude_helper.wait_and_get_amplitude_events(2) self.amplitude_helper.verify_for_event_type(events[0], self.amplitude_helper.SEARCH_RESULTS["event_type"]) assert_that(events[0]["event_properties"]["search_result_type"]).is_equal_to(self.amplitude_helper.SEARCH_RESULTS["search_result_type_account"]) account_id = self.account_page.get_account_id_from_url() assert_that(events[0]["event_properties"]["result_id"]).is_equal_to(account_id) self.amplitude_helper.verify_for_event_type(events[1], self.amplitude_helper.ACCOUNT_PAGE["event_type"]) # step 6 self.global_search.navigate_to_chart_digest_using_logo() self.chart_digest.is_opened() events = self.amplitude_helper.wait_and_get_amplitude_events(2) self.amplitude_helper.verify_for_event_type(events[0], self.amplitude_helper.LOGO["event_type"]) self.amplitude_helper.verify_for_event_type(events[1], self.amplitude_helper.CHARTS_DIGEST_PAGE["event_type"])