import datetime import random 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 app.api_client import ApiClient from app.src.pages.login_page import LoginPage from app.src.pages.position_playlist_popup import PositionPlaylistPopup from app.src.pages.track_page import TrackPage @pytest.mark.usefixtures("set_up", "one_time_set_up") class DeepLinkingTrackPageTest(unittest.TestCase): @pytest.fixture(autouse=True) def classSetup(self): self.loginPage = LoginPage(self.driver) self.tp = TrackPage(self.driver) self.pip = PositionPlaylistPopup(self.driver) self.api_client = ApiClient() self.ts = TestStatus(self.driver) @parameterized.expand( [ (AppConfig.get("track40")["id"], "first_playlist", "track"), (AppConfig.get("track40")["id"], "previous_playlists_tab", "track"), (AppConfig.get("playlist11")["id"], "spotify-playlist-details-tab-tracks", "playlist"), ] ) @allure.story("AP-5945") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-3740/2] Spotify Playlist Details popup. Date-picker") @allure.description("TC verifies that the user can change the period on Position in Playlist popup on Track page and Spotify Playlist pages.") def test_spotify_popup_date_picker(self, id, tab, page): self.loginPage.login_with_worker() self.tp.open_spotify_page(id, page) self.tp.scroll_to_track_details() self.tp.td_switch_to_playlist(tab) if page == "track": self.tp.td_change_dsp("Spotify") index_popup = random.choice([0, 1, 2, 3, 4, 5]) self.pip.open_popup(index=index_popup) # step 1-3, 7-8 count_graph_first = self.pip.get_graph_period_displayed() # step 4-5 for p, d in zip(self.tp.dp_predefined_periods, self.tp.dp_predefined_count_days): xaxis_before = self.tp.graph_get_xaxis() kpis_before = self.pip.get_legend_kpis() days_count_before = int(self.pip.get_graph_period_displayed()) assert_that(count_graph_first).is_equal_to(days_count_before) self.tp.select_predefined_period(p) days_count = int(self.pip.get_graph_period_displayed()) count_p = self.tp.graph_get_count_days_from_calendar() xaxis_after = self.tp.graph_get_xaxis() date_to_ui = self.tp.get_calendar_end_date() kpis_after = self.pip.get_legend_kpis() assert_that(days_count).is_equal_to(days_count_before) if d == self.tp.dp_predefined_count_days[-1]: assert_that(count_p).is_greater_than_or_equal_to(d - 5) assert_that(count_p).is_less_than_or_equal_to(d + 5) else: assert_that(count_p).is_equal_to(d) assert_that(str(datetime.datetime.today().date())).is_equal_to(date_to_ui) if p > self.tp.dp_predefined_periods[0]: assert_that(xaxis_before).is_not_equal_to(xaxis_after) assert_that(sum(kpis_before)).is_less_than_or_equal_to(sum(kpis_after)) # step 6 self.tp.select_previous_mounth_period() kpis_custom = self.pip.get_legend_kpis() count_graph = self.pip.get_graph_period_displayed() assert_that(count_graph).is_equal_to(days_count) assert_that(kpis_after != kpis_custom or kpis_after == [-1] or kpis_after == [-1, -1]).described_as(f"{kpis_after}\n{kpis_custom}").is_true()