import logging 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 ui_automation_framework.utils import logger as cl from app.api_client import ApiClient from app.src.pages.album_page import AlbumPage from app.src.pages.comparison_page import TrackComparisonPage 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 DeepLinkingTrackPageTest(unittest.TestCase): log = cl.Logger(logging.DEBUG) @pytest.fixture(autouse=True) def classSetup(self): self.loginPage = LoginPage(self.driver) self.tp = TrackPage(self.driver) self.cp = TrackComparisonPage(self.driver) self.ap = AlbumPage(self.driver) self.api_client = ApiClient() self.ts = TestStatus(self.driver) @allure.story("AP-5016") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-4911] [Track -> Video Performance] Deep linking verification. STEPS 1-4, 13-15") @allure.description("TC verifies deep-linking functionality for chosen Video Performance tab filter settings so that user can use predefined links to view" " streaming data coming from YOUTUBE in the Track Performance area. STEPS 1-4, 13-15") def test_youtube_vp_deep_linking_steps_1_4(self): self.loginPage.login_with_worker() self.tp.open_spotify_track_page_with_market_id(track_id=AppConfig.get("track40")["id"], market_id=AppConfig.get("market")["global"]["url"]) default_url = self.tp.get_url() # step 1 self.tp.switch_to_youtube_video_performance() self.tp.verify_params_in_url({self.tp.str_gr_tab: 3}) self.cp.open_new_tab() self.open_current_url_in_new_tab() yt_selected = self.tp.is_tab_selected("track-performance-youtube") assert_that(yt_selected).is_true() self.switch_to_first_tab() # step 2 self.tp.market_dd_choose_few_countries(param=[AppConfig.get("market")["us"]["name"]], tab="youtube_vp") self.tp.verify_params_in_url({self.tp.str_gr_country: AppConfig.get("market")["us"]["market"]}) self.open_current_url_in_new_tab() graph_market = self.tp.graph_get_selected_market(dd="youtube_vp") assert_that(graph_market).is_equal_to(AppConfig.get("market")["us"]["name"]) self.tp.verify_params_in_url({self.tp.str_gr_country: AppConfig.get("market")["us"]["market"]}) self.replace_param_in_url(self.tp.str_gr_country, AppConfig.get("market")["us"]["market"], AppConfig.get("market")["canada"]["market"]) graph_market = self.tp.graph_get_selected_market(dd="youtube_vp") assert_that(graph_market).is_equal_to(AppConfig.get("market")["canada"]["name"]) self.tp.verify_params_in_url({self.tp.str_gr_country: AppConfig.get("market")["canada"]["market"]}) self.replace_param_in_url(self.tp.str_gr_country, AppConfig.get("market")["canada"]["market"], "test") self.verify_url(default_url) self.switch_to_first_tab() # step 3 self.tp.stream_and_source_choose_region(param=self.tp.REGION_ASIA, dd="youtube_vp") self.tp.verify_params_in_url({self.tp.str_gr_region: "ras"}) self.open_current_url_in_new_tab() graph_market = self.tp.graph_get_selected_market(dd="youtube_vp") assert_that(graph_market).is_equal_to(self.tp.REGION_ASIA) self.tp.verify_params_in_url({self.tp.str_gr_region: "ras"}) self.replace_param_in_url(self.tp.str_gr_region, "ras", "rcs") graph_market = self.tp.graph_get_selected_market(dd="youtube_vp") assert_that(graph_market).is_equal_to(self.tp.REGION_CIS) self.tp.verify_params_in_url({self.tp.str_gr_region: "rcs"}) self.replace_param_in_url(self.tp.str_gr_region, "rcs", "fgc") self.verify_url(default_url) self.switch_to_first_tab() # step 4 self.tp.stream_and_source_deselect_countries(market_name=["Hong Kong"], dd="youtube_vp") countries_list = self.tp.parameter_from_url(self.tp.str_gr_country) self.tp.log.info(f"Countries list from URL: {countries_list}") country_list = "kh,cn,fj,in,id,jp,la,mo,my,np,pg,ph,sg,kr,lk,tw,th,vn" self.tp.verify_params_in_url({self.tp.str_gr_country: country_list}) self.open_current_url_in_new_tab() graph_market = self.tp.graph_get_selected_market(dd="youtube_vp") assert_that(graph_market).is_equal_to("18 Markets") self.tp.verify_params_in_url({self.tp.str_gr_country: country_list.replace("%2C", ",")}) country_list_new = "kh,cn,fj" self.replace_param_in_url(self.tp.str_gr_country, country_list, country_list_new) graph_market = self.tp.graph_get_selected_market(dd="youtube_vp") assert_that(graph_market).is_equal_to("3 Markets") self.tp.verify_params_in_url({self.tp.str_gr_country: country_list_new}) self.replace_param_in_url(self.tp.str_gr_country, country_list_new, "sbc") self.verify_url(default_url) @allure.story("AP-5016") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-4911] [Track -> Video Performance] Deep linking verification. STEPS 5-9, 13-15") @allure.description("TC verifies deep-linking functionality for chosen Video Performance tab filter settings so that user can use predefined links to view" " streaming data coming from YOUTUBE in the Track Performance area. STEPS 5-9, 13-15") def test_youtube_vp_deep_linking_steps_5_9(self): self.loginPage.login_with_worker() self.tp.open_spotify_track_page_with_market_id(track_id=AppConfig.get("track40")["id"], market_id=AppConfig.get("market")["global"]["url"]) default_url = self.tp.get_url().replace("market=14", "market=16") self.tp.switch_to_youtube_video_performance() # step 5 self.tp.select_market(AppConfig.get("market")["canada"]["name"]) self.tp.switch_to_youtube_video_performance() self.tp.verify_params_in_url({self.tp.str_gr_tab: 3, self.tp.market: AppConfig.get("market")["canada"]["url"]}) self.cp.open_new_tab() self.open_current_url_in_new_tab() yt_selected = self.tp.is_tab_selected("track-performance-youtube") assert_that(yt_selected).is_true() self.tp.verify_params_in_url({self.tp.str_gr_tab: 3, self.tp.market: AppConfig.get("market")["canada"]["url"]}) graph_market = self.tp.graph_get_selected_market(dd="youtube_vp") assert_that(graph_market).is_equal_to(AppConfig.get("market")["canada"]["name"]) self.switch_to_first_tab() # step 6 self.tp.market_dd_choose_few_countries(param=[AppConfig.get("market")["us"]["name"], AppConfig.get("market")["canada"]["name"]], tab="youtube_vp") self.tp.verify_params_in_url({self.tp.str_gr_country: "ca,us"}) self.open_current_url_in_new_tab() graph_market = self.tp.graph_get_selected_market(dd="youtube_vp") assert_that(graph_market).is_equal_to("2 Markets") self.tp.verify_params_in_url({self.tp.str_gr_country: "ca,us"}) self.switch_to_first_tab() # step 7 self.tp.choose_graph_view_area_graph_percentage() self.tp.verify_params_in_url({self.tp.str_gr_view: 3}) self.open_current_url_in_new_tab() self.tp.verify_graph_view_chosen("Area Graph, %") self.tp.verify_params_in_url({self.tp.str_gr_view: 3}) self.switch_to_first_tab() # step 8 self.tp.choose_graph_view_area_graph() self.tp.verify_params_in_url({self.tp.str_gr_view: 2}) self.open_current_url_in_new_tab() self.tp.verify_graph_view_chosen("Area Graph") self.tp.verify_params_in_url({self.tp.str_gr_view: 2}) self.replace_param_in_url(self.tp.str_gr_view, 2, 3) self.tp.verify_graph_view_chosen("Area Graph, %") self.replace_param_in_url(self.tp.str_gr_view, 3, 8) self.verify_url(default_url) self.switch_to_first_tab() # step 9 self.tp.vp_youtube_change_source_view(param=AppConfig.get("source")["by_video"]) self.tp.verify_params_in_url({self.tp.str_gr_view: 1, self.tp.str_gr_type: 4}) self.open_current_url_in_new_tab() source_type = self.tp.get_source_type() assert_that(source_type).is_equal_to(AppConfig.get("source")["by_video"]) self.tp.verify_params_in_url({self.tp.str_gr_view: 1, self.tp.str_gr_type: 4}) self.switch_to_first_tab() @allure.story("AP-5016") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-4911] [Track -> Video Performance] Deep linking verification. STEPS 10-17") @allure.description("TC verifies deep-linking functionality for chosen Video Performance tab filter settings so that user can use predefined links to view" " streaming data coming from YOUTUBE in the Track Performance area. STEPS 10-17") def test_youtube_vp_deep_linking_steps_10_12(self): self.loginPage.login_with_worker() self.tp.open_spotify_track_page_with_market_id(track_id=AppConfig.get("track40")["id"], market_id=AppConfig.get("market")["global"]["url"]) default_url = self.tp.get_url() self.tp.switch_to_youtube_video_performance() self.cp.open_new_tab() # step 10 for source, param in [ (AppConfig.get("source")["all_views"], 1), (AppConfig.get("source")["by_source"], 2), # (AppConfig.get("source")["by_avg_view_duration"], 5), (AppConfig.get("source")["by_likes"], 6), (AppConfig.get("source")["by_dislikes"], 7), (AppConfig.get("source")["by_comments"], 8), (AppConfig.get("source")["by_shares"], 9), ]: self.tp.vp_youtube_change_source_view(source) self.tp.verify_params_in_url({self.tp.str_gr_type: param}) self.open_current_url_in_new_tab() source_type_ui = self.tp.get_source_type() assert_that(source_type_ui).is_equal_to(source) self.tp.verify_params_in_url({self.tp.str_gr_type: param}) if param == 9: self.replace_param_in_url(self.tp.str_gr_type, param, 6) source_type_ui = self.tp.get_source_type() assert_that(source_type_ui).is_equal_to("By Likes") self.tp.verify_params_in_url({self.tp.str_gr_type: 6}) self.replace_param_in_url(self.tp.str_gr_type, 6, 10) self.verify_url(default_url) self.switch_to_first_tab() # step 11 self.tp.vp_youtube_change_source_view(AppConfig.get("source")["by_source"]) url_default = self.tp.get_url() self.tp.vp_youtube_check_videos(count=2) url_ids = self.tp.parameter_from_url(self.tp.str_gr_video) self.open_current_url_in_new_tab() self.tp.vp_youtube_verify_selected_videos_dd("2 Videos") url_ids_2 = self.tp.parameter_from_url(self.tp.str_gr_video) assert_that(url_ids).is_equal_to(url_ids_2) self.switch_to_first_tab() # step 12 self.tp.open_url(url_default) self.tp.youtube_change_sources(param=["Playlists", "Suggested Videos"], dd="vp") self.tp.verify_params_in_url({self.tp.str_gr_source: "playlists,suggested_videos"}) self.open_current_url_in_new_tab() source_ui = self.tp.get_current_source(param="vp_youtube") assert_that(source_ui).is_equal_to("2 Sources") self.tp.verify_params_in_url({self.tp.str_gr_source: "playlists,suggested_videos"}) self.replace_param_in_url(self.tp.str_gr_source, "playlists%2Csuggested_videos", "playlists") source_ui = self.tp.get_current_source(param="vp_youtube") assert_that(source_ui).is_equal_to("Playlists") self.tp.verify_params_in_url({self.tp.str_gr_source: "playlists"}) self.replace_param_in_url(self.tp.str_gr_source, "playlists", "test") self.verify_url(default_url) self.switch_to_first_tab() # step 16 self.tp.market_dd_choose_few_countries(param=[self.tp.all_markets], tab="youtube_vp") self.tp.verify_params_in_url({self.tp.str_gr_country: 0}) # step 17 self.tp.select_previous_mounth_period() start_date = self.tp.get_calendar_start_date() end_date = self.tp.get_url_end_date() self.tp.verify_params_in_url({self.tp.str_gr_start_date: start_date, self.tp.str_gr_end_date: end_date}) @allure.step("Open current url in new browser tab") def open_current_url_in_new_tab(self): current_url = self.tp.get_url() self.cp.switch_to_tab(2) self.tp.open_url(current_url) @allure.step("Switch to first browser tab") def switch_to_first_tab(self): self.cp.switch_to_tab(1) @allure.step("Replace param in url") def replace_param_in_url(self, param, old, new): url_to_go = self.tp.get_url().replace(f"{param}={old}", f"{param}={new}") self.tp.open_url(url_to_go) self.log.info("parameter replaced") @allure.step("Verify url") def verify_url(self, url_exp): self.tp.is_graph_period_displayed() url_current = self.tp.get_url() assert_that(url_exp).is_equal_to(url_current)