import unittest from datetime import datetime 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.src.pages.global_track_priorities_page import GlobalTrackPrioritiesPage from app.src.pages.login_page import LoginPage from app.src.pages.track_page import TrackPage from app.src.pages.tt_dashboard_page import TTDashboardPage @pytest.mark.usefixtures("set_up", "one_time_set_up") class TTDashboardPageTest(unittest.TestCase): @pytest.fixture(autouse=True) def classSetup(self): self.loginPage = LoginPage(self.driver) self.tt_dashboard = TTDashboardPage(self.driver) self.trackPage = TrackPage(self.driver) self.gtp = GlobalTrackPrioritiesPage(self.driver) self.api_client = ApiClient() self.ts = TestStatus(self.driver) @parameterized.expand( [ ("7days", "by-creations-change", "7", "creations_change", "global", "worldwide_no_asian", ""), ("7days", "by-creations-change", "7", "creations_change", "us", "us", "2022-03-18"), ] ) @allure.story("AP-7499") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-6909] TikTok Dashboard. By Creations Change -> 7 Days. Table content verification") @allure.description("TC verifies table on Sony TikTok TopList → By Creations Change → 7 Days view.") def test_tt_dashboard_table_weekly_values_verification(self, view, tab, days_api, type_api, market, market_api, date): self.loginPage.login_with_worker() self.tt_dashboard.open() self.tt_dashboard.select_tab(tab) self.tt_dashboard.select_view(view) self.tt_dashboard.change_market(AppConfig.get("market")[market]["name"]) if date != "": self.gtp.enter_datepicker_date_manually(date=date, location="tt_dashboard") # step 1, 16 table_ui = self.tt_dashboard.get_all_from_table() index_column = table_ui[self.tt_dashboard.column_index] assert_that([int(i) for i in index_column]).is_sorted() # step 2 count_check = 1 track_column = table_ui[self.tt_dashboard.column_track_name][:count_check] date_ui = self.tt_dashboard.get_selected_date_ui() date_formatted = datetime.strptime(date_ui, self.trackPage.get_date_format_from_locale()).strftime("%Y-%m-%d") api_resp = self.api_client.get_tiktok_charts_tracks(date=date_formatted, market=market_api, days=int(days_api), type=type_api)[:count_check] assert_that([t.split("\n")[0] for t in track_column]).is_equal_to([t["track"]["name"] for t in api_resp]) track_artist_column = table_ui[self.tt_dashboard.column_track_artist_name][:count_check] assert_that(track_artist_column).is_equal_to([", ".join(a["name"] for a in t["track"]["artists"]) for t in api_resp]) assert_that(table_ui[self.tt_dashboard.column_image_cover][:count_check]).is_equal_to([t["track"]["cover"] for t in api_resp]) # step 3-4 self.tt_dashboard.verify_track_title_hover() # step 5 self.tt_dashboard.verify_artist() # step 6, 8 self.tt_dashboard.verify_table_columns() # step 7 assert_that([int(c.replace(",", "")) for c in table_ui[self.tt_dashboard.column_current_creations][:count_check]]).is_equal_to([t["selected"]["creations"] for t in api_resp if t["selected"]["creations"]]) # step 9 assert_that([int(c.split("\n")[0].replace(",", "")) for c in table_ui[self.tt_dashboard.column_creations_rank][:count_check]]).is_equal_to([t["selected"]["change"]["value"] for t in api_resp if t["selected"]["change"]["value"]]) assert_that([int(c.split("(")[1].split("%")[0].lower().replace("k", "").replace("m", "").replace("b", "")) for c in table_ui[self.tt_dashboard.column_creations_rank][:count_check]]).is_equal_to( [self.trackPage.millify(t["selected"]["change"]["percent"]) for t in api_resp if t["selected"]["change"]["percent"]] ) assert_that([int(c.split("#")[1]) for c in table_ui[self.tt_dashboard.column_creations_rank][:count_check]]).is_equal_to([i for i in list(range(1, count_check + 1))]) # step 10 ranking_trend_column = table_ui[self.tt_dashboard.column_creations_trend][:count_check] trend_api_values = [] for t in api_resp: if t["selected"]["position"]["is_new"] or t["selected"]["position"]["is_re_entry"]: trend_api_values.append("") else: trend_api_values.append(str(abs(int(t["selected"]["position"]["trend"]) * -1))) assert_that(ranking_trend_column).is_equal_to(trend_api_values) # step 11 flags_ui = self.tt_dashboard.get_flags_ui()[:count_check] flags_api = [f["top_markets"][:2] for f in api_resp if f["top_markets"]] assert_that(flags_ui).is_equal_to(flags_api) # step 12 self.tt_dashboard.verify_top_markets_hover() # step 13 assert_that([int(d) for d in table_ui[self.tt_dashboard.column_days_on_list][:count_check]]).is_equal_to([t["days_on_list"] for t in api_resp if t["days_on_list"]]) # step 14 self.tt_dashboard.verify_comparison_icon() # NOT AUTOMATED STEP - 15