import logging import time import allure from appium.webdriver.common.mobileby import MobileBy from ui_automation_framework.utils import logger as cl from app.src.pages.navigation_page import Navigation from app.src.ui_elements.button_ui_element import ButtonUIElement from app.src.ui_elements.label_ui_element import LabelUIElement from app.src.ui_elements.list_ui_element import ListUIElement class NotificationsPage(Navigation): log = cl.Logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver self.notifications_locators = self.get_page_locators("NotificationsPage", "notification_elements.json") @property def lb_title(self): return LabelUIElement(self.driver, self.locator(self.notifications_locators, "title"), "Title") @property def lb_disabled_notifications(self): return LabelUIElement( self.driver, self.locator(self.notifications_locators, "disabled_notifications_msg"), "Disabled notifications message", ) @property def bn_search_for_tracks(self): return ButtonUIElement( self.driver, self.locator(self.notifications_locators, "search_for_tracks_button"), "Search for tracks button", ) @property def lt_notifications(self): return ListUIElement( self.driver, (MobileBy.IOS_CLASS_CHAIN, '**/XCUIElementTypeOther[`name == "notification-card"`][{}]'), all_elements_locator=(MobileBy.IOS_CLASS_CHAIN, '**/XCUIElementTypeOther[`name == "notification-card"`]'), name="Notifications", ) @allure.step("Clicking on notifications") def click_on_notification(self, position): self.lt_notifications.select_by_position(position) return self @allure.step("Scrolling notifications screen") def scroll_notifications(self): self.driver.execute_script("mobile: scroll", {"direction": "down"}) self.driver.execute_script("mobile: scroll", {"direction": "down"}) # need a small hack to let notifications load time.sleep(1) self.driver.execute_script("mobile: scroll", {"direction": "down"}) self.driver.execute_script("mobile: scroll", {"direction": "down"}) time.sleep(1) self.driver.execute_script("mobile: scroll", {"direction": "down"}) self.driver.execute_script("mobile: scroll", {"direction": "down"}) @allure.step("Getting notification title") def get_notification_text(self, **kwargs): pos_type = list(kwargs.items())[0][0] pos = list(kwargs.items())[0][1] notification_label = self.lt_notifications.get_item_by_position(pos).label if not notification_label.startswith("THIS MONTH"): notification_label_without_date = notification_label.split("AGO")[1] else: notification_label_without_date = notification_label.split("THIS MONTH")[1] if pos_type == "position": return notification_label_without_date.strip() elif pos_type == "track_position": for i in ["moved", "entered", "exited"]: if i in notification_label_without_date: notification_title = notification_label_without_date.split(i)[0] return notification_title.strip() elif pos_type == "playlist_position": if "tracklist" in notification_label_without_date: notification_title = notification_label_without_date.split("tracklist")[0] if notification_title.startswith("  "): notification_title = notification_title[3:] else: notification_title = notification_label_without_date.split("added to")[1].split("at position")[0] return notification_title.strip() @allure.step("Verifying star your first track placeholder is displayed") def is_star_track_placeholder_displayed(self): return self.is_element_displayed(*self.locator(self.notifications_locators, "star_track_placeholder")) and self.is_element_displayed(*self.locator(self.notifications_locators, "search_for_tracks_button")) @property def bn_settings_widget(self): # bn_go_to_settings in case if you don't have any notifications return ButtonUIElement( self.driver, ('**/XCUIElementTypeOther[`name == "notification-settings-touchable-card"`]', "class-chain"), "Notification settings widget", ) @property def bn_go_to_settings(self): return ButtonUIElement( self.driver, ('**/XCUIElementTypeOther[`name == "go-to-settings-button"`]', "class-chain"), name="Go to settings", )