import unittest import allure import pytest from ui_automation_framework.core import TestStatus from ui_automation_framework.utils import AppConfig from app.api_client import ApiClient 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): us = AppConfig.get("market")["us"] @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.api_client = ApiClient() self.ts = TestStatus(self.driver) @allure.story("AP-640") @allure.severity(allure.severity_level.NORMAL) @allure.title("Dashboard page: Verification of the required data in the 'Major moves' " "section for Apple Music Daily chart") @allure.description("""TC verifies the ‘Major moves' section on the Dashboard page. 'Major moves' section’s functionality works as expected.""") def test_mm_apple_required_data(self): 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(self.us["name"]) # step 1 self.chart_digest.select_tab(tab=self.chart_digest.TAB_APPLE) # step 2 self.chart_digest.verify_title_hover(table=self.chart_digest.MAJOR_MOVES, tab=self.chart_digest.TAB_APPLE) # step 3 tracks_number = self.chart_digest.get_mm_total_tracks() total_trends = [] total_icons = [] total_positions = [] number_of_pages = tracks_number // 20 for page in range(number_of_pages + 1): trends = self.chart_digest.get_position_trends_for_table(table="{}-table".format(self.chart_digest.MAJOR_MOVES)) for t in trends: total_trends.append(t) icons = self.chart_digest.get_track_icons_for_table(table="{}-table".format(self.chart_digest.MAJOR_MOVES)) for i in icons: total_icons.append(i) positions = self.chart_digest.get_track_position_for_table(table="{}-table".format(self.chart_digest.MAJOR_MOVES)) for p in positions: total_positions.append(p) if tracks_number > 20: self.chart_digest.mm_next_page() self.ts.markFinal(all(t >= 5 for t in total_trends), "STEP 3: all trends are correct") self.ts.markFinal(len(total_icons) == len(total_trends), "icons are displayed") self.ts.markFinal(all(p in list(range(0, 101)) for p in total_positions), "positions are correct") # step 4 min_trends = 5 if min(total_trends) > min_trends: min_trends = min(total_trends) self.ts.markFinal( total_trends[: total_trends.index(min_trends)] == sorted(total_trends[: total_trends.index(min_trends)], reverse=True), "STEP 4: tracks are sorted by trends desc by default", ) self.ts.markFinal( total_trends[total_trends.index(min_trends) :] == sorted(total_trends[total_trends.index(min_trends) :]), "tracks are sorted by trends desc by default", ) # step 5 self.chart_digest.click_on_track_name_in_table(table=self.chart_digest.MAJOR_MOVES) self.chart_digest.go_back() self.chart_digest.select_tab(tab=self.chart_digest.TAB_APPLE) # step 6 self.chart_digest.verify_hover_artist_for_table(table=self.chart_digest.MAJOR_MOVES, tab=self.chart_digest.TAB_APPLE) # step 7 self.trackPage.select_market(AppConfig.get("market")["algerial"]["name"]) self.chart_digest.verify_major_moves_empty() # step 8-9 self.trackPage.select_market(self.us["name"]) self.chart_digest.select_tab(tab=self.chart_digest.TAB_APPLE) self.chart_digest.mm_compare_api_and_ui(market=self.us["market"], vendor=self.chart_digest.TAB_APPLE) # step 10-11 self.trackPage.select_market(AppConfig.get("market")["argentina"]["name"]) self.chart_digest.select_tab(tab=self.chart_digest.TAB_APPLE) self.chart_digest.mm_compare_api_and_ui(market=AppConfig.get("market")["argentina"]["market"], vendor=self.chart_digest.TAB_APPLE) # step 11 self.chart_digest.refresh() self.chart_digest.select_tab(tab=self.chart_digest.TAB_APPLE) self.chart_digest.mm_verify_pagination() # step 12 self.chart_digest.select_tab(tab=self.chart_digest.TAB_APPLE) self.chart_digest.verify_hover_and_pagination() self.chart_digest.mm_switch_page_to(page=2) # step 13 self.chart_digest.mm_select_last_page() # step 14 self.trackPage.select_market(AppConfig.get("market")["algerial"]["name"]) self.chart_digest.select_tab(tab=self.chart_digest.TAB_APPLE) self.chart_digest.mm_verify_no_pagination()