import unittest import allure import pytest from assertpy import assert_that from parameterized import parameterized from ui_automation_framework.core import TestStatus from ui_automation_framework.utils import AppConfig from app.api_client import ApiClient from app.mysql_db_client_custom import MySqlClient from app.src.pages.amazon_playlist_page import AmazonPlaylistPage from app.src.pages.login_page import LoginPage from app.src.pages.position_playlist_popup import PositionPlaylistPopup from app.src.pages.top_charts_page import TopChartsPage from app.src.pages.track_page import TrackPage from app.src.pages.tt_dashboard_pot_popup import TTDashboardPOTPopup @pytest.mark.usefixtures("set_up", "one_time_set_up") class DeepLinkingTrackPageTest(unittest.TestCase): @pytest.fixture(autouse=True) def classSetup(self): self.loginPage = LoginPage(self.driver) self.tp = TrackPage(self.driver) self.pip = PositionPlaylistPopup(self.driver) self.topChartsPage = TopChartsPage(self.driver) self.tt_dashboard_potp = TTDashboardPOTPopup(self.driver) self.amazon_playlist = AmazonPlaylistPage(self.driver) self.api_client = ApiClient() self.sql_client = MySqlClient() self.ts = TestStatus(self.driver) @parameterized.expand([("spotify", "playlists", "current"), ("apple", "playlists", "current"), ("apple", "stations", "current"), ("amazon", "playlists", "current"), ("spotify", "playlists", "past"), ("apple", "playlists", "past")]) @allure.story("AP-8356") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-8002][Amazon Playlists] [Track page] The popover on Playlists/Stations icon verification.") @allure.description("TC verifies the popover with the playlist metadata on Playlists/Stations icons that was added instead of clickable DSP icon.") def test_td_amazon_popover_verification(self, dsp, entity, tab): self.loginPage.login_with_worker() self.tp.select_market(AppConfig.get("market")["global"]["name"]) self.tp.open_spotify_track_page(AppConfig.get("track57")["id"]) if tab == "past": self.tp.td_switch_to_past_playlists_tab() self.tp.td_change_dsp(AppConfig.get("dsp")[dsp]) if entity != "playlists": self.tp.td_change_entities(entity) # steps 1-2, 5-6, 9-11, 14 self.verify_popover(dsp, entity) @allure.step("TP - TD - verify popover") def verify_popover(self, dsp, entity): loc = "//*[@id='popover']" loc_playlist = "(//*[contains(@href, '/playlist/')])[1]" loc_dsp_icon = f"//*[@id='popover']//../*[contains(@class, 'icon-{dsp}')]/parent::a" loc_details = "(//*[contains(@id, 'table-cell-position')])[1]" if dsp == "apple" and entity == "stations": self.tp.td_cps_tab_sort_by_column("selected-track-streams-7-days") loc_playlist = "(//*[contains(@id, 'Entity-')]//../span)[1]" playlist = self.tp.get_element(loc_playlist, "xpath") playlist_name = self.tp.get_text(element=playlist) type_text = "Type" entity_text = entity.upper()[:-1] owner_text = {"spotify": "Spotify", "apple": "Apple Curators", "amazon": "Amazon Curators"} spotify_text = f"""{playlist_name} By Spotify {owner_text[dsp]} {type_text} {entity_text}""" apple_text = f"""{playlist_name} {owner_text[dsp]} {type_text} {entity_text}""" amazon_text = f"""{playlist_name} {owner_text[dsp]} {type_text} {entity_text}""" text_exp = {"spotify": spotify_text, "apple": apple_text, "amazon": amazon_text} self.tp.hover_on_element(element=playlist) popover_text = self.tp.get_text(loc, "xpath") assert_that(len(popover_text)).is_greater_than(0) assert_that(self.tp.is_element_displayed(loc_dsp_icon, "xpath")).is_true() assert_that(popover_text).is_equal_to(text_exp[dsp]) icon_attr = str(self.tp.get_attribute_value(locator=loc_dsp_icon, locator_type="xpath", attribute="href")) assert_that(icon_attr).contains(dsp) self.tp.hover_on_element(loc_details, "xpath") popover_text = self.tp.get_text(loc, "xpath") assert_that(len(popover_text)).is_equal_to(0) self.tp.hover_on_element(element=playlist) popover_text = self.tp.get_text(loc, "xpath") assert_that(len(popover_text)).is_greater_than(0) self.tp.hover_on_element(loc_dsp_icon, "xpath") self.tp.hover_on_element(loc_details, "xpath") popover_text = self.tp.get_text(loc, "xpath") assert_that(len(popover_text)).is_equal_to(0) # NOT AUTOMATED STEPS - 3-4, 7-8, 12-13