import logging 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 ui_automation_framework.utils import logger as cl from app.api_client import ApiClient from app.src.pages.artist_page import ArtistPage from app.src.pages.chart_digest import ChartDigestPage from app.src.pages.left_navigation_panel import LeftNavigationPanel from app.src.pages.login_page import LoginPage from app.src.pages.track_page import TrackPage @pytest.mark.usefixtures("set_up", "one_time_set_up") class TopChartsPageTest(unittest.TestCase): log = cl.Logger(logging.DEBUG) @pytest.fixture(autouse=True) def classSetup(self): self.loginPage = LoginPage(self.driver) self.left_panel = LeftNavigationPanel(self.driver) self.chart_digest = ChartDigestPage(self.driver) self.trackPage = TrackPage(self.driver) self.artist_page = ArtistPage(self.driver) self.api_client = ApiClient() self.ts = TestStatus(self.driver) @parameterized.expand(["us", "argentina"]) @allure.story("AP-662") @allure.severity(allure.severity_level.NORMAL) @allure.title("Verification of the 'Exits from Top 10' section for Spotify tracks") @allure.description("""TC verifies Top 10 Exits section on the Dashboard page functionality works as expected for Spotify tracks.""") def test_top_10_spotify_exit(self, market): self.loginPage.login_with_worker() self.loginPage.is_logged_in() self.left_panel.open_chart_digest_page() self.chart_digest.is_opened() # step 1-3 self.trackPage.select_market(AppConfig.get("market")[market]["name"]) self.switch_top_10_spotify_exits() tracks = self.chart_digest.get_tracks_for_table(table=self.chart_digest.TOP_VIEW) if len(tracks[1]) > 0: # step 4 t = self.chart_digest.get_text(element=tracks[1][0]) self.chart_digest.click_element(element=tracks[1][0]) self.trackPage.is_track_page_title_present(track=t) self.trackPage.go_back() self.switch_top_10_spotify_exits() # step 5 artists = self.chart_digest.get_artists_for_table(table=self.chart_digest.TOP_VIEW) artist = str(self.chart_digest.get_text(element=artists[1][0])).rstrip(",") self.chart_digest.click_element(element=artists[1][0]) self.artist_page.verify_title(title=artist) self.trackPage.go_back() self.switch_top_10_spotify_exits() # step 7-9 self.compare_ui_api_spotify_top_10_exits(vendor=self.chart_digest.TAB_SPOTIFY, market=AppConfig.get("market")[market]) # step 6 for c in ["name", "position"]: self.chart_digest.verify_sorting(table=self.chart_digest.TOP_VIEW, column=c) else: # step 10-11 self.chart_digest.verify_empty_table_top_10_exits(table=self.chart_digest.TOP_VIEW, tab=self.chart_digest.TAB_SPOTIFY) def compare_ui_api_spotify_top_10_exits(self, vendor, market): spotify_ui = self.chart_digest.get_all_from_table(table=self.chart_digest.TOP_VIEW) spotify_ui_artists = [str(spotify_ui["artists"][a]).replace(",", "") for a in range(len(spotify_ui["artists"]))] self.ts.markFinal(all(p in list(range(11, 101)) for p in spotify_ui["positions"]), "positions are correct") self.ts.markFinal(spotify_ui["positions"] == sorted(spotify_ui["positions"]), "tracks are sorted by positions") spotify_api = self.api_client.get_top_10_exits(vendor=vendor, market=market["market"]) spotify_api_exits = spotify_api["tracks"] tracks_names_api = [spotify_api_exits[n]["name"] for n in range(len(spotify_api_exits))] tracks_artists_api = [spotify_api_exits[a]["artists"][b]["name"] for a in range(len(spotify_api_exits)) for b in range(len(spotify_api_exits[a]["artists"]))] tracks_trends_api = [abs(spotify_api_exits[t]["trend"]) for t in range(len(spotify_api_exits))] positions_api = [spotify_api_exits[p]["position"] for p in range(len(spotify_api_exits))] assert_that(spotify_ui["tracks"]).is_equal_to(tracks_names_api) assert_that(spotify_ui_artists).is_equal_to(tracks_artists_api) assert_that(spotify_ui["trends"]).is_equal_to(tracks_trends_api) assert_that(spotify_ui["positions"]).is_equal_to(positions_api) def switch_top_10_spotify_exits(self): self.chart_digest.select_tab(tab="{}-{}".format(self.chart_digest.TOP_VIEW, self.chart_digest.TAB_SPOTIFY)) self.chart_digest.select_section_for_table("{}-{}".format(self.chart_digest.TOP_VIEW, self.chart_digest.SECTION_EXITS_TOP_10))