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.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): 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.artist_page = ArtistPage(self.driver) self.api_client = ApiClient() self.ts = TestStatus(self.driver) @allure.story("AP-639") @allure.severity(allure.severity_level.NORMAL) @allure.title("Dashboard page: Verification of the required data in the " "'Major moves' section for Spotify 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_spotify_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-3 self.chart_digest.select_tab(tab=self.chart_digest.TAB_SPOTIFY) top_10_tracks_before = self.chart_digest.get_tracks_for_table(table=self.chart_digest.TOP_VIEW)[0] self.chart_digest.select_tab(tab=self.chart_digest.TAB_APPLE) top_10_tracks_after = self.chart_digest.get_tracks_for_table(table=self.chart_digest.TOP_VIEW)[0] self.ts.markFinal(top_10_tracks_after == top_10_tracks_before, "STEP 1-3: top 10 table content is not changed") # step 4 self.chart_digest.select_tab(tab=self.chart_digest.TAB_SPOTIFY) # step 5-6 self.chart_digest.verify_title_hover(table=self.chart_digest.MAJOR_MOVES, tab=self.chart_digest.TAB_SPOTIFY) # step 7 tracks_number = self.chart_digest.get_mm_total_tracks() total_trends = [] total_icons = [] total_positions = [] number_of_pages = (tracks_number - 1) // 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), "all trends are correct") self.ts.markFinal(len(total_icons) == len(total_icons), "icons are displayed") self.ts.markFinal(all(p in list(range(1, 201)) for p in total_positions), "positions are correct") # step 8 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", ) 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_SPOTIFY) artists = self.chart_digest.get_artists_for_table(table=f"{self.chart_digest.MAJOR_MOVES}-table") 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.trackPage.select_market(AppConfig.get("market")["algerial"]["name"]) # step 11 self.chart_digest.verify_major_moves_empty() self.trackPage.select_market(self.us["name"]) self.chart_digest.select_tab(tab=self.chart_digest.TAB_SPOTIFY) # step 12, 13 self.chart_digest.mm_compare_api_and_ui(market=self.us["market"], vendor=self.chart_digest.TAB_SPOTIFY) # step 14-16 self.chart_digest.refresh() for c in ["name", "trend", "position"]: self.chart_digest.verify_sorting(self.chart_digest.MAJOR_MOVES, c) # step 17 for m in ["us", "uk"]: self.trackPage.select_market(AppConfig.get("market")[m]["name"]) self.chart_digest.select_tab(tab=self.chart_digest.TAB_SPOTIFY) self.chart_digest.mm_compare_api_and_ui(market=AppConfig.get("market")[m]["market"], vendor=self.chart_digest.TAB_SPOTIFY) self.chart_digest.refresh() self.chart_digest.select_tab(tab=self.chart_digest.TAB_SPOTIFY) self.chart_digest.mm_verify_pagination() self.chart_digest.select_tab(tab=self.chart_digest.TAB_SPOTIFY) self.chart_digest.verify_hover_and_pagination() self.chart_digest.mm_switch_page_to(page=2) self.chart_digest.mm_select_last_page() self.trackPage.select_market(AppConfig.get("market")["algerial"]["name"]) self.chart_digest.select_tab(tab=self.chart_digest.TAB_SPOTIFY) self.chart_digest.mm_verify_no_pagination()