import logging import allure from assertpy import assert_that from ui_automation_framework.core import BasePage, TestStatus from ui_automation_framework.utils import CoreConfig from ui_automation_framework.utils import logger as cl from app.api_client import ApiClient class MyStarredTracksPage(BasePage): log = cl.Logger(logging.DEBUG) PAGE_TITLE = "My Starred Tracks" UNSTARRED_TRACK_ICON_COLOR = "color: rgb(158, 158, 158);" STARRED_TRACK_ICON_COLOR = "color: rgb(252, 187, 36);" def __init__(self, driver): super().__init__(driver) self.driver = driver self.my_starred_tracks_locators = self.get_page_locators("MyStarredTracksPage", "my_starred_tracks_elements.json") self.ts = TestStatus(self.driver) self.api_client = ApiClient() @allure.step("Artist page - get title") def is_title_displayed(self): el = self.wait_for_element_visible(*self.locator(self.my_starred_tracks_locators, "my_starred_tracks_title")) title = self.get_text(element=el) self.log.info("My Starred Tracks title is displayed:" + title) assert_that(title).is_equal_to(self.PAGE_TITLE) @allure.step("Open My Starred Tracks Page") def open_my_starred_tracks_page(self): self.driver.get(CoreConfig.ENV_BASE_URL + "/spotify/starred-tracks") self.page_has_loaded() @allure.step("Delete all starred tracks - spotify and apple") def delete_all_starred_tracks(self, tracks_list, token): for t in range(tracks_list["count"]): if len(tracks_list) > 0: if tracks_list["items"][t]["vendor"] == "spotify": self.api_client.delete_apple_starred_track(isrc=tracks_list["items"][t]["isrc"], id="spotify%3Atrack%3" + tracks_list["items"][t]["id"], token=token) if tracks_list["items"][t]["vendor"] == "apple": self.api_client.delete_apple_starred_track(isrc=tracks_list["items"][t]["isrc"], id=tracks_list["items"][t]["id"], token=token) else: break starred_tracks = self.api_client.get_starred_tracks(token=token) self.log.info("Starred tracks list after delete: " + str(starred_tracks)) @allure.step("Unstar track and verify that it is unstarred") def unstar_track_in_my_starred_tracks_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.STARRED_TRACK_ICON_COLOR) self.click_element(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") @allure.step("MST - get table dates - UI") def get_table_dates(self, loc="//div[@id]/*/*[contains(., '/')][string-length(text()) = 8]"): self.wait_for_element_visible(loc, "xpath") self.page_has_loaded() dates_el = self.get_elements(loc, "xpath") dates = [self.get_text(element=d) for d in dates_el] return dates @allure.step("MST - switch to chart position tab") def switch_to_chart_position(self): loc = "//*[text()='Chart Positions']/parent::*" tab = self.wait_for_element_clickable(loc, "xpath") self.click_element(element=tab)