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.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): ex_us_region = "reo" middle_east_region = "rme" north_africa = "rnf" cis = "rcs" south_africa = "rsa" asia = "ras" europe = "reu" latin_iberia = "ril" north_america = "rna" oceania = "roc" regions = [asia, cis, europe, latin_iberia, north_africa, north_america, oceania, south_africa] expected_countries_in_the_list_1 = {"fr", "de", "gb"} expected_countries_in_the_list_2 = {"bh", "eg", "il", "ar", "au"} str_gr_country_all_markets = "0" global_market = AppConfig.get("market")["global"]["name"] argentina_market = AppConfig.get("market")["argentina"]["name"] australia_market = AppConfig.get("market")["australia"]["name"] argentina_in_url = AppConfig.get("market")["argentina"]["market"] australia_in_url = AppConfig.get("market")["australia"]["market"] spotify = AppConfig.get("dsp")["spotify"] apple = AppConfig.get("dsp")["apple"] amazon = AppConfig.get("dsp")["amazon"] total_streams = AppConfig.get("dsp")["total_streams"] by_dsp = AppConfig.get("dsp")["by_dsp"] dsp = [spotify, apple, amazon, total_streams, by_dsp] @pytest.fixture(autouse=True) def classSetup(self): self.loginPage = LoginPage(self.driver) self.tp = TrackPage(self.driver) self.cp = TrackComparisonPage(self.driver) self.ts = TestStatus(self.driver) @allure.issue("https://data-analytics.atlassian.net/browse/AP-5561") @pytest.mark.flaky(reruns=0) @allure.story("AP-4785") @allure.severity(allure.severity_level.NORMAL) @allure.title("Deep linking: Track Performance -> Streams and Sources -> Regions deep linking verification") @allure.description("TC verifies that user can share the link to track page with selected region.") def test_track_performance_regions(self): self.loginPage.login_with_worker() self.tp.select_market(self.global_market) self.tp.open_spotify_track_page(AppConfig.get("track14")["id"]) for d in self.dsp: self.tp.select_dsp(d) # step1 self.tp.stream_and_source_choose_region(self.tp.REGION_EX_US) url_region = self.tp.parameter_from_url(self.tp.str_gr_region) self.ts.markFinal( url_region == self.ex_us_region, "STEP 1: Parameter str_gr_region is added to the deep-linking and has value: " + str(url_region), ) self.check_data_in_new_tab(d, "step1") # step2 self.tp.stream_and_source_deselect_countries([self.argentina_market, self.australia_market]) self.tp.verify_params_not_in_url([self.tp.str_gr_region]) url_countries = self.tp.parameter_from_url(self.tp.str_gr_country) url_countries_list = url_countries.split(",") intersection_list = set(url_countries_list).intersection(self.expected_countries_in_the_list_1) self.tp.log.info("Comparison list: " + str(intersection_list)) self.ts.markFinal( intersection_list == self.expected_countries_in_the_list_1, "STEP 2: URL contains checked markets: " + str(intersection_list), ) self.ts.markFinal( self.argentina_in_url not in url_countries_list, "STEP 2: " + self.argentina_market + " is removed from URL", ) self.ts.markFinal( self.australia_in_url not in url_countries_list, "STEP 2: " + self.australia_market + " is removed from URL", ) self.check_data_in_new_tab(d, "step2") # step3 self.tp.stream_and_source_choose_region(self.tp.REGION_MIDDLE_EAST) self.tp.verify_params_not_in_url([self.tp.str_gr_country]) url_region = self.tp.parameter_from_url(self.tp.str_gr_region) self.ts.markFinal( url_region == self.middle_east_region, "STEP 3: Parameter str_gr_region is added to the deep-linking and has value: " + str(url_region), ) self.check_data_in_new_tab(d, "step3") # step4 self.tp.stream_and_source_add_countries_to_selected([self.australia_market, self.argentina_market]) self.tp.verify_params_not_in_url([self.tp.str_gr_region]) url_countries = self.tp.parameter_from_url(self.tp.str_gr_country) url_countries_list = url_countries.split(",") intersection_list = set(url_countries_list).intersection(self.expected_countries_in_the_list_2) self.tp.log.info("Comparison list: " + str(intersection_list)) assert_that(intersection_list).is_equal_to(self.expected_countries_in_the_list_2) self.check_data_in_new_tab(d, "step4") # step5 regions_without_us_ex_and_middle_east = [x for x in self.tp.REGIONS if x not in [self.tp.REGION_EX_US, self.tp.REGION_MIDDLE_EAST]] self.tp.log.info("Required regions list: " + str(regions_without_us_ex_and_middle_east)) for r, v in zip(regions_without_us_ex_and_middle_east, self.regions): self.tp.stream_and_source_choose_region(param=r) url_region = self.tp.parameter_from_url(self.tp.str_gr_region) self.ts.markFinal( url_region == v, "STEP 5: Parameter str_gr_region is added to the deep-linking and has value: " + str(url_region), ) self.check_data_in_new_tab(d, "step5") # step 6 url_regions = ["roc", "rna", "rnf"] for ur in url_regions: self.tp.go_back() url_region = str(self.tp.parameter_from_url(self.tp.str_gr_region)) self.ts.markFinal(url_region == ur, "STEP 6: Back browser button leads to correct region in url: " + url_region) self.tp.go_back() # step 7 for ur in reversed(url_regions): self.tp.go_forward() url_region = str(self.tp.parameter_from_url(self.tp.str_gr_region)) self.ts.markFinal(url_region == ur, "STEP 7: Forward browser button leads to correct region in url: " + url_region) # step 8 self.tp.stream_and_source_choose_country(self.tp.all_markets) url_all_markets = str(self.tp.parameter_from_url(self.tp.str_gr_country)) self.ts.markFinal( url_all_markets == self.str_gr_country_all_markets, "STEP 8: Related to all markets parameter is added to the url and has value: " + url_all_markets, ) self.check_data_in_new_tab(d, "step8") @allure.step("Data verification in separate tab: url, market drop-down text, total amount") def check_data_in_new_tab(self, dsp, step_number): url = self.tp.get_url() market_dd_text = self.tp.graph_get_selected_market() if self.tp.streams_in_period_graph_is_present(): if dsp in [self.spotify, self.apple, self.amazon]: total = str(self.tp.get_streams_in_period_total()) else: total = str(self.tp.get_streams_in_period_total_combined()) else: total = self.tp.get_streams_in_period_no_data() self.cp.open_new_tab() self.cp.switch_to_tab(2) self.tp.go_to_url(url) url_in_new_tab = self.tp.get_url() market_dd_text_in_new_tab = self.tp.graph_get_selected_market() if self.tp.streams_in_period_graph_is_present(): if dsp in [self.spotify, self.apple, self.amazon]: total_in_new_tab = str(self.tp.get_streams_in_period_total()) else: total_in_new_tab = str(self.tp.get_streams_in_period_total_combined()) else: total_in_new_tab = self.tp.get_streams_in_period_no_data() self.ts.markFinal(url == url_in_new_tab, step_number + ": " + url + " is the same as " + url_in_new_tab) self.ts.markFinal( market_dd_text == market_dd_text_in_new_tab, step_number + ": " + market_dd_text + " is the same as " + market_dd_text_in_new_tab, ) self.ts.markFinal(total == total_in_new_tab, step_number + ": " + total + " is the same as " + total_in_new_tab) self.cp.close_current_tab() self.cp.switch_to_tab(1)