import logging import time import allure from assertpy import assert_that from selenium.webdriver import ActionChains from ui_automation_framework.core import BasePage, TestStatus from ui_automation_framework.utils import AppConfig from ui_automation_framework.utils import logger as cl from app.api_client import ApiClient from app.mysql_db_client_custom import MySqlClient from app.src.pages.account_page import AccountPage from app.src.pages.album_page import AlbumPage from app.src.pages.amazon_playlist_page import AmazonPlaylistPage from app.src.pages.apple_playlist_page import ApplePlaylistPage from app.src.pages.artist_page import ArtistPage from app.src.pages.spotify_playlist_page import SpotifyPlaylistPage from app.src.pages.track_page import TrackPage class GlobalSearch(BasePage): log = cl.Logger(logging.DEBUG) EXPECTED_HINT = "Search for tracks, playlists, artists, albums or accounts" SEARCH_VALUE = "water" EMPTY_ALBUMS_SEARCH_VALUE = "Taca a Pica na Novinha" ACTIVE_SEARCH_FIELD_COLOR = "rgb(1, 156, 254)" ACTIVE_TAB_COLOR = "rgba(255, 60, 129, 1)" MARKET_HELP_TEXT = "search results are displayed" TOP_RESULTS = "Top Results" TRACKS = "Tracks" PLAYLISTS = "Playlists" ARTISTS = "Artists" ALBUMS = "Albums" ACCOUNTS = "Accounts" tab_names = [TOP_RESULTS, TRACKS, PLAYLISTS, ARTISTS, ALBUMS, ACCOUNTS] playlists = ["spotify", "apple"] MAX_TOP_RESULTS_TRACKS_LIST_LEN = 10 MAX_TOP_RESULTS_SPOTIFY_PLAYLISTS_LEN = 4 MAX_TOP_RESULTS_APPLE_PLAYLISTS_LEN = 2 MAX_TOP_RESULTS_AMAZON_PLAYLISTS_LEN = 2 MAX_TOP_RESULTS_ALBUMS_LEN = 4 MAX_TRACKS_TAB_TRACKS_LIST_LEN = 20 MAX_PLAYLISTS_TAB_PLAYLISTS_LIST_LEN = 20 MAX_ARTISTS_TAB_ARTISTS_LIST_LEN = 20 MAX_ALBUMS_TAB_ALBUMS_LIST_LEN = 20 MAX_ACCOUNTS_TAB_ACCOUNTS_LIST_LEN = 20 MAX_RESENT_SEARCHES_LIST_LEN = 21 top_results_elements = ["track", "playlist-spotify", "playlist-apple", "playlist-amazon", "album"] search_results_elements = ["track", "playlist-spotify", "playlist-apple", "artist", "album", "account"] TRACKS_TAB_NAME_COLUMN = "Name" TRACKS_TAB_ARTIST_COLUMN = "Artist" PLAYLISTS_TAB_SPOTIFY_PLAYLISTS_COLUMN_NAME = "Spotify Playlists" PLAYLISTS_TAB_APPLE_PLAYLISTS_COLUMN_NAME = "Apple Music Playlists" ARTISTS_TAB_NAME_COLUMN = "Name" ALBUMS_TAB_NAME_COLUMN = "Name" ALBUMS_TAB_ARTIST_COLUMN = "Artist" ACCOUNTS_TAB_NAME_COLUMN = "Name" ACCOUNTS_TAB_USERNAME_COLUMN = "Username" ART_SQUARE_SHAPE = "0px" ART_ROUND_SHAPE = "50%" ALBUM_TYPE_SINGLE = "single" def __init__(self, driver): super().__init__(driver) self.driver = driver self.global_search_locators = self.get_page_locators("GlobalSearch", "global_search_elements.json") self.track_locators = self.get_page_locators("TrackPage", "track_page_elements.json") self.sql_client = MySqlClient() self.api_client = ApiClient() self.tp = TrackPage(self.driver) self.sp = SpotifyPlaylistPage(self.driver) self.ap = ApplePlaylistPage(self.driver) self.amazon_playlist = AmazonPlaylistPage(self.driver) self.album_page = AlbumPage(self.driver) self.artist_page = ArtistPage(self.driver) self.account_page = AccountPage(self.driver) self.ts = TestStatus(self.driver) @allure.step("Verify that search field in the Top Header has a hint") def verify_hint_in_search_field_in_top_header(self): self.wait_for_element_visible(*self.locator(self.global_search_locators, "search_field")) self.wait_for_element_clickable(*self.locator(self.global_search_locators, "search_field")) search_field_hint = self.get_attribute_value(*self.locator(self.global_search_locators, "search_field_input"), attribute="placeholder") self.log.info("Search field hint text is: " + str(search_field_hint)) assert_that(search_field_hint).is_equal_to(self.EXPECTED_HINT) @allure.step("Get search field value") def get_global_search_field_value(self): self.wait_for_element_visible(*self.locator(self.global_search_locators, "search_field")) self.wait_for_element_clickable(*self.locator(self.global_search_locators, "search_field")) search_field_value = self.get_attribute_value(*self.locator(self.global_search_locators, "search_field_input"), attribute="value") self.log.info("Search field value is: " + str(search_field_value)) return search_field_value @allure.step("Put focus to the search field") def put_focus_to_the_search_field(self): self.wait_for_element_visible(*self.locator(self.global_search_locators, "search_field")) search = self.wait_for_element_clickable(*self.locator(self.global_search_locators, "search_field")) ActionChains(self.driver).move_to_element(to_element=search).click().pause(2).release().perform() self.page_has_loaded() @allure.step("Verify that search field is in the focus") def verify_search_field_is_in_focus(self): search_field = self.get_element(*self.locator(self.global_search_locators, "search_field_input")) focused_el = self.driver.switch_to.active_element assert_that(search_field).is_equal_to(focused_el) @allure.step("Verify that active search field has a blue frame") def verify_active_search_field_has_blue_frame(self): search_border_color = self.get_element(*self.locator(self.global_search_locators, "search_field")).value_of_css_property("border-color") self.log.info("Border color:" + search_border_color) assert_that(search_border_color).is_equal_to(self.ACTIVE_SEARCH_FIELD_COLOR) @allure.step("Verify that recent search list is empty") def verify_empty_recent_search(self): empty_search_icon = self.is_element_displayed(*self.locator(self.global_search_locators, "no_searches_icon")) empty_search_text = self.is_element_displayed(*self.locator(self.global_search_locators, "no_searches_text")) assert_that(empty_search_icon).is_true() assert_that(empty_search_text).is_true() @allure.step("Click beyond search field") def click_beyond_search_field(self): market = self.get_element(*self.locator(self.track_locators, "market_picker")) action = ActionChains(self.driver).move_to_element(to_element=market) action.perform() action.click().release().perform() @allure.step("Verify search window is not present") def verify_search_window_is_not_present(self): search_window = self.is_element_displayed(*self.locator(self.global_search_locators, "search_window")) self.log.info("Search window is present: " + str(search_window)) assert_that(search_window).is_false() @allure.step("Enter search value to the search field") def enter_search_value(self, value): self.wait_for_element_visible(*self.locator(self.global_search_locators, "search_field")) search = self.wait_for_element_clickable(*self.locator(self.global_search_locators, "search_field")) ActionChains(self.driver).move_to_element(to_element=search).click().perform() ActionChains(self.driver).move_to_element(to_element=search).click().pause(2).click_and_hold(on_element=search).send_keys(value).perform() self.page_has_loaded() @allure.step("Check clear icon") def check_clear_icon(self): clear_icon = self.is_element_displayed(*self.locator(self.global_search_locators, "clear_icon")) assert_that(clear_icon).is_true() @allure.step("Verify if all tabs are present") def verify_all_tabs_are_present(self): self.wait_for_element_visible(*self.locator(self.global_search_locators, "tabs")) tabs = self.get_elements(*self.locator(self.global_search_locators, "tabs")) tab_names = [self.get_text(element=t) for t in tabs] self.log.info("Tab names: " + str(tab_names)) expected_tabs = [n.upper() for n in self.tab_names] assert_that(tab_names).is_equal_to(expected_tabs) @allure.step("Verify search window is not present") def verify_search_tabs_are_not_present(self): search_tabs = self.is_element_displayed(*self.locator(self.global_search_locators, "tabs")) self.log.info("Search tabs are present: " + str(search_tabs)) assert_that(search_tabs).is_false() @allure.step("Clear the search field") def clear_the_search_field(self): clear_icon = self.get_element(*self.locator(self.global_search_locators, "clear_icon")) ActionChains(self.driver).move_to_element(to_element=clear_icon).click().perform() @allure.step("Check which tab is active") def check_active_tab(self, tab): tab_locator = "//*[@id='global-search-tabs']//span[contains(text(), '{}')]".format(tab) self.wait_for_element_visible(locator="//*[@id='global-search-tabs']//span[contains(text(), '{}')]".format(tab), locator_type="xpath") active_tab_color = self.get_element(locator=tab_locator, locator_type="xpath").value_of_css_property("color") active_tab_underlined = self.get_element(locator=tab_locator, locator_type="xpath").value_of_css_property("border-bottom-color") assert_that(active_tab_color).is_equal_to(self.ACTIVE_TAB_COLOR) assert_that(active_tab_underlined).is_equal_to(self.ACTIVE_TAB_COLOR) @allure.step("Open required tab in Global Search window") def open_tab(self, tab_name): tab_locator = "//*[@id='global-search-tabs']//span[contains(text(), '{}')]".format(tab_name) self.log.info("Tab locator" + tab_locator) self.wait_for_element_visible(locator=tab_locator, locator_type="xpath") tab = self.wait_for_element_clickable(locator=tab_locator, locator_type="xpath") self.click_element(element=tab, locator_type="xpath") @allure.step("Get global search target market") def verify_search_target_market(self, market): search_market_locator = "//div[@id='global-search-tab-market-selected']/span[contains(text(), '{}')]".format(market) self.wait_for_element_visible(locator=search_market_locator, locator_type="xpath") search_market_element = self.get_element(locator=search_market_locator, locator_type="xpath") search_market_text = self.get_text(element=search_market_element) self.wait_for_element_visible(*self.locator(self.global_search_locators, "search_market_text")) search_market_help_text_element = self.get_element(*self.locator(self.global_search_locators, "search_market_text")) search_market_help_text = self.get_text(element=search_market_help_text_element) assert_that(search_market_text).is_equal_to(market) assert_that(search_market_help_text).is_equal_to(self.MARKET_HELP_TEXT) @allure.step("Verify Top Results tab elements") def verify_top_results_tab_elements(self): for e in self.top_results_elements: elements = self.get_elements(locator="//a[contains(@id, 'global-search-{}-')]".format(e), locator_type="xpath") elements_art_list = self.get_elements(locator="//*[contains(@id,'global-search-{}') and contains(@id,'-image-cover')]".format(e), locator_type="xpath") if e == "tracks": elements_title_list = self.get_elements(*self.locator(self.global_search_locators, "tracks_titles_list")) else: elements_title_list = self.get_elements(locator="//*[contains(@id,'global-search-{}') and contains(@id,'-image-cover')]".format(e), locator_type="xpath") elements_subtitle_list = self.get_elements(locator="//*[contains(@id,'global-search-{}') and contains(@id,'-subtitle')]".format(e), locator_type="xpath") self.log.info("Subtitles:" + str(elements_subtitle_list)) if e == "tracks": assert_that(len(elements)).is_less_than_or_equal_to(self.MAX_TOP_RESULTS_TRACKS_LIST_LEN) assert_that(len(elements)).is_equal_to(len(elements_subtitle_list)) elif e == "playlist-spotify": assert_that(len(elements)).is_less_than_or_equal_to(self.MAX_TOP_RESULTS_SPOTIFY_PLAYLISTS_LEN) assert_that(len(elements)).is_equal_to(len(elements_subtitle_list)) elif e == "playlist-apple": assert_that(len(elements)).is_less_than_or_equal_to(self.MAX_TOP_RESULTS_APPLE_PLAYLISTS_LEN) elif e == "playlist-amazon": assert_that(len(elements)).is_less_than_or_equal_to(self.MAX_TOP_RESULTS_AMAZON_PLAYLISTS_LEN) elif e == "album": assert_that(len(elements)).is_less_than_or_equal_to(self.MAX_TOP_RESULTS_ALBUMS_LEN) assert_that(len(elements)).is_equal_to(len(elements_subtitle_list)) assert_that(len(elements)).is_greater_than(0) assert_that(len(elements)).is_equal_to(len(elements_art_list)) assert_that(len(elements)).is_equal_to(len(elements_title_list)) @allure.step("Verify hover over element") def verify_hover_over_element(self, element): elements = self.get_elements(locator="//a[contains(@id,'global-search-{}-')]".format(element), locator_type="xpath") if element == "track": elements_names = self.get_elements(locator="//*[contains(@id, 'global-search-{}-') and contains(@id, '-title') and contains(@tag, 'p')]".format(element), locator_type="xpath") else: elements_names = self.get_elements(locator="//*[contains(@id,'global-search-{}-') and contains(@id, '-title')]".format(element), locator_type="xpath") before_hover_element = elements[0].value_of_css_property("font-weight") self.log.info("Before hover: " + str(before_hover_element)) time.sleep(5) ActionChains(self.driver).move_to_element(to_element=elements[0]).perform() after_hover_element = elements_names[0].value_of_css_property("font-weight") self.log.info("After hover: " + str(after_hover_element)) assert_that(before_hover_element).is_not_equal_to(after_hover_element) @allure.step("Verify hover over recent search element") def verify_hover_over_recent_search_element(self, element): self.wait_for_element_visible(locator="//a[contains(@id,'global-search-{}-')]".format(element), locator_type="xpath") elements = self.get_elements(locator="//a[contains(@id,'global-search-recent-{}-')]".format(element), locator_type="xpath") elements_names = self.get_elements(locator="//*[contains(@id,'global-search-recent-{}-') and contains(@id, '-title')]".format(element), locator_type="xpath") before_hover_element = elements[0].value_of_css_property("font-weight") self.log.info("Before hover: " + str(before_hover_element)) time.sleep(5) ActionChains(self.driver).move_to_element(to_element=elements[0]).perform() after_hover_element = elements_names[0].value_of_css_property("font-weight") self.log.info("After hover: " + str(after_hover_element)) assert_that(before_hover_element).is_not_equal_to(after_hover_element) @allure.step("Get tab elements titles") def get_tab_elements_title(self, element): elements = self.get_elements(locator="//a[contains(@id, 'global-search-{}-')]//span[contains(@id,'global-search-{}') and contains(@id,'-title')]".format(element, element), locator_type="xpath") elements_name = [self.get_text(element=e) for e in elements] self.log.info("Titles: " + str(elements_name)) return elements_name @allure.step("Navigate to the element") def navigate_from_tab_to_element(self, element, index=0): if element == "track": elements = self.get_elements(locator="//*[contains(@id, 'global-search-{}-') and contains(@id, '-title') and contains(@tag, 'p')]".format(element), locator_type="xpath") elif element == "album": elements = self.get_elements(locator="//*[contains(@id, 'global-search-{}-') and contains(@id, '-title') and contains(@tag, 'p')]".format(element), locator_type="xpath") else: elements = self.get_elements(locator="//*[contains(@id,'global-search-{}-') and contains(@id,'-title')]".format(element), locator_type="xpath") ActionChains(self.driver).move_to_element(to_element=elements[index]).click().perform() @allure.step("Navigate from recent search to the element") def navigate_from_recent_search_to_element(self, element): elements = self.get_elements(locator="//*[contains(@id, 'global-search-recent-{}-') and contains(@id, '-title')]".format(element), locator_type="xpath") ActionChains(self.driver).move_to_element(to_element=elements[0]).click().perform() @allure.step("Get elements title on Recent Searches") def get_elements_title_on_resent_searches(self): resent_searches_elements = self.get_elements(*self.locator(self.global_search_locators, "resent_search_elements_title")) self.log.info("Resent search elements: " + str(resent_searches_elements)) resent_searches_elements_titles = [] for r in resent_searches_elements: resent_searches_elements_titles.append(self.get_text(element=r)) self.log.info("Resent search elements title: " + str(resent_searches_elements_titles)) return resent_searches_elements_titles @allure.step("Get page title") def get_page_title(self, page): for title in self.search_results_elements: if page == "track": title = self.tp.get_track_title() elif page == "playlist-spotify": title = self.sp.get_playlist_title() elif page == "playlist-apple": title = self.ap.get_playlist_name() self.log.info("Apple playlist page title is: " + title) elif page == "playlist-amazon": title = self.amazon_playlist.get_metadata()["title"] elif page == "artist": title = self.artist_page.get_title() elif page == "album": title = self.album_page.get_album_title() elif page == "account": title = self.account_page.get_title() return title @allure.step("Verify global search Top Results elements") def verify_top_results_elements(self, elements): for e in elements: self.enter_search_value(self.SEARCH_VALUE) time.sleep(5) names = self.get_tab_elements_title(e) self.navigate_from_tab_to_element(e) self.verify_search_window_is_not_present() title = self.get_page_title(e) assert_that(names[0]).is_equal_to(title) if e == "playlist-apple": owner = self.ap.playlist_get_owner_name() if owner == "N/A": continue if e != "playlist-amazon": self.put_focus_to_the_search_field() resent_searches_elements_title = self.get_elements_title_on_resent_searches() assert_that(title).is_equal_to(resent_searches_elements_title[0]) @allure.step("Verify Tracks tab elements") def verify_tracks_tab_elements(self): self.page_has_loaded() self.wait_for_element_visible(*self.locator(self.global_search_locators, "tracks_tab_column_name")) name_column = self.get_text(*self.locator(self.global_search_locators, "tracks_tab_column_name")) artist_column = self.get_text(*self.locator(self.global_search_locators, "tracks_tab_column_artist")) tracks_art_list = self.get_elements(*self.locator(self.global_search_locators, "tracks_art_list")) tracks_list = self.get_elements(locator="//*[@id='global-search-track-container']//a[contains(@id, 'global-search-track')]", locator_type="xpath") self.log.info("Track list len: " + str(len(tracks_list))) track_art_shape = tracks_art_list[0].value_of_css_property("border-radius") self.log.info("CSS property border-radius is: " + str(track_art_shape)) assert_that(track_art_shape).is_equal_to(self.ART_SQUARE_SHAPE) assert_that(name_column).is_equal_to(self.TRACKS_TAB_NAME_COLUMN) assert_that(artist_column).is_equal_to(self.TRACKS_TAB_ARTIST_COLUMN) assert_that(len(tracks_list)).is_greater_than(0) assert_that(len(tracks_list)).is_less_than_or_equal_to(self.MAX_TRACKS_TAB_TRACKS_LIST_LEN) @allure.step("Verify Tracks tab columns names are a stick after scroll down") def verify_tracks_tab_columns_name_stick(self): name_column = self.is_element_displayed(*self.locator(self.global_search_locators, "tracks_tab_column_name")) artist_column = self.is_element_displayed(*self.locator(self.global_search_locators, "tracks_tab_column_artist")) tracks_list = self.get_elements(locator="//*[@id='global-search-track-container']//a[contains(@id, 'global-search-track')]", locator_type="xpath") ActionChains(self.driver).move_to_element(tracks_list[-1]).perform() assert_that(name_column).is_true() assert_that(artist_column).is_true() @allure.step("Verify Playlists tab elements") def verify_playlists_tab_elements(self, playlist): playlist_art = "//*[contains(@id,'global-search-playlist-{}-') and contains(@id,'-image-cover')]" playlist_icon = "//*[contains(@id, 'global-search-status-bar-tab-playlists-column-{}') and contains(@id, '-{}-icon')]" playlist_title = "//*[contains(@id, 'global-search-status-bar-tab-playlists-column-{}-') and contains(@id, 'playlists-text')]" playlists_list = self.get_elements(locator="//*[@id='global-search-playlist-container-{}']//a[contains(@id, 'global-search-playlist-{}-')]".format(playlist, playlist), locator_type="xpath") playlist_column_icon = self.is_element_displayed(locator=playlist_icon.format(playlist, playlist), locator_type="xpath") playlist_column_title = self.get_text(locator=playlist_title.format(playlist), locator_type="xpath") playlist_art_list = self.get_elements(locator=playlist_art.format(playlist), locator_type="xpath") playlist_art_shape = (playlist_art_list[0]).value_of_css_property("border-radius") self.log.info("CSS property border-radius is: " + str(playlist_art_shape)) assert_that(playlist_column_icon).is_true() if playlist == "spotify": assert_that(playlist_column_title).is_equal_to(self.PLAYLISTS_TAB_SPOTIFY_PLAYLISTS_COLUMN_NAME) elif playlist == "apple": assert_that(playlist_column_title).is_equal_to(self.PLAYLISTS_TAB_APPLE_PLAYLISTS_COLUMN_NAME) assert_that(playlist_art_shape).is_equal_to(self.ART_SQUARE_SHAPE) assert_that(len(playlists_list)).is_greater_than(0) assert_that(len(playlists_list)).is_less_than_or_equal_to(self.MAX_PLAYLISTS_TAB_PLAYLISTS_LIST_LEN) @allure.step("Verify Artists tab elements") def verify_artists_tab_elements(self): artist_column_name = self.get_text(*self.locator(self.global_search_locators, "artists_tab_column_name")) artist_art_list = self.get_elements(*self.locator(self.global_search_locators, "artists_art_list")) artists_list = self.get_elements(locator="//*[@id='global-search-artist-container']//a[contains(@id, 'global-search-artist')]", locator_type="xpath") artist_art_shape = artist_art_list[0].value_of_css_property("border-radius") self.log.info("CSS property border-radius is: " + str(artist_art_shape)) assert_that(artist_art_shape).is_equal_to(self.ART_ROUND_SHAPE) assert_that(artist_column_name).is_equal_to(self.ARTISTS_TAB_NAME_COLUMN) assert_that(len(artists_list)).is_greater_than(0) assert_that(len(artists_list)).is_less_than_or_equal_to(self.MAX_ARTISTS_TAB_ARTISTS_LIST_LEN) @allure.step("Verify Albums tab elements") def verify_albums_tab_elements(self): name_column = self.get_text(*self.locator(self.global_search_locators, "albums_tab_column_name")) artist_column = self.get_text(*self.locator(self.global_search_locators, "albums_tab_column_artist")) self.wait_for_element_visible(*self.locator(self.global_search_locators, "albums_art_list")) albums_art_list = self.get_elements(*self.locator(self.global_search_locators, "albums_art_list")) albums_list = self.get_elements(locator="//*[@id='global-search-album-container']//a[contains(@id, 'global-search-album')]", locator_type="xpath") album_art_shape = albums_art_list[0].value_of_css_property("border-radius") self.log.info("CSS property border-radius is: " + str(album_art_shape)) assert_that(album_art_shape).is_equal_to(self.ART_SQUARE_SHAPE) assert_that(name_column).is_equal_to(self.ALBUMS_TAB_NAME_COLUMN) assert_that(artist_column).is_equal_to(self.ALBUMS_TAB_ARTIST_COLUMN) assert_that(len(albums_list)).is_greater_than(0) assert_that(len(albums_list)).is_less_than_or_equal_to(self.MAX_ALBUMS_TAB_ALBUMS_LIST_LEN) @allure.step("Verify Accounts tab elements") def verify_accounts_tab_elements(self): name_column = self.get_text(*self.locator(self.global_search_locators, "accounts_tab_column_name")) username_column = self.get_text(*self.locator(self.global_search_locators, "accounts_tab_column_username")) accounts_art_list = self.get_elements(*self.locator(self.global_search_locators, "accounts_art_list")) accounts_list = self.get_elements(locator="//a[contains(@id, 'global-search-account')]", locator_type="xpath") accounts_art_shape = accounts_art_list[0].value_of_css_property("border-radius") self.log.info("CSS property border-radius is: " + str(accounts_art_shape)) assert_that(accounts_art_shape).is_equal_to(self.ART_ROUND_SHAPE) assert_that(name_column).is_equal_to(self.ACCOUNTS_TAB_NAME_COLUMN) assert_that(username_column).is_equal_to(self.ACCOUNTS_TAB_USERNAME_COLUMN) assert_that(len(accounts_list)).is_greater_than(0) assert_that(len(accounts_list)).is_less_than_or_equal_to(self.MAX_ACCOUNTS_TAB_ACCOUNTS_LIST_LEN) @allure.step("Verify Resent Searches elements label") def verify_resent_searches_elements_label(self, element): if element == "track": element_label = self.get_elements(locator="//*[contains(@id, 'global-search-recent-spotify-{}-') and contains(@id, '-label')]".format(element), locator_type="xpath") element_label_text = [self.get_text(element=e) for e in element_label] assert_that(element_label_text[0]).is_equal_to("TRACK") elif element == "spotify-playlist": element_label = self.get_elements(locator="//*[contains(@id, 'global-search-recent-{}-') and contains(@id, '-label')]".format(element), locator_type="xpath") element_label_text = [self.get_text(element=e) for e in element_label] element_label_spotify_icon = self.get_elements(locator="//*[contains(@id, 'global-search-recent-{}-') and contains(@id, '-image-cover')]/parent::div//span[contains(@class, 'icon-spotify')]".format(element), locator_type="xpath") is_spotify_icon_displayed = self.is_element_displayed(element=element_label_spotify_icon[0]) assert_that(is_spotify_icon_displayed).is_true() assert_that(element_label_text[0]).is_equal_to("PLAYLIST") elif element == "playlist-apple": element_label = self.get_elements(locator="//*[contains(@id, 'global-search-recent-pl-') and contains(@id, '-label')]", locator_type="xpath") element_label_text = [self.get_text(element=e) for e in element_label] element_label_apple_icon = self.get_elements(locator="//*[contains(@id, 'global-search-recent-pl-') and contains(@id, '-image-cover')]/parent::div//span[contains(@class, 'icon-apple')]", locator_type="xpath") is_apple_icon_displayed = self.is_element_displayed(element=element_label_apple_icon[0]) assert_that(is_apple_icon_displayed).is_true() assert_that(element_label_text[0]).is_equal_to("PLAYLIST") elif element == "artist": element_label = self.get_elements(locator="//*[contains(@id, 'global-search-recent-spotify-{}-') and contains(@id, '-label')]".format(element), locator_type="xpath") element_label_text = [self.get_text(element=e) for e in element_label] assert_that(element_label_text[0]).is_equal_to("ARTIST") elif element == "album": element_label = self.get_elements(locator="//*[contains(@id, 'global-search-recent-spotify-{}-') and contains(@id, '-label')]".format(element), locator_type="xpath") element_label_text = [self.get_text(element=e) for e in element_label] assert_that(element_label_text[0]).is_equal_to("ALBUM") elif element == "account": element_label = self.get_elements(locator="//*[contains(@id, 'global-search-recent-spotify-user-') and contains(@id, '-label')]", locator_type="xpath") element_label_text = [self.get_text(element=e) for e in element_label] assert_that(element_label_text[0]).is_equal_to("ACCOUNT") @allure.step("Get Resent Searches elements list") def verify_resent_searches_elements_list_len(self): elements_list = self.get_elements(locator="//a[contains (@id, 'global-search-recent-')]", locator_type="xpath") assert_that(len(elements_list)).is_greater_than(0) assert_that(len(elements_list)).is_less_than_or_equal_to(self.MAX_RESENT_SEARCHES_LIST_LEN) @allure.step("Navigate to each track form Tracks tab") def navigate_to_each_track_from_tracks_tab(self): tracks_list = self.get_elements(locator="//*[@id='global-search-track-container']//a[contains(@id, 'global-search-track')]", locator_type="xpath") self.log.info("Tracks list: " + str(tracks_list)) for t in range(len(tracks_list)): self.navigate_from_tab_to_element("track", index=t) self.put_focus_to_the_search_field() self.enter_search_value(self.SEARCH_VALUE) time.sleep(5) self.open_tab("Tracks") time.sleep(5) @allure.step("Verify global search tabs") def verify_global_search_tabs(self): dict_all = { "track": {"tab": "Tracks", "element": "track", "element_name": "spotify-track"}, "playlists": { "tab": "Playlists", "spotify": {"element": "spotify", "element_name": "playlist-spotify", "recent_search": "spotify-playlist"}, "apple": {"element": "apple", "element_name": "playlist-apple", "recent_search": "pl"}, "amazon": {"element": "amazon", "element_name": "playlist-amazon"}, }, "artist": {"tab": "Artists", "element": "artist", "element_name": "spotify-artist"}, "album": {"tab": "Albums", "element": "album", "element_name": "spotify-album"}, "account": {"tab": "Accounts", "element": "account", "element_name": "spotify-user"}, } playlists_types = ["spotify", "apple", "amazon"] for item in ["track", "playlists", "artist", "album", "account"]: if item == "playlists": for playlist in playlists_types: self.put_focus_to_the_search_field() self.enter_search_value(self.SEARCH_VALUE) time.sleep(2) self.open_tab(dict_all[item]["tab"]) time.sleep(2) names = self.get_tab_elements_title(dict_all[item][playlist]["element_name"]) self.log.info("{} playlist: ".format(playlist) + str(names)) self.verify_hover_over_element(dict_all[item][playlist]["element_name"]) self.verify_playlists_tab_elements(dict_all[item][playlist]["element"]) self.navigate_from_tab_to_element(dict_all[item][playlist]["element_name"]) title = self.get_page_title(dict_all[item][playlist]["element_name"]) assert_that(names[0]).is_equal_to(title) if playlist != "amazon": self.put_focus_to_the_search_field() self.verify_hover_over_recent_search_element(dict_all[item][playlist]["recent_search"]) resent_searches_elements_title = self.get_elements_title_on_resent_searches() assert_that(title).is_equal_to(resent_searches_elements_title[0]) self.verify_resent_searches_elements_label(dict_all[item][playlist]["element_name"]) self.navigate_from_recent_search_to_element(dict_all[item][playlist]["recent_search"]) title = self.get_page_title(dict_all[item][playlist]["element_name"]) assert_that(names[0]).is_equal_to(title) else: self.put_focus_to_the_search_field() self.enter_search_value(self.SEARCH_VALUE) self.open_tab(dict_all[item]["tab"]) time.sleep(5) names = self.get_tab_elements_title(dict_all[item]["element"]) self.log.info("{} names: ".format(dict_all[item]["tab"]) + str(names)) self.verify_hover_over_element(dict_all[item]["element"]) if item == "track": self.verify_tracks_tab_elements() self.verify_tracks_tab_columns_name_stick() elif item == "artist": self.verify_artists_tab_elements() elif item == "album": self.verify_albums_tab_elements() elif item == "account": self.verify_accounts_tab_elements() self.navigate_from_tab_to_element(dict_all[item]["element"]) title = self.get_page_title(dict_all[item]["element"]) assert_that(names[0]).is_equal_to(title) self.put_focus_to_the_search_field() self.verify_hover_over_recent_search_element(dict_all[item]["element_name"]) resent_searches_elements_title = self.get_elements_title_on_resent_searches() assert_that(title).is_equal_to(resent_searches_elements_title[0]) self.verify_resent_searches_elements_label(dict_all[item]["element"]) self.navigate_from_recent_search_to_element(dict_all[item]["element_name"]) title = self.get_page_title(dict_all[item]["element"]) assert_that(names[0]).is_equal_to(title) @allure.step("Verify single albums are not shown in Search Results") def verify_single_albums(self): api_resp = self.api_client.get_global_search_results_albums_artists_tracks(query=self.EMPTY_ALBUMS_SEARCH_VALUE, market=AppConfig.get("market")["us"]["market"]) album_types = [] for a in range(len(api_resp["albums"]["items"])): album_types.append(api_resp["albums"]["items"][a]["album_type"]) self.log.info("Albums types list: " + str(album_types)) for t in album_types: assert_that(t).is_equal_to(self.ALBUM_TYPE_SINGLE) @allure.step("Top Results - Album section presence") def top_results_album_section_presence(self): album_section = self.is_element_displayed(*self.locator(self.global_search_locators, "top_results_album_section")) return album_section @allure.step("Get page content") def get_page_content(self): page_text = self.get_text(locator='//*[contains(@class, "App-main")]', locator_type="xpath") self.log.info("Page text: " + str(page_text)) return page_text @allure.step("Navigate to Charts Digest page through logo click") def navigate_to_chart_digest_using_logo(self): self.wait_for_element_visible(*self.locator(self.global_search_locators, "logo")) self.wait_for_element_clickable(*self.locator(self.global_search_locators, "logo")) self.click_element(*self.locator(self.global_search_locators, "logo"))