import unittest from datetime import datetime 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.mysql_db_client_custom import MySqlClient from app.src.pages.comparison_page import TrackComparisonPage 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): us = AppConfig.get("market")["us"] @pytest.fixture(autouse=True) def classSetup(self): self.loginPage = LoginPage(self.driver) self.topChartsPage = TopChartsPage(self.driver) self.trackPage = TrackPage(self.driver) self.comparison_page = TrackComparisonPage(self.driver) self.ts = TestStatus(self.driver) self.api_client = ApiClient() self.sql_client = MySqlClient() @allure.issue("https://data-analytics.atlassian.net/browse/AP-9323") @pytest.mark.flaky(reruns=0) @allure.story("AP-2235") @allure.severity(allure.severity_level.NORMAL) @allure.title("Switching between Daily/Weekly Spotify Top Chart view") @allure.description( """TC Verifies that the user can easily view the Top 200 Spotify chart for the previous dates in a Daily and Weekly view.""" ) def test_daily_weekly_switch(self): user = self.loginPage.get_user_email_with_worker() token = self.api_client.authorize(user=user) self.loginPage.login_with_worker() self.topChartsPage.open_top_chart_page() self.trackPage.select_market(self.us["name"]) # step 1 self.topChartsPage.verify_chosen_switch(self.topChartsPage.DAILY) # step 2-3 self.verify_period_dd(tab=self.topChartsPage.DAILY, token=token) self.topChartsPage.open_spotify_chart_for_date("12/30/19") # step 5 self.topChartsPage.verify_period_dd_info_icon() # step 6-7 self.topChartsPage.change_sub_tab(self.topChartsPage.WEEKLY) self.verify_period_dd(tab=self.topChartsPage.WEEKLY, token=token) self.topChartsPage.open_spotify_chart_for_date("12/26/19") # step 9 self.topChartsPage.change_spotify_market(AppConfig.get("market")["argentina"]["name"]) self.topChartsPage.verify_chosen_switch(self.topChartsPage.DAILY) self.verify_period_dd(tab=self.topChartsPage.DAILY, token=token) # step 10-11 self.topChartsPage.change_sub_tab(self.topChartsPage.WEEKLY) self.verify_period_dd(tab=self.topChartsPage.WEEKLY, token=token) date_step_10 = self.topChartsPage.get_chosen_date() self.topChartsPage.open_spotify_chart_for_date("12/26/19") self.topChartsPage.change_spotify_market(self.us["name"]) assert_that(date_step_10).is_equal_to(self.topChartsPage.get_chosen_date()) self.topChartsPage.switch_tab(self.topChartsPage.APPLE_TYPE) self.topChartsPage.switch_tab(self.topChartsPage.SPOTIFY_TYPE) self.topChartsPage.verify_chosen_switch(self.topChartsPage.DAILY) self.verify_period_dd(tab=self.topChartsPage.DAILY, token=token) self.trackPage.select_market(AppConfig.get("market")["brazil"]["name"]) self.verify_period_dd(tab=self.topChartsPage.DAILY, token=token, market=AppConfig.get("market")["brazil"]) self.topChartsPage.verify_chosen_switch(self.topChartsPage.DAILY) def verify_period_dd(self, tab, token, market=AppConfig.get("market")["us"]): exp_date = self.api_client.get_top_charts_dates(vendor="spotify", market=market["market"], type=tab, token=token)["max_date"] date_ui = self.topChartsPage.get_chosen_date() date_ui = datetime.strptime(date_ui, self.trackPage.get_date_format_from_locale()).strftime("%Y-%m-%d") if tab == self.topChartsPage.DAILY: first_date = "07/30/17" self.topChartsPage.open_spotify_chart_for_date(first_date) else: first_date = "12/29/16" self.topChartsPage.open_spotify_chart_for_date_dd(first_date) chosen_date_ui = self.topChartsPage.get_chosen_date() assert_that(date_ui).is_equal_to(exp_date) assert_that(chosen_date_ui).is_equal_to(first_date) # NOT AUTOMATED STEPS 4, 8