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.mysql_db_client_custom import MySqlClient 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.sql_client = MySqlClient() self.ts = TestStatus(self.driver) @parameterized.expand(["us", "france"]) @allure.story("AP-637") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-66] Dashboard: Verification of the required data in the 'Bubbling Under' section for Apple Music Daily") @allure.description( """TC verifies 'Bubbling Under' section on the Dashboard page for Apple Top 100 tracks. 'Bubbling Under' section functionality works as expected. """ ) def test_bu_apple_daily_v(self, market): user = self.loginPage.get_user_email_with_worker() token = self.api_client.authorize(user=user) self.loginPage.login_with_worker() self.loginPage.is_logged_in() self.left_panel.open_chart_digest_page() self.chart_digest.is_opened() self.trackPage.select_market(AppConfig.get("market")[market]["name"]) self.chart_digest.select_tab(self.chart_digest.TAB_APPLE) self.chart_digest.scroll_to_section(self.chart_digest.BUBBLING_UNDER) tracks = self.chart_digest.get_tracks_for_table(table=self.chart_digest.BUBBLING_UNDER) if len(tracks[1]) > 0: self.chart_digest.page_has_loaded() 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.chart_digest.select_tab(self.chart_digest.TAB_APPLE) self.chart_digest.scroll_to_section(table=self.chart_digest.BUBBLING_UNDER) self.chart_digest.verify_tooltip_apple_artist(table=self.chart_digest.BUBBLING_UNDER) self.compare_ui_api_apple_bu(token=token, market=AppConfig.get("market")[market]) self.chart_digest.verify_trend_calculation(table=self.chart_digest.BUBBLING_UNDER, vendor=self.chart_digest.TAB_APPLE, market=AppConfig.get("market")[market]["market"], token=token) for c in ["name", "position"]: self.chart_digest.verify_sorting(table=self.chart_digest.BUBBLING_UNDER, column=c) apple_api = self.api_client.get_vendor_api_tracks(vendor=self.chart_digest.TAB_APPLE, market=AppConfig.get("market")[market]["market"], token=token) bu_apple_api = apple_api["tracks"][50:60] tracks_trends_api = [bu_apple_api[t]["trend"] for t in range(len(bu_apple_api))] trends_for_arrows = [trend * (-1) for trend in tracks_trends_api] trends_for_arrows_indexes = [t for t in range(len(trends_for_arrows))] for index, trend in zip(trends_for_arrows_indexes, trends_for_arrows): self.chart_digest.verify_trend_arrow(table=self.chart_digest.BUBBLING_UNDER, index=index + 1, trend=trend) def compare_ui_api_apple_bu(self, token, market): apple_ui = self.chart_digest.get_all_from_table(table=self.chart_digest.BUBBLING_UNDER) self.chart_digest.log.info("Apple UI: " + str(apple_ui)) self.ts.markFinal(all(p in list(range(51, 61)) for p in apple_ui["positions"]), "positions are correct") self.ts.markFinal(apple_ui["positions"] == sorted(apple_ui["positions"]), "tracks are sorted by positions") apple_api = self.api_client.get_vendor_api_tracks(vendor=self.chart_digest.TAB_APPLE, market=market["market"], token=token, end=60) bu_apple_api = apple_api["tracks"][50:60] tracks_names_api = [bu_apple_api[n]["name"] for n in range(len(bu_apple_api))] tracks_artists_api = [bu_apple_api[a]["artist"] for a in range(len(bu_apple_api))] tracks_trends_api = [abs(bu_apple_api[t]["trend"]) for t in range(len(bu_apple_api))] positions_api = [bu_apple_api[p]["position"] for p in range(len(bu_apple_api))] assert_that(apple_ui["tracks"]).is_equal_to(tracks_names_api) assert_that(apple_ui["artists"]).is_equal_to(tracks_artists_api) blue_dot_indexes = [tracks_trends_api.index(t_api) for t_api in tracks_trends_api if abs(t_api) > 1000] if len(blue_dot_indexes) > 0: for index in blue_dot_indexes: self.chart_digest.verify_trend_blue_dot_present(index=index + 1, table=self.chart_digest.BUBBLING_UNDER) else: assert_that(apple_ui["trends"]).is_equal_to(tracks_trends_api) assert_that(apple_ui["positions"]).is_equal_to(positions_api)