import logging import operator import time import allure from assertpy import assert_that from ui_automation_framework.core import BasePage, TestStatus from ui_automation_framework.utils import AppConfig, CoreConfig from ui_automation_framework.utils import logger as cl from app.api_client import ApiClient from app.src.pages.my_starred_tracks_page import MyStarredTracksPage from app.src.pages.track_page import TrackPage class AlbumPage(BasePage): log = cl.Logger(logging.DEBUG) COUNTRIES_TAB = "countries" ALBUM_TAB = "album" TRACK_TAB = "tracks" def __init__(self, driver): super().__init__(driver) self.driver = driver self.album_page = self.get_page_locators("AlbumPage", "album_elements.json") self.trackPage = TrackPage(self.driver) self.api_client = ApiClient() self.ts = TestStatus(self.driver) self.my_starred_tracks_page = MyStarredTracksPage(self.driver) @allure.step("Album page - get save and skips streams") def get_save_and_skips(self): self.scroll_to_element(*self.locator(self.album_page, "save_and_skips")) self.wait_for_element_visible(*self.locator(self.album_page, "save_and_skips")) values_el = self.get_elements(*self.locator(self.album_page, "save_and_skips")) values = [int(str(self.get_text(element=v)).replace(",", "").replace("%", "")) for v in values_el] self.log.info("save and skips values from ui: {}".format(values)) return values @allure.step("Album page - open album page") def open_album_page(self, album): self.open_url(f"{CoreConfig.ENV_BASE_URL}/spotify/album/{album}") @allure.step("Album page - verify save and skips") def verify_save_and_skips(self, isrcs, market, token): save_skips_ui = self.get_save_and_skips() start = str(self.trackPage.get_calendar_start_date()) end = str(self.trackPage.get_calendar_end_date()) title = self.wait_for_element_visible(*self.locator(self.album_page, "performance_title")) self.click_element(element=title) response_api = self.api_client.get_spotify_demographics_delphi_isrcs(isrcs=isrcs, start_date=start, end_date=end, market=market, token=token) save_skips_api = [ response_api["body"][0]["streams"], response_api["body"][0]["saves"]["total"], ] self.ts.markFinal( save_skips_ui[1:] == save_skips_api[1:], "save and skips ui and api are equal: ui: {}, api: {}".format(save_skips_ui, save_skips_api), ) self.ts.markFinal( round(save_skips_ui[0] / save_skips_api[0], 2) in (save_skips_api[0] / 100.0 for save_skips_api[0] in range(98, 102)), "streams ui and api are equal: ui: {}, api: {}".format( round(save_skips_ui[0] / save_skips_api[0], 2), list(save_skips_api[0] / 100.0 for save_skips_api[0] in range(98, 102)), ), ) @allure.step("Album page - track performance verify streams ages and genders") def track_performance_verify_streams_age_and_gender(self, dsp, market, isrcs, token): start_date = str(self.trackPage.get_calendar_start_date()) end_date = str(self.trackPage.get_calendar_end_date()) title = self.wait_for_element_visible(*self.locator(self.album_page, "performance_title")) self.click_element(element=title) self.trackPage.track_performance_verify_age_groups(dsp=dsp) self.trackPage.track_performance_verify_genders(dsp=dsp) age_tooltip_info = self.trackPage.get_age_groups_tooltip_info() age_streams_ui = age_tooltip_info["streams"] age_percentage_ui = age_tooltip_info["percentage"] gender_tooltip_info = self.trackPage.get_gender_groups_tooltip_info() gender_streams_ui = gender_tooltip_info["streams"] gender_percentage_ui = gender_tooltip_info["percentage"] streams_api = self.get_streams_age_gender_api(dsp=dsp, market=market, isrcs=isrcs, start_date=start_date, end_date=end_date, token=token) self.ts.markFinal(streams_api["ages"] == age_streams_ui, "ages ui: {}, api: {}".format(age_streams_ui, streams_api["ages"])) self.ts.markFinal( streams_api["genders"] == gender_streams_ui, "genders ui: {}, api: {}".format(gender_streams_ui, streams_api["genders"]), ) for p in age_percentage_ui: p_expected = round(age_streams_ui[age_percentage_ui.index(p)] / sum(gender_streams_ui) * 100, 1) self.ts.markFinal( round(p_expected - 0.1, 1) <= p <= round(p_expected + 0.1, 1), "age percentage is actual: {}, expected: {}".format(p, p_expected), ) for p in gender_percentage_ui: p_expected = round(gender_streams_ui[gender_percentage_ui.index(p)] / sum(gender_streams_ui) * 100, 1) self.ts.markFinal( round(p_expected - 0.1, 1) <= p <= round(p_expected + 0.1, 1), "gender percentage is actual: {}, expected: {}".format(p, p_expected), ) @allure.step("Album page - get streams for genders and ages from api delphi") def get_streams_age_gender_api(self, market, isrcs, start_date, end_date, token, dsp): if dsp == AppConfig.get("dsp")["spotify"]: api_response = self.api_client.get_spotify_demographics_delphi_isrcs(market=market, isrcs=isrcs, start_date=start_date, end_date=end_date, token=token)["body"] ages = [0, 0, 0, 0, 0, 0, 0, 0] for age in dict(api_response[0]["age_bands"]).keys(): if "all" not in age: if "0_17" in age: ages[0] = ages[0] + sum((i["age_bands"]).get(age) for i in api_response) elif "18_22" in age: ages[1] = ages[1] + sum((i["age_bands"]).get(age) for i in api_response) elif "23_27" in age: ages[2] = ages[2] + sum((i["age_bands"]).get(age) for i in api_response) elif "28_34" in age: ages[3] = ages[3] + sum((i["age_bands"]).get(age) for i in api_response) elif "35_44" in age: ages[4] = ages[4] + sum((i["age_bands"]).get(age) for i in api_response) elif "45_59" in age: ages[5] = ages[5] + sum((i["age_bands"]).get(age) for i in api_response) elif "60" in age: ages[6] = ages[6] + sum((i["age_bands"]).get(age) for i in api_response) elif "unknown" in age: ages[7] = ages[7] + sum((i["age_bands"]).get(age) for i in api_response) genders = [0, 0, 0, 0] for gender in dict(api_response[0]["age_bands"]).keys(): if "all" not in gender: if "female" in gender: genders[0] = genders[0] + sum((i["age_bands"]).get(gender) for i in api_response) elif "male" in gender: genders[1] = genders[1] + sum((i["age_bands"]).get(gender) for i in api_response) elif "neutral" in gender: genders[2] = genders[2] + sum((i["age_bands"]).get(gender) for i in api_response) elif "unknown" in gender: genders[3] = genders[3] + sum((i["age_bands"]).get(gender) for i in api_response) elif dsp == AppConfig.get("dsp")["apple"]: api_response = self.api_client.get_apple_demographics_delphi_isrcs(market=market, isrcs=isrcs, start_date=start_date, end_date=end_date, token_mobile=token)["body"][0] ages = [0, 0, 0, 0, 0, 0, 0, 0] self.log.info("age bands: {}".format(api_response["age_bands"])) self.log.info("genders: {}".format(api_response["genders"])) self.log.info("age keys: {}".format(dict(api_response["age_bands"]).keys())) self.log.info("gender keys: {}".format(dict(api_response["genders"]).keys())) for age in dict(api_response["age_bands"]).keys(): if "all" not in age: if "0_17" in age: ages[0] = ages[0] + dict(api_response["age_bands"]).get(age) elif "18_24" in age: ages[1] = ages[1] + dict(api_response["age_bands"]).get(age) elif "25_34" in age: ages[2] = ages[2] + dict(api_response["age_bands"]).get(age) elif "35_44" in age: ages[3] = ages[3] + dict(api_response["age_bands"]).get(age) elif "45_54" in age: ages[4] = ages[4] + dict(api_response["age_bands"]).get(age) elif "55_64" in age: ages[5] = ages[5] + dict(api_response["age_bands"]).get(age) elif "65" in age: ages[6] = ages[6] + dict(api_response["age_bands"]).get(age) elif "unknown" in age: ages[7] = ages[7] + dict(api_response["age_bands"]).get(age) genders = [0, 0, 0] for gender in dict(api_response["age_bands"]).keys(): if "all" not in gender: if "female" in gender: genders[0] = genders[0] + dict(api_response["age_bands"]).get(gender) elif "male" in gender: genders[1] = genders[1] + dict(api_response["age_bands"]).get(gender) elif "unknown" in gender: genders[2] = genders[2] + dict(api_response["age_bands"]).get(gender) self.log.info("delphi api: ages: {}, genders: {}".format(ages, genders)) self.ts.markFinal(sum(ages) == sum(genders), "sum ages: {} and genders: {} are equal".format(sum(ages), sum(genders))) return {"ages": ages, "genders": genders} @allure.step("Album page - get streams for genders and ages from api delphi") def select_dsp(self, param): dd = "//*[contains(@id, 'dsp-dd')]" loc = f"{dd}/..//*[text()='{param}']" self.scroll_to_element(dd, "xpath") dsp_dd = self.wait_for_element_clickable(dd, "xpath") self.click_on_element_js(element=dsp_dd) dsp = self.wait_for_element_visible(loc, "xpath") self.click_on_element_js(element=dsp) @allure.step("Album page - AP switch to tab") def switch_to_tab(self, param): tab = self.wait_for_element_visible(f"//*[contains(@id, 'album-tab-{param.lower()}')]", "xpath") self.click_element(element=tab) time.sleep(1) @allure.step("Album page - get playlist title") def get_album_title(self): album_title_element = self.get_element(*self.locator(self.album_page, "album_title")) self.wait_for_element_visible(album_title_element) album_title = self.get_text(element=album_title_element) self.log.info("Album title is " + album_title) return album_title @allure.step("Album page - title is present") def album_title_is_present(self): self.wait_for_element_visible(*self.locator(self.album_page, "album_title")) album_title = self.is_element_displayed(*self.locator(self.album_page, "album_title")) self.log.info("Album title is displayed" + str(album_title)) assert_that(album_title).is_true() @allure.step("AP - click export") def click_export(self): export_selector = "//*[contains(@id, '-export-btn') and contains(@id, '-performance-')]" export_button = self.trackPage.wait_for_element_clickable(export_selector, "xpath") self.trackPage.click_element(element=export_button) @allure.step("Stream and source - verify export") def verify_export_album_track(self, market, ap=False, album_tab="", markets=[], add=""): dsp_ui = self.trackPage.get_current_dsp() track_name = self.trackPage.get_track_title(ap) if ap: self.click_export() else: self.trackPage.click_export() self.trackPage.click_export_as_csv() if album_tab != "Track": column_all_streams = "All Streams" if dsp_ui in [AppConfig.get("dsp")["spotify"], AppConfig.get("dsp")["amazon"], AppConfig.get("dsp")["apple"]]: streams_ui = int(self.trackPage.get_streams_in_period_total().replace(",", "")) else: streams_ui = self.trackPage.get_streams_in_period_total_combined() if len(markets) == 1: market = markets[0].upper() file_path = f"http://{CoreConfig.SELENOID_HOST}:4444/download/{self.trackPage.driver.session_id}/{track_name} - {market} - {dsp_ui}{add}.csv" else: file_path = f"http://{CoreConfig.SELENOID_HOST}:4444/download/{self.trackPage.driver.session_id}/Album Tracks – {track_name}{add}.csv" column_all_streams = "Streams" start_date = self.trackPage.get_calendar_start_date() end_date = self.trackPage.get_calendar_end_date() ids_loc = "//*[contains(@href, '/track/')]" self.trackPage.wait_for_element_visible(locator=ids_loc, locator_type="xpath") ids = self.trackPage.get_elements(locator=ids_loc, locator_type="xpath") ids = [self.trackPage.get_attribute_value(element=i, attribute="href").split("/")[-1] for i in ids] isrcs = [self.api_client.get_isrc_by_spotify_id(market="_gl", id=i)["external_ids"]["isrc"] for i in ids] self.log.info(f"isrcs for track tab: {isrcs}") spotify_totals = [self.api_client.get_track_per_country(isrc=i, start_date=start_date, end_date=end_date, vendor="spotify") for i in isrcs] apple_totals = [self.api_client.get_track_per_country(isrc=i, start_date=start_date, end_date=end_date, vendor="apple") for i in isrcs] spotify_totals = sum(sum(sum(d["streams"] for d in r["data"]) for r in z if r["countryCode"] in markets) for z in spotify_totals) apple_totals = sum(sum(sum(d["streams"] for d in r["data"]) for r in z if r["countryCode"] in markets) for z in apple_totals) if dsp_ui == AppConfig.get("dsp")["spotify"]: streams_ui = spotify_totals elif dsp_ui == AppConfig.get("dsp")["apple"]: streams_ui = apple_totals else: streams_ui = spotify_totals + apple_totals self.log.info(f"file path: {file_path}") data = self.trackPage.read_from_csv(file_path) file_streams_sum = sum(data.dropna().get(column_all_streams).to_list()) self.log.info(f"dsp: {dsp_ui}, streams: {streams_ui}, {file_streams_sum}") assert_that(streams_ui).is_equal_to(file_streams_sum) @allure.step("Get album id from url") def get_album_id_from_url(self): url = self.get_url() album_id = url.split("/")[-1] return album_id @allure.step("Album - API get By Markets Streams") def get_streams_by_markets_api(self, isrcs, source_spotify="all", source_apple="all", source_amazon="all"): start = self.trackPage.get_calendar_start_date() end = self.trackPage.get_calendar_end_date() # sources_spotify = ["sourceCollection", "sourceOthersPlaylist", "sourceReleaseRadar", "sourceDiscoverWeekly", # "sourceRadio", "sourceDailyMix", "sourceChart", "sourcePlayQueue", "sourceAlbum", # "sourceArtist", "sourceSearch", "sourceOther"] # sources_apple = ['0', '1', '2', '3', '4', '5', '6', '7'] # sources_amazon = ["auto_playlist", "recently_added", "recently_played", "user_playlist", "genre", # 'songs', 'album', 'artist', 'search', # "gno_prime_playlist", "gno_unl_playlist", "golden_playlist", "prime_playlist", "shared_playlist", "unlimited_playlist", # "personalize_playlist", # "amf_station_seed", "custom_mix", "error", "prime_station", "prime_station_seed", "similarity", "similarity_station", "station", # "undefined", # "unknown", "unl_station_seed", "unlimited_station", "unlimited_station_se"] # if source_spotify != 'all': # sources_spotify = source_spotify # if source_apple != 'all': # sources_apple = source_apple # if source_amazon != 'all': # sources_amazon = source_amazon # dsp spotify api_spotify_resp = [self.api_client.get_track_per_country(isrc=i, start_date=start, end_date=end, vendor="spotify") for i in isrcs] api_spotify_days = [[{a["countryCode"]: len(list(set(s["date"]) for s in a["data"]))} for a in b] for b in api_spotify_resp] if source_spotify == "all": api_spotify_streams = [[{a["countryCode"]: sum(s["streams"] for s in a["data"])} for a in b] for b in api_spotify_resp] else: api_spotify_streams = [[{a["countryCode"]: sum(s[ks] for s in a["data"] for ks in source_spotify)} for a in b] for b in api_spotify_resp] new_resp = [] for a in api_spotify_streams: new_resp = new_resp + a new_resp_days = [] for a in api_spotify_days: new_resp_days = new_resp_days + a self.log.info(f"new resp days spotify: {new_resp_days}") keys_spotify = list(set(list(k.keys())[0] for k in new_resp)) result_spotify_days = {} for d in new_resp_days: if list(d.keys())[0] in result_spotify_days.keys(): result_spotify_days[list(d.keys())[0]] = max(result_spotify_days[list(d.keys())[0]], d.get(list(d.keys())[0])) else: result_spotify_days.update(d) # self.log.info(f'spotify days count: {result_spotify_days}') self.log.info(f"keys all spotify: {keys_spotify}, \nlen: {len(keys_spotify)}") result_spotify = {} for d in new_resp: if list(d.keys())[0] in result_spotify.keys(): result_spotify[list(d.keys())[0]] += d.get(list(d.keys())[0]) else: result_spotify.update(d) result_spotify = dict(sorted(result_spotify.items(), key=operator.itemgetter(1), reverse=True)) self.log.info(f'spotify total: {result_spotify["_gl"]}\nby markets: {result_spotify}') spotify_average = {} for k in result_spotify.keys(): spotify_average[k] = self.trackPage.apply_rounding_percentage(result_spotify[k] / result_spotify_days[k]) self.log.info(f"spotify average: {spotify_average}") spotify_api_res = {"views": result_spotify, "avg": spotify_average} # dsp apple api_apple_resp = [self.api_client.get_track_per_country(isrc=i, start_date=start, end_date=end, vendor="apple") for i in isrcs] if source_apple == "all": api_apple = [[{a["countryCode"]: sum(s["streams"] for s in a["data"])} for a in b] for b in api_apple_resp] else: api_apple = [[{a["countryCode"]: sum(s["source"][ks] for s in a["data"] for ks in source_apple)} for a in b] for b in api_apple_resp] # self.log.info(f'\n\n\n\n\n\n\n\n\n\n\n\n\n\napi apple resp: {api_apple_resp}\n\n\n\n\n\n\n\n\n\n\n') new_resp = [] for a in api_apple: new_resp = new_resp + a keys_apple = list(set(list(k.keys())[0] for k in new_resp)) # self.log.info(f'keys all: : {keys_apple}') result_apple = {} for d in new_resp: if list(d.keys())[0] in result_apple.keys(): result_apple[list(d.keys())[0]] += d.get(list(d.keys())[0]) else: result_apple.update(d) result_apple = dict(sorted(result_apple.items(), key=operator.itemgetter(1), reverse=True)) # self.log.info(f'apple total: {result_apple["_gl"]}\nby markets: {result_apple}') api_apple_days = [[{a["countryCode"]: [s["date"] for s in a["data"]]} for a in b] for b in api_apple_resp] new_resp_days_a = [] for a in api_apple_days: new_resp_days_a = new_resp_days_a + a result_apple_days = {} for d in new_resp_days_a: if list(d.keys())[0] in result_apple_days.keys(): result_apple_days[list(d.keys())[0]] += d.get(list(d.keys())[0]) else: result_apple_days.update(d) for k in result_apple_days.keys(): result_apple_days[k] = len(list(set(result_apple_days[k]))) self.log.info(f"apple days count: {result_apple_days}") apple_average = {} for k in result_apple.keys(): apple_average[k] = self.trackPage.apply_rounding_percentage(result_apple[k] / result_apple_days[k]) self.log.info(f"apple average: {apple_average}") apple_api_res = {"views": result_apple, "avg": apple_average} # amazon result_amazon = {} amazon_average = {} amazon_api_res = {} result_amazon_days = {} keys_amazon = [] if "/spotify/track/" in self.get_url(): api_amazon_resp = [self.api_client.get_amazon_tracks(isrc=i, start_date=start, end_date=end) for i in isrcs] keys_amazon = list(list(set(a["country_code"] for a in b["items"]) for b in api_amazon_resp)[0]) self.log.info(f"keys amazon: {keys_amazon}") if source_amazon == "all": api_amazon = [{cc: sum(a["streams"] for a in b["items"] if a["country_code"] == cc)} for b in api_amazon_resp for cc in keys_amazon] else: api_amazon = [{cc: sum(a["selection_source_type"][sst] for a in b["items"] if a["country_code"] == cc)} for b in api_amazon_resp for cc in keys_amazon for sst in source_amazon] for d in api_amazon: if list(d.keys())[0] in result_amazon.keys(): result_amazon[list(d.keys())[0]] += d.get(list(d.keys())[0]) else: result_amazon.update(d) result_amazon = dict(sorted(result_amazon.items(), key=operator.itemgetter(1), reverse=True)) # self.log.info(f'amazon total: {result_amazon["worldwide"]}\nby markets: {result_amazon}') api_amazon_days = [{cc: len(list(a["date"] for a in b["items"] if a["country_code"] == cc))} for b in api_amazon_resp for cc in keys_amazon] for d in api_amazon_days: if list(d.keys())[0] in result_amazon_days.keys(): result_amazon_days[list(d.keys())[0]] = max(result_amazon_days[list(d.keys())[0]], d.get(list(d.keys())[0])) else: result_amazon_days.update(d) # self.log.info(f'amazon days count: {result_amazon_days}') result_amazon["_gl"] = result_amazon.pop("worldwide") result_amazon_days["_gl"] = result_amazon_days.pop("worldwide") for k in result_amazon.keys(): amazon_average[k] = self.trackPage.apply_rounding_percentage(result_amazon[k] / result_amazon_days[k]) self.log.info(f"amazon average: {amazon_average}") amazon_api_res = {"views": result_amazon, "avg": amazon_average} # all streams all_resp = {k: result_spotify.get(k, 0) + result_apple.get(k, 0) + result_amazon.get(k, 0) for k in set(list(result_spotify.keys()) + list(result_apple.keys()) + list(result_amazon.keys()))} all_resp = dict(sorted(all_resp.items(), key=operator.itemgetter(1), reverse=True)) # self.log.info(f'all streams total: {all_resp["_gl"]}\nby markets: {all_resp}') result_days = {} for k in list(set(keys_spotify + keys_apple + keys_amazon)): result_days[k] = max(result_spotify_days[k] if result_spotify_days.get(k) else 0, result_apple_days[k] if result_apple_days.get(k) else 0, result_amazon_days[k] if result_amazon_days.get(k) else 0) # self.log.info(f'all days total: {result_days["_gl"]}\nby markets: {result_days}') all_average = {} for k in all_resp.keys(): all_average[k] = self.trackPage.apply_rounding_percentage(all_resp[k] / result_days[k]) self.log.info(f"all average: {all_average}") all_api_res = {"views": all_resp, "avg": all_average} all_values = {"spotify": spotify_api_res, "apple": apple_api_res, "amazon": amazon_api_res, "total_streams": all_api_res} self.log.info(f"all values: {all_values}") return all_values @allure.step("Star track and verify that it is starred") def star_track_in_album_page(self): locator = "//span[contains(@class, 'icon-star')]/ancestor::div[1]" self.wait_for_element_visible(locator=locator, locator_type="xpath") self.scroll_to_element(locator=locator, locator_type="xpath") icons_list = self.get_elements(locator=locator, locator_type="xpath") first_track_star_color = icons_list[0].get_attribute("style") self.log.info(f"star color before: {first_track_star_color}") assert_that(first_track_star_color).is_equal_to(self.my_starred_tracks_page.UNSTARRED_TRACK_ICON_COLOR) self.click_on_element_js(element=icons_list[0]) starred_hint = self.wait_for_element_visible(locator="//*[text()='Track successfully starred']", locator_type="xpath") hint = self.get_text(element=starred_hint) assert_that(hint).is_equal_to("Track successfully starred") self.wait_for_element_visible(locator=locator, locator_type="xpath") time.sleep(2) icons_list = self.get_elements(locator=locator, locator_type="xpath") first_track_star_color = icons_list[0].get_attribute("style") self.log.info(f"star color after: {first_track_star_color}") assert_that(first_track_star_color).is_equal_to(self.my_starred_tracks_page.STARRED_TRACK_ICON_COLOR) @allure.step("Unstar track and verify that it is unstarred") def unstar_track_in_album_page(self): locator = "//span[contains(@class, 'icon-star')]/ancestor::div[1]" self.wait_for_element_visible(locator=locator, locator_type="xpath") icons_list = self.get_elements(locator=locator, locator_type="xpath") first_track_star_color = icons_list[0].get_attribute("style") self.log.info(f"star color before: {first_track_star_color}") assert_that(first_track_star_color).is_equal_to(self.my_starred_tracks_page.STARRED_TRACK_ICON_COLOR) self.click_on_element_js(element=icons_list[0]) starred_hint = self.wait_for_element_visible(locator="//*[text()='Track successfully unstarred']", locator_type="xpath") hint = self.get_text(element=starred_hint) assert_that(hint).is_equal_to("Track successfully unstarred") self.wait_for_element_visible(locator=locator, locator_type="xpath") time.sleep(2) icons_list = self.get_elements(locator=locator, locator_type="xpath") first_track_star_color = icons_list[0].get_attribute("style") self.log.info(f"star color after: {first_track_star_color}") assert_that(first_track_star_color).is_equal_to(self.my_starred_tracks_page.UNSTARRED_TRACK_ICON_COLOR) @allure.step("Get track data from tracks list") def get_track_data_from_tracks_list(self, track_number): locator_track_id = f"//*[contains(@id, 'album-table-cell-track-name-{track_number}')]//a" locator_track_name = f"//*[contains(@id, 'album-table-cell-track-name-{track_number}')]//a" locator_track_artists = f"//div[@id='album-table-cell-artist-names-{track_number}']//a" track_link = self.get_element(locator=locator_track_id, locator_type="xpath") track_id = track_link.get_attribute("href").split("/")[-1] track_name = self.get_text(locator=locator_track_name, locator_type="xpath") track_artists_list = self.get_elements(locator=locator_track_artists, locator_type="xpath") track_artists = [self.get_text(element=t) for t in track_artists_list] track_artists_final = [t.replace(",", "") for t in track_artists] track_data = {"track_id": track_id, "track_name": track_name, "track_artists": track_artists_final} self.log.info("Track data: " + str(track_data)) return track_data @allure.step("AP - Get isrcs from details") def get_isrcs_from_details(self): ids_loc = "//*[contains(@href, '/track/')]" self.trackPage.wait_for_element_visible(locator=ids_loc, locator_type="xpath") ids = self.trackPage.get_elements(locator=ids_loc, locator_type="xpath") ids = [self.trackPage.get_attribute_value(element=i, attribute="href").split("/")[-1] for i in ids] isrcs = [self.api_client.get_isrc_by_spotify_id(market="_gl", id=i)["external_ids"]["isrc"] for i in ids] return isrcs @allure.step("AP - Get UPC") def get_upc(self): locator = '//a[contains(@href, "/album")]/following-sibling::div' elements = self.get_elements(locator=locator, locator_type="xpath") album_els = [self.get_text(element=e) for e in elements] album_info = "".join(album_els).replace("\n", ",").replace("Released: ", "").replace("UPC: ", "").replace("Label: ", "").split(",") album_info_keys = ["Released", "UPC", "Label"] album_data = dict(zip(album_info_keys, album_info)) self.log.info("Album info: " + str(album_data)) return album_data