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( [ ("daily", "by-creations-change", "1", "creations_change", "global", "worldwide_no_asian", ""), ("daily", "by-creations-change", "1", "creations_change", "us", "us", "2022-03-18"), ("daily", "by-creations", "1", "creations", "global", "worldwide_no_asian", ""), ("daily", "by-creations", "1", "creations", "us", "us", "2022-03-18"), ("7days", "by-creations", "7", "creations", "global", "worldwide_no_asian", ""), ("7days", "by-creations", "7", "creations", "us", "us", "2022-03-18"), ] ) @allure.story("AP-7298, AP-7506, AP-7534") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-6908][TT Dashboard> By Creations Change Daily] Table content> values verification.") @allure.description("TC verifies Table on the ‘Sony TikTok Toplists’ → By Creation Change tab → Daily’ Page") def test_tt_dashboard_table_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, 11 (5) count_check = 5 table_ui = self.tt_dashboard.get_all_from_table() 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] if tab == self.tt_dashboard.by_creations_change: 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"]]) else: 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"]["creations"] for t in api_resp if t["selected"]["creations"]]) 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 2 (1) (1-3) ranking_by_change_column = table_ui[self.tt_dashboard.column_creations_rank][:count_check] change_qty = [int(q.split("\n")[0].replace(",", "")) for q in ranking_by_change_column] positions = [int(p.split("#")[-1]) for p in ranking_by_change_column] if tab == self.tt_dashboard.by_creations_change: change_qty_api = [t["selected"]["creations"] - t["previous"]["creations"] for t in api_resp if t["selected"]["creations"] or t["previous"]["creations"]] else: change_qty_api = [t["selected"]["creations"] for t in api_resp if t["selected"]["creations"]] assert_that(change_qty).is_equal_to(change_qty_api) assert_that(positions).is_equal_to([i for i in list(range(1, count_check + 1))]) if tab == self.tt_dashboard.by_creations_change: change_percentage = [int(p.split("(")[-1].split("%")[0].lower().replace("k", "").replace("m", "").replace("b", "")) for p in ranking_by_change_column] assert_that(change_percentage).is_equal_to([self.trackPage.millify(t["selected"]["change"]["percent"]) for t in api_resp]) # step 4 (3) (4) 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 5 (4) (5) week_change_api_values = [] if view == self.tt_dashboard.daily: api_path = "week" else: api_path = "selected" for t in api_resp: if t[api_path]["change"]["value"]: week_change_api_values.append(abs(t[api_path]["change"]["value"])) elif t["selected"]["creations"]: week_change_api_values.append(abs(t["selected"]["creations"])) week_change_percentage = [self.trackPage.millify(abs(t[api_path]["change"]["percent"])) if t[api_path]["change"]["percent"] else 0 for t in api_resp] change7_days_ago_column = table_ui[self.tt_dashboard.column_creations_trend_weekly][:count_check] change7_qty = [int(q.split("\n")[0].replace(",", "")) for q in change7_days_ago_column] change7_percentage = [int(q.split("(")[-1].split("%")[0].lower().replace("k", "").replace("m", "").replace("b", "").replace(",", "")) for q in change7_days_ago_column] assert_that(change7_qty).is_equal_to(week_change_api_values) assert_that(change7_percentage).is_equal_to(week_change_percentage) # step 6 (6) (6) 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([set(f) for f in flags_ui]).is_equal_to([set(f) for f in flags_api]) # step 8 (8) (8) 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 9 (9) (9) self.tt_dashboard.verify_comparison_icon() # AP-7298 - NOT AUTOMATED STEPS - 10, COVERED IN OTHER TEST - STEP 3, 7 # AP-7506 - NOT AUTOMATED STEPS - 10, COVERED IN OTHER TEST - STEP 2, 7 # AP-7534 - NOT AUTOMATED STEPS - 10, COVERED IN OTHER TEST - STEP 2, 7