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.album_page import AlbumPage from app.src.pages.apple_playlist_page import ApplePlaylistPage from app.src.pages.comparison_page import TrackComparisonPage from app.src.pages.left_navigation_panel import LeftNavigationPanel 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): date_to_check_ui = "10/10/2020" date_to_check_url = "2020-10-10" two_markets = "2 Markets" countries_url = "&str_gr_country=ca%2Cus" url_date_range = f"{countries_url}&str_gr_start_date=2020-10-01&str_gr_end_date=2020-10-31" total_amazon_exp = "357,343" values_exp = [9017411, 1214060, 1735622, 56286, 37389, 0, 1698579, 4275475] device_types_exp = [4658522, 3487285, 326445, 545159] os_types_exp = [4605081, 1213694, 2322291, 10236, 63412, 802697] totals_by_dsp_all_exp = ["77,866,277", "2,511,815"] totals_by_dsp_exp = totals_by_dsp_all_exp + [ "45,852,497\n(58.9%)", "1,479,113", "23,354,759\n(30.0%)", "753,379", "8,659,021\n(11.1%)", "279,323", ] total_all_streams_exp = "9,017,411" daily_all_streams_exp = "290,884" tooltip_amazon_exp = f"""Saturday, {date_to_check_ui} Search Artist Album Songs Station Playlists User Playlist 0 (0%) 1,457 (0%) 3,160 (1%) 58,465 (16%) 197,702 (55%) 52,727 (15%) 43,832 (12%) Total {total_amazon_exp}""" tooltip_by_dsp_exp = f"""Saturday, {date_to_check_ui} Spotify Apple Music Amazon 1,614,820 (58%) 829,783 (30%) 357,343 (13%) Total 2,801,946""" tooltip_total_streams_exp = f"""Saturday, {date_to_check_ui} Total 2,801,946 (100%)""" @pytest.fixture(autouse=True) def classSetup(self): self.loginPage = LoginPage(self.driver) self.tp = TrackPage(self.driver) self.ap = AlbumPage(self.driver) self.app = ApplePlaylistPage(self.driver) self.cp = TrackComparisonPage(self.driver) self.leftPanel = LeftNavigationPanel(self.driver) self.ts = TestStatus(self.driver) @allure.story("AP-4775") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-4526] Data recalculation for multiple selected markets. AMAZON. - STEP 1-7") @allure.description("""TC verifies that after selecting several markets data on the UI is recalculated properly. - STEP 1-7""") def test_amazon_multiple_markets_calculation_steps_1_7(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"]) url_before = self.tp.get_url() self.tp.select_dsp(AppConfig.get("dsp")["spotify"]) # step 1-2 streams_before = self.tp.get_streams_in_period_total() self.tp.open_current_url_with_param(self.url_date_range) streams_after = self.tp.get_streams_in_period_total() self.ts.markFinal(streams_before != streams_after, f"STEP 1-2: {streams_before}\nand {streams_after} are diff") # step 3 self.tp.select_dsp(AppConfig.get("dsp")["amazon"]) url_month = self.tp.get_url() markets = self.tp.graph_get_selected_market() self.ts.markFinal(markets == self.two_markets, f"STEP 3: markets are: {markets}") # step 4 tooltips = self.tp.graph_get_tooltips() tooltip_ui = [t for t in tooltips if self.date_to_check_ui in t][0] self.ts.markFinal(tooltip_ui == self.tooltip_amazon_exp, f"STEP 4: \n{tooltip_ui}\nand \n{self.tooltip_amazon_exp} match") # step 5 self.tp.open_url(f"{url_before}&str_gr_start_date={self.date_to_check_url}&str_gr_end_date={self.date_to_check_url}{self.countries_url}") self.tp.select_dsp(AppConfig.get("dsp")["amazon"]) for s in [self.tp.dd_by_voice, self.tp.dd_lean_back_forward, self.tp.dd_by_tier]: self.tp.change_source_type(s) total = self.tp.graph_amazon_get_totals()[0] self.ts.markFinal(total == self.total_amazon_exp, f" STEP 5: total is: {total}") self.tp.change_source_type(AppConfig.get("source")["all_streams"]) total = self.tp.graph_amazon_get_totals()[2].split("\n")[0].strip() self.ts.markFinal(total == self.total_amazon_exp, f"total is: {total}") self.tp.select_dsp(AppConfig.get("dsp")["by_dsp"]) total = self.tp.graph_get_legend_by_dsp()[6].split("\n")[0] self.ts.markFinal(total == self.total_amazon_exp, f"total is: {total}") # step 6 self.tp.open_url(url_month) total = self.tp.get_streams_in_period_total() assert_that(total).is_equal_to(self.total_all_streams_exp) # step 7 for s in [self.tp.dd_by_voice, self.tp.dd_lean_back_forward, self.tp.dd_by_tier]: self.tp.change_source_type(s) total = self.tp.graph_amazon_get_totals()[0] daily_avg_ui = self.tp.graph_amazon_get_totals()[1] self.ts.markFinal(total == self.total_all_streams_exp, f"STEP 7: total is: {total}") self.ts.markFinal(daily_avg_ui == self.daily_all_streams_exp, f"daily avg is: {daily_avg_ui}") self.tp.change_source_type(AppConfig.get("source")["all_streams"]) total = self.tp.graph_amazon_get_totals()[2].split("\n")[0].strip() daily_avg_ui = self.tp.graph_amazon_get_totals()[3] self.ts.markFinal(total == self.total_all_streams_exp, f"total is: {total}") self.ts.markFinal(daily_avg_ui == self.daily_all_streams_exp, f"daily avg is: {daily_avg_ui}") self.tp.select_dsp(AppConfig.get("dsp")["by_dsp"]) total = self.tp.graph_get_legend_by_dsp()[6].split("\n")[0] daily_avg_ui = self.tp.graph_get_legend_by_dsp()[7] self.ts.markFinal(total == self.total_all_streams_exp, f"total is: {total}") self.ts.markFinal(daily_avg_ui == self.daily_all_streams_exp, f"daily avg is: {daily_avg_ui}") @allure.story("AP-4775") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-4526] Data recalculation for multiple selected markets. AMAZON. STEP 8-15") @allure.description("""TC verifies that after selecting several markets data on the UI is recalculated properly. STEP 8-15""") def test_amazon_multiple_markets_calculation_steps_8_15(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"]) self.tp.select_dsp(AppConfig.get("dsp")["amazon"]) self.tp.open_current_url_with_param(self.url_date_range) # step 8 values_lb_lf = self.tp.get_lean_values() values_lb_lf = values_lb_lf["lean_forward_by_source"] + values_lb_lf["lean_back_by_source"] values_lb_lf = [sum(values_lb_lf)] + values_lb_lf file_csv = self.tp.export_and_get_csv(columns=self.tp.CSV_AMAZON_BY_SOURCE_COLUMNS) file_values = [sum(file_csv[c]) for c in self.tp.CSV_AMAZON_BY_SOURCE_COLUMNS] self.ts.markFinal(file_values == values_lb_lf, f"STEP 8: {file_values}\nand\n{values_lb_lf} match") self.ts.markFinal(values_lb_lf == self.values_exp, f"{values_lb_lf}\nand {self.values_exp} match") # step 9 device_types = self.tp.get_device_type_tooltips()["streams"] self.ts.markFinal(device_types == self.device_types_exp, f"STEP 9: {device_types} and {self.device_types_exp} match") # step 10 os_types = self.tp.graph_get_os_tooltips()["streams"] self.ts.markFinal(os_types == self.os_types_exp, f"STEP 10: {os_types} and {self.os_types_exp} match") # step 11 self.tp.select_dsp(AppConfig.get("dsp")["by_dsp"]) tooltips = self.tp.graph_get_tooltips() tooltip_ui = [t for t in tooltips if self.date_to_check_ui in t][0] self.ts.markFinal(tooltip_ui == self.tooltip_by_dsp_exp, f"STEP 11: \n{tooltip_ui}\nand \n{self.tooltip_by_dsp_exp} match") # step 12 totals_ui = self.tp.graph_amazon_get_totals(totals="by_dsp") self.ts.markFinal(totals_ui == self.totals_by_dsp_exp, f"STEP 12: {totals_ui}\nand {self.totals_by_dsp_exp} match") # step 13 self.tp.select_dsp(AppConfig.get("dsp")["total_streams"]) tooltips = self.tp.graph_get_tooltips() tooltip_ui = [t for t in tooltips if self.date_to_check_ui in t][0] self.ts.markFinal( tooltip_ui == self.tooltip_total_streams_exp, f"STEP 13: {tooltip_ui}\nand {self.tooltip_total_streams_exp} match", ) # step 14 totals_ui = self.tp.graph_amazon_get_totals(totals="by_dsp") self.ts.markFinal(totals_ui == self.totals_by_dsp_all_exp, f"STEP 14: {totals_ui}\nand {self.totals_by_dsp_all_exp} match") # step 15 self.tp.stream_and_source_choose_region(self.tp.REGION_NORTH_AMERICA) totals_ui = self.tp.graph_amazon_get_totals(totals="by_dsp") self.ts.markFinal(totals_ui == self.totals_by_dsp_all_exp, f"STEP 15: {totals_ui}\nand {self.totals_by_dsp_all_exp} match")