import json import time import unittest from argparse import Namespace 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.mysql_db_client_custom import MySqlClient from app.src.pages.apple_playlist_page import ApplePlaylistPage from app.src.pages.chart_digest import ChartDigestPage 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 ApplePlaylistPageTest(unittest.TestCase): playlist19 = json.loads(json.dumps(AppConfig.get("playlist19")), object_hook=lambda d: Namespace(**d)) playlist14 = json.loads(json.dumps(AppConfig.get("playlist14")), object_hook=lambda d: Namespace(**d)) playlist9 = json.loads(json.dumps(AppConfig.get("playlist9")), object_hook=lambda d: Namespace(**d)) us = json.loads(json.dumps(AppConfig.get("market")["us"]), object_hook=lambda d: Namespace(**d)) @pytest.fixture(autouse=True) def classSetup(self): self.loginPage = LoginPage(self.driver) self.ap = ApplePlaylistPage(self.driver) self.tp = TrackPage(self.driver) self.chart_digest = ChartDigestPage(self.driver) self.api_client = ApiClient() self.sql_client = MySqlClient() self.ts = TestStatus(self.driver) @allure.story("AP-3835") @allure.severity(allure.severity_level.NORMAL) @allure.title("""Apple Playlist page header verification""") @allure.description("""TC verifies Apple Playlist page header after similar to Spotify info playlist was added.""") def test_page_header(self): self.loginPage.login_with_worker() self.loginPage.is_logged_in() self.tp.select_market(AppConfig.get("market")["us"]["name"]) # step 1 self.ap.open_apple_playlist_page(self.playlist19.apple_id) # step 2, 5-7 self.ap.verify_header() # step 8-12, 19 self.ap.verify_market_droplist_filtering() # step 13 self.ap.verify_donats_chart_text(AppConfig.get("market")["canada"]["market"]) # step 14 self.ap.verify_market_bold(AppConfig.get("market")["canada"]["name"]) self.ap.market_droplist_click() # step 15 self.ap.change_market(AppConfig.get("market")["us"]["name"]) self.ap.market_droplist_click() self.ap.verify_market_bold(AppConfig.get("market")["us"]["name"]) self.ap.market_droplist_click() # step 16 self.ap.change_market(AppConfig.get("market")["australia"]["name"]) self.ap.market_droplist_click() self.ap.verify_market_bold(AppConfig.get("market")["australia"]["name"]) self.ap.market_droplist_click() # step 18 self.ap.open_apple_playlist_page(AppConfig.get("playlist21")["apple_id"]) self.ap.verify_subtitle() # step 20 self.ap.open_apple_playlist_page(AppConfig.get("playlist22")["apple_id"]) self.ap.market_droplist_click() market_list = self.ap.get_markets_from_droplist() self.ts.markFinal(not any(m in market_list for m in self.ap.TOP_6_MARKETS_FULL_NAME), f"no top markets in {market_list}") self.ts.markFinal(market_list == sorted(market_list), "market list is sorted alphabetically") # step 21 self.ap.open_apple_playlist_page(AppConfig.get("playlist23")["apple_id"]) self.ap.market_droplist_click() market_list = self.ap.get_markets_from_droplist() top_5 = list(self.ap.TOP_6_MARKETS_FULL_NAME) top_5.remove(AppConfig.get("market")["uk"]["name"]) self.ts.markFinal(not all(m in market_list for m in top_5), f"top 5 markets in {market_list}") self.ts.markFinal( AppConfig.get("market")["uk"]["name"] not in market_list, f"{AppConfig.get('market')['uk']['name']} not in {market_list}", ) for t in top_5: if t in market_list: market_list.remove(t) self.ts.markFinal(market_list == sorted(market_list), "market list is sorted alphabetically") # step 22 self.ap.open_apple_playlist_page(self.playlist19.apple_id) self.ap.change_market(AppConfig.get("market")["us"]["name"]) art_us = self.ap.get_art_link() self.ap.open_apple_playlist_page(self.playlist19.apple_id) self.ap.change_market(AppConfig.get("market")["canada"]["name"]) art_ca = self.ap.get_art_link() self.ts.markFinal(art_ca != art_us, "links are different for ca and us") # step 23 self.ap.open_apple_playlist_page(AppConfig.get("playlist24")["apple_id"]) market_list = self.ap.get_markets_from_droplist() self.ts.markFinal([AppConfig.get("market")["us"]["name"]] == market_list, f"market list: {market_list}") # step 24 aut0_id = self.loginPage.get_auth0_id() self.sql_client.clear_search_history(id=aut0_id) self.tp.select_market(AppConfig.get("market")["canada"]["name"]) self.ap.global_search_open_apple_playlist(self.playlist14, market=AppConfig.get("market")["canada"], verify=False) self.chart_digest.open_charts_digest_page() self.ap.open_apple_playlist_page(self.playlist14.apple_id) self.ap.verify_chosen_market(AppConfig.get("market")["canada"]) time.sleep(15) self.chart_digest.open_charts_digest_page() self.ap.recent_search_open_last_item() self.ap.verify_chosen_market(AppConfig.get("market")["canada"]) # NOT AUTOMATED STEPS - 3, 4, 25 @allure.story("AP-3835") @allure.severity(allure.severity_level.NORMAL) @allure.title("""Apple Playlist page header verification - STEP 17""") @allure.description("""TC verifies Apple Playlist page header after similar to Spotify info playlist was added. - STEP 17""") def test_page_header_step_17(self): self.loginPage.login_with_worker() self.loginPage.is_logged_in() self.tp.select_market(AppConfig.get("market")["us"]["name"]) # step 17 self.ap.open_apple_playlist_page(AppConfig.get("playlist28")["apple_id"]) art_1 = self.ap.is_art_missed() self.ap.open_apple_playlist_page(AppConfig.get("playlist29")["apple_id"]) art_2 = self.ap.is_art_missed() self.ts.markFinal(art_1 or art_2, "art is not present on apple playlist page")