import logging import time 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.src.pages.my_starred_tracks_page import MyStarredTracksPage class ArtistPage(BasePage): log = cl.Logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver self.artist_page = self.get_page_locators("ArtistPage", "artist_elements.json") self.ts = TestStatus(self.driver) self.my_starred_tracks_page = MyStarredTracksPage(self.driver) @allure.step("Navigating to the specified artist page ") def open_artist_page(self, artist_id): self.driver.get(CoreConfig.ENV_BASE_URL + "/spotify/artist/" + artist_id) self.page_has_loaded() @allure.step("Artist page - verify title") def verify_title(self, title): el = self.wait_for_element_visible(*self.locator(self.artist_page, "artist_title")) title_ui = self.get_text(element=el) self.log.info("artist title is displayed:" + title_ui) title_exp = title.split(",") title_exp = [t.strip() for t in title_exp] self.ts.markFinal(title_ui in title_exp, f"artist title expected: {title_exp}\nui: {title_ui}") @allure.step("Artist page - get title") def get_title(self): el = self.wait_for_element_visible(*self.locator(self.artist_page, "artist_title")) title = self.get_text(element=el) self.log.info("Artist title is displayed:" + title) return title @allure.step("Artist page - title is present") def title_is_present(self): el = self.wait_for_element_visible(*self.locator(self.artist_page, "artist_title")) title = self.is_element_displayed(element=el) self.log.info("Artist title is displayed:" + str(title)) assert_that(title).is_true() @allure.step("Get artist id from url") def get_artist_id_from_url(self): url = self.get_url() artist_id = url.split("/")[-1].split("?")[0] return artist_id @allure.step("Star track and verify that it is starred") def star_track_in_artist_page(self): locator = "//span[contains(@class, 'icon-star')]/ancestor::div[1]" self.wait_for_element_visible(locator=locator, locator_type="xpath") time.sleep(10) 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_element(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("Star track and verify that it is starred") def unstar_track_in_artist_page(self): locator = "//span[contains(@class, 'icon-star')]/ancestor::div[1]" time.sleep(10) 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_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") 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("Artist page - table filtering") def table_filtering(self, text): self.clear_text(*self.locator(self.artist_page, "artist_filter")) self.send_text(text, *self.locator(self.artist_page, "artist_filter")) self.click_element(*self.locator(self.artist_page, "filter_icon")) @allure.step("Artist page - verify No results message after filtering") def verify_no_results_message(self): self.page_has_loaded() no_results = self.wait_for_element_visible(*self.locator(self.artist_page, "table_no_results")) no_results_to_show = self.wait_for_element_visible(*self.locator(self.artist_page, "table_no_results_to_show")) no_results_text = self.get_text(element=no_results) no_results_to_show_text = self.get_text(element=no_results_to_show) assert_that(self.is_element_displayed(element=no_results)).is_true() assert_that(no_results_text).is_equal_to("Try another filter.") assert_that(no_results_to_show_text).is_equal_to("No results to show.")