import datetime import json import math import random import unittest from argparse import Namespace 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.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.position_playlist_popup import PositionPlaylistPopup from app.src.pages.track_page import TrackPage @pytest.mark.usefixtures("set_up", "one_time_set_up") class ApplePlaylistPageTest(unittest.TestCase): playlist14 = json.loads(json.dumps(AppConfig.get("playlist14")), object_hook=lambda d: Namespace(**d)) playlist15 = json.loads(json.dumps(AppConfig.get("playlist15")), object_hook=lambda d: Namespace(**d)) playlist25 = json.loads(json.dumps(AppConfig.get("playlist25")), object_hook=lambda d: Namespace(**d)) @pytest.fixture(autouse=True) def classSetup(self): self.loginPage = LoginPage(self.driver) self.ap = ApplePlaylistPage(self.driver) self.pip = PositionPlaylistPopup(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-3967") @allure.severity(allure.severity_level.NORMAL) @allure.title("""Apple Playlist page. 'Details' popup verification. STEP 1-19""") @allure.description("""TC verifies that Position in Playlist popup on Apple Music Playlist page meets design and functional requirements. STEP 1-19""") def test_apple_playlist_page_details_popup_step_1_19(self): self.loginPage.login_with_worker() # step 1 self.tp.select_market(AppConfig.get("market")["global"]["name"]) self.ap.open_apple_playlist_page_with_market(self.playlist14.apple_id, AppConfig.get("market")["global"]["market"]) self.ap.change_market(AppConfig.get("market")["us"]["name"]) # step 2 link_details = self.ap.tl_get_column_values(self.ap.TL_COLUMN_DETAILS_LINK) positions = self.ap.tl_get_column_values(self.ap.TL_COLUMN_POSITION) self.ts.markFinal(len(link_details) == len(positions), "STEP 2: each track in tl has details link") # step 3 market_url = self.tp.parameter_from_url(self.ap.hd_filter_market) index = random.choice([0, 1, 2, 3, 4]) self.ap.open_position_details_popup(index) self.ap.tdp_verify_local_market(market=market_url) # step 5 self.ap.verify_popup_elements() # step 6 popup_owner = self.ap.popup_get_owner_name() self.ap.close_popup() playlist_owner = self.ap.playlist_get_owner_name() self.ts.markFinal(popup_owner == playlist_owner, f"STEP 6: {popup_owner} and {playlist_owner} are match") # step 7 self.ap.open_apple_playlist_page(self.playlist15.apple_id) self.ap.tl_sort_by_column(self.ap.TL_COLUMN_AVG_STREAMS) self.ap.open_position_details_popup(index) popup_owner = self.ap.popup_get_owner_name() # step 8 self.ap.popup_verify_chart_elements() track_metadata = self.ap.popup_get_metadata() # step 9 playlist_owner = self.ap.playlist_get_owner_name() self.ts.markFinal(popup_owner == playlist_owner, f"STEP 7: {popup_owner} and {playlist_owner} are match") # step 12 self.ap.popup_verify_artist_tooltip() # step 11 self.ap.popup_click_on_track_name() self.tp.is_track_page_title_present(track_metadata["track"]) # step 13 self.ap.open_apple_playlist_page(self.playlist15.apple_id) self.ap.open_position_details_popup(index) self.ap.popup_click_on_playlist_name_and_verify() # step 14 self.ap.open_apple_playlist_page(self.playlist15.apple_id) self.ap.tl_sort_by_column(self.ap.TL_COLUMN_AVG_STREAMS) self.ap.open_position_details_popup(index) self.ap.popup_click_on_playlist_creator() # step 15-18 self.ap.pop_verify_date_picker() # step 19 self.ap.popup_verify_predefined_periods() @pytest.mark.timeout(300) @allure.story("AP-3967") @allure.severity(allure.severity_level.NORMAL) @allure.title("""Apple Playlist page. 'Details' popup verification. STEP 20-36""") @allure.description("""TC verifies that Position in Playlist popup on Apple Music Playlist page meets design and functional requirements. STEP 20-36""") def test_apple_playlist_page_details_popup_step_20_36(self): self.loginPage.login_with_worker() self.ap.open_apple_playlist_page_with_market(self.playlist25.apple_id, AppConfig.get("market")["global"]["market"]) self.ap.change_market(AppConfig.get("market")["us"]["name"]) self.ap.tl_sort_by_column(self.ap.TL_COLUMN_AVG_STREAMS) index = random.choice([0, 1, 2, 3, 4]) self.ap.open_position_details_popup(index) # step 20 self.ap.popup_select_previous_mounth_period() # step 21-24, 26, 28, 42 values = self.ap.verify_chart_tooltip(AppConfig.get("market")["us"]["market"]) csv = self.ap.popup_export_to_csv_and_verify() positions_excel = self.ap.popup_export_to_csv_and_verify()["position"] assert_that(positions_excel).is_subset_of(values["position"]) csv_global = csv["global"] csv_local = csv["local"] # step 27 values_global = values["global"] values_local = values["local"] self.ts.markFinal(list(set(values_global)) == list(set(csv_global)), f"{values_global} and {csv_global} match") self.ts.markFinal(list(set(values_local)) == list(set(csv_local)), f"{values_local} and {csv_local} match") # step 29 percentage_calculated = math.floor(values_local[0] / values_global[0] * 100) self.ts.markFinal( percentage_calculated == values["percentage"][0], f"STEP 29 calculated: {percentage_calculated} and tooltip: {values['percentage'][0]} match", ) # step 30-35 self.ap.popup_verify_chart_min_max(tooltips=values, market=AppConfig.get("market")["us"]["market"]) # step 36 self.ap.close_popup() @allure.story("AP-3967") @allure.severity(allure.severity_level.NORMAL) @allure.title("""Apple Playlist page. 'Details' popup verification. STEP 37-50""") @allure.description("""TC verifies that Position in Playlist popup on Apple Music Playlist page meets design and functional requirements. STEP 37-50""") def test_apple_playlist_page_details_popup_step_37_50(self): self.loginPage.login_with_worker() self.ap.open_apple_playlist_page_with_market(self.playlist25.apple_id, AppConfig.get("market")["global"]["market"]) # step 37 self.ap.change_market(AppConfig.get("market")["australia"]["name"]) self.ap.verify_chosen_market(AppConfig.get("market")["australia"]) # step 38 index = random.choice([0, 1, 2, 3, 4]) self.ap.open_position_details_popup(index) track_id = self.pip.get_id_from_track_link() isrc = self.api_client.get_isrc_by_apple_id(id=track_id, market=AppConfig.get("market")["australia"]["market"])["data"][0]["attributes"]["isrc"] self.ap.verify_popup_network_market(market=AppConfig.get("market")["australia"]["market"], isrc=isrc, playlist_id=self.playlist25.apple_id) self.ap.close_popup() # step 39 self.ap.change_market(AppConfig.get("market")["canada"]["name"]) self.ap.verify_chosen_market(AppConfig.get("market")["canada"]) # step 40 self.ap.open_position_details_popup(index) track_id = self.pip.get_id_from_track_link() isrc = self.api_client.get_isrc_by_apple_id(id=track_id, market=AppConfig.get("market")["canada"]["market"])["data"][0]["attributes"]["isrc"] self.ap.verify_popup_network_market(market=AppConfig.get("market")["canada"]["market"], isrc=isrc, playlist_id=self.playlist25.apple_id) # step 41 self.ap.popup_verify_local_market(AppConfig.get("market")["canada"]["header"]) # step 43 self.ap.popup_verify_na(market=AppConfig.get("market")["canada"]["market"]) # step 44 self.ap.popup_verify_no_data_for_previous_period() # step 50 self.ap.close_popup() self.ap.tl_choose_date("12/15/19") self.ap.open_position_details_popup(index) days_count = self.ap.popup_get_days_count_from_day_picker() end = self.ap.popup_get_start_end_date()["end"] days_displayed = self.ap.popup_get_days_in_playlist_is_displayed() self.ts.markFinal(not days_displayed, "days in playlist info is not present") self.ts.markFinal(end == datetime.date.today(), f"end date: {end} is correct: {datetime.date.today()}") self.ts.markFinal(days_count == 28, f"days count is: {days_count}") # TODO - NOT AUTOMATED - STEPS 4, 45-49