import datetime import unittest import allure import pytest from assertpy import assert_that 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.top_charts_page import TopChartsPage from app.src.pages.track_page import TrackPage @pytest.mark.usefixtures("set_up", "one_time_set_up") class TopChartsPageTest(unittest.TestCase): released_date = "2016-11-12" date_to_enter = "2022-02-27" invalid_date_1 = "2020-22-22" invalid_dates = ["310116", "22/02/03", "January 3, 2022", "2/3/22", "3/2/22", "22/2/3", "220203", "03Jan22", "22Jan03", "2022, January 3", "01/01"] @pytest.fixture(autouse=True) def classSetup(self): self.loginPage = LoginPage(self.driver) self.topChartsPage = TopChartsPage(self.driver) self.trackPage = TrackPage(self.driver) self.gtp = GlobalTrackPrioritiesPage(self.driver) self.api_client = ApiClient() self.ts = TestStatus(self.driver) @allure.story("AP-7579") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-5822][Shazam] Top-200 chart date picker STEPS 1-10") @allure.description("TC verifies datepicker on Top Charts → Shazam Daily Top 200. STEPS 1-10") def test_top_shazam_tab_date_picker_verification_steps_1_10(self): self.loginPage.login_with_worker() self.trackPage.select_market(AppConfig.get("market")["global"]["name"]) self.topChartsPage.open_top_chart_page() self.topChartsPage.switch_tab(self.topChartsPage.SHAZAM_TYPE) # steps 1-2 date_ui = self.topChartsPage.get_shazam_date_ui() dates_api = self.api_client.get_data_health_positions_shazam() default_date_api = dates_api[0]["latest_data_date"] min_date_api = dates_api[0]["earliest_data_date"] assert_that(default_date_api).is_equal_to(date_ui) # step 3 self.gtp.expand_datepicker() self.gtp.check_datepicker_manual_entry_field() self.gtp.verify_date_month_format() self.gtp.verify_datepicker_arrows() default_date_api = datetime.datetime.strptime(default_date_api, "%Y-%m-%d").date() self.gtp.calendar_default_grid_verification(default_date_api, False) # step 4, 15 self.trackPage.verify_trending_datepicker_last_available_date(date=str(default_date_api)) self.gtp.datepicker_swipe_to_date(date=min_date_api) self.trackPage.verify_trending_datepicker_first_available_date(date=min_date_api) # step 5-7 self.gtp.reset_datepicker(expected_default_date=str(default_date_api)) self.gtp.expand_datepicker() self.trackPage.trending_datepicker_grid_verification(grid_date=default_date_api) # step 8 month_year_before = self.topChartsPage.get_month_year() self.topChartsPage.calendar_click_arrow() month_year_after = self.topChartsPage.get_month_year() assert_that(month_year_before).is_equal_to(month_year_after) # steps 9-10 self.topChartsPage.select_previous_day_verify() @allure.story("AP-7579") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-5822][Shazam] Top-200 chart date picker STEPS 11-19") @allure.description("TC verifies datepicker on Top Charts → Shazam Daily Top 200. STEPS 11-19") def test_top_shazam_tab_date_picker_verification_steps_11_19(self): self.loginPage.login_with_worker() self.trackPage.select_market(AppConfig.get("market")["global"]["name"]) self.topChartsPage.open_top_chart_page() self.topChartsPage.switch_tab(self.topChartsPage.SHAZAM_TYPE) # step 11 date_ui = self.topChartsPage.get_shazam_date_ui() dates_api = self.api_client.get_data_health_positions_shazam() default_date_api = dates_api[0]["latest_data_date"] assert_that(default_date_api).is_equal_to(date_ui) # step 12 self.topChartsPage.expand_date_picker() month_year_before = self.topChartsPage.get_month_year() self.topChartsPage.calendar_click_arrow() month_year_after = self.topChartsPage.get_month_year() assert_that(month_year_before).is_equal_to(month_year_after) # step 13 self.gtp.verify_datepicker_arrows_background() # step 14 self.gtp.verify_datepicker_swiping_to_unavailable_date(date=self.released_date, swipe="backward", year_month="year") self.gtp.verify_datepicker_swiping_to_unavailable_date(date=self.released_date, swipe="forward", year_month="year") self.gtp.verify_datepicker_swiping_to_unavailable_date(date=self.released_date, swipe="backward", year_month="month") self.gtp.verify_datepicker_swiping_to_unavailable_date(date=self.released_date, swipe="forward", year_month="month") # step 16 self.gtp.reset_datepicker(expected_default_date=str(default_date_api)) # step 17 self.gtp.clear_date_manually() # step 18-19 self.gtp.enter_datepicker_date_manually(date=str(self.date_to_enter), location="top_charts", apply_by="outside") self.gtp.verify_datepicker_grid_selected_date(expected_selected_date=str(self.date_to_enter)) @allure.story("AP-7579") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-5822][Shazam] Top-200 chart date picker STEPS 20-29") @allure.description("TC verifies datepicker on Top Charts → Shazam Daily Top 200. STEPS 20-29") def test_top_shazam_tab_date_picker_verification_steps_20_29(self): self.loginPage.login_with_worker() self.trackPage.select_market(AppConfig.get("market")["global"]["name"]) self.topChartsPage.open_top_chart_page() self.topChartsPage.switch_tab(self.topChartsPage.SHAZAM_TYPE) # step 20-29 for date in self.invalid_dates: self.gtp.verify_datepicker_invalid_date_manual_entering(date=date)