import logging import time import allure from appium.webdriver.common.mobileby import MobileBy from dateutil.parser import parse from dateutil.relativedelta import relativedelta from ui_automation_framework.utils import AppConfig from ui_automation_framework.utils import logger as cl from app.mysql_db_client_custom import MySqlClient from app.src.pages.track_page import TrackPage 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 HotHitsPlacementsPage(TrackPage): log = cl.Logger(logging.DEBUG) REGION_BUTTON_LOCATOR = '**/XCUIElementTypeOther[`label == "{region}"`][2]' def __init__(self, driver, api_client): super().__init__(driver, api_client) self.driver = driver self.sql_client = MySqlClient() self.hot_hits_placements_locators = self.get_page_locators("HotHitsPlacements", "hot_hits_placements_elements.json") def lb_track_name(self, track_name): locator = f'**/XCUIElementTypeOther[`label == "{track_name}"`][2]' return LabelUIElement(self.driver, (locator, "class-chain")) @property def bn_hot_hits_i_icon(self): return ButtonUIElement(self.driver, self.locator(self.hot_hits_placements_locators, "i_icon")) @property def lb_hot_hits_popup_title(self): return LabelUIElement(self.driver, self.locator(self.hot_hits_placements_locators, "hot_hits_popup_title")) # @property # def lb_hot_hits_popup_date(self): # return LabelUIElement(self.driver, self.locator(self.hot_hits_placements_locators, "hot_hits_popup_date")) def lb_hot_hits_popup_date(self, locator, using): return LabelUIElement(self.driver, (locator, using)) @property def lb_hot_hits_popup_content(self): return LabelUIElement(self.driver, self.locator(self.hot_hits_placements_locators, "hot_hits_popup_content")) @allure.step("Clicking i-icon for Hot Hits") def open_hot_hits_i_popup(self): self.bn_hot_hits_i_icon.click() return self @allure.step("Verifying Hot Hits info popup presence") def is_hot_hits_popup_opened(self): hothits_datetime_sql_result = self.sql_client.get_hothits_datetime() hothits_job_latest_run_datetime = hothits_datetime_sql_result[0] hothits_latest_data_datetime = hothits_datetime_sql_result[1] hothits_job_latest_run_datetime_formatted = parse(hothits_job_latest_run_datetime[2]) + relativedelta(hours=3) hothits_latest_data_datetime_formatted = parse(hothits_latest_data_datetime[2]) + relativedelta(hours=3) if hothits_latest_data_datetime_formatted > hothits_job_latest_run_datetime_formatted: hothits_datetime = hothits_latest_data_datetime_formatted else: hothits_datetime = hothits_job_latest_run_datetime_formatted # _hothits_datetime = hothits_datetime.strftime("%m/%d/%y, %I:%M %p") hh_date = hothits_datetime.strftime("%m/%d/%y") hh_time = hothits_datetime.strftime(":%M %p") # locator = f"**/XCUIElementTypeStaticText[`label == \"Data last received: {hothits_datetime}.\"`]" locator = f"**/XCUIElementTypeStaticText[`label contains " f'"Data last received: {hh_date}, " and label contains "{hh_time}."`]' self.lb_hot_hits_popup_title.wait(to_assert=False) self.lb_hot_hits_popup_date(locator, "class-chain").wait(to_assert=False) self.lb_hot_hits_popup_content.wait(to_assert=False) self.log.debug( { "HH Title": self.lb_hot_hits_popup_title.is_visible(), "HH Date": self.lb_hot_hits_popup_date(locator, "class-chain").is_visible(), "HH Content": self.lb_hot_hits_popup_content.is_visible(), } ) return self.lb_hot_hits_popup_title.is_visible() and self.lb_hot_hits_popup_date(locator, "class-chain").is_visible() and self.lb_hot_hits_popup_content.is_visible() def lb_avg_position(self, position): locator = f'**/XCUIElementTypeOther[`label == "#{position} AVG. POSITION"`]' return LabelUIElement(self.driver, (locator, "class-chain")) def lb_top_position(self, position): locator = f'**/XCUIElementTypeOther[`label == "{position} TOP 10 RANKS"`]' return LabelUIElement(self.driver, (locator, "class-chain")) def bn_region(self, region): locator = f'**/XCUIElementTypeOther[`label == "{region}"`][2]' return ButtonUIElement(self.driver, (locator, "class-chain")) @allure.step("Checking all region buttons presence") def check_all_regions_are_present(self): regions = AppConfig.get("regions") return all([ButtonUIElement(self.driver, (self.REGION_BUTTON_LOCATOR.format(region=r), "class-chain")).is_present() for r in regions]) @allure.step('Click on "{region}" region button') def click_region_button(self, region): ButtonUIElement(self.driver, (self.REGION_BUTTON_LOCATOR.format(region=region), "class-chain")).click() return self @property def lt_market_cards(self): return ListUIElement( self.driver, all_elements_locator=( MobileBy.IOS_CLASS_CHAIN, self.locator(self.hot_hits_placements_locators, "market_card")[0], ), ) @property def lt_active_market_cards(self): return ListUIElement( self.driver, all_elements_locator=( MobileBy.ID, self.locator(self.hot_hits_placements_locators, "active_market_card")[0], ), ) @property def lt_inactive_market_cards(self): return ListUIElement( self.driver, all_elements_locator=( MobileBy.ID, self.locator(self.hot_hits_placements_locators, "inactive_market_card")[0], ), ) @property def bn_sorting(self): return ButtonUIElement(self.driver, self.locator(self.hot_hits_placements_locators, "sorting_button")) def sort_markets(self, sort_by): option_locator = { "Top Markets": self.locator(self.hot_hits_placements_locators, "sorting_popup_top_markets_option"), "Track Position": self.locator(self.hot_hits_placements_locators, "sorting_popup_track_position_option"), } self.bn_sorting.click() LabelUIElement(self.driver, self.locator(self.hot_hits_placements_locators, "sorting_popup_title")).is_visible() ButtonUIElement(self.driver, option_locator[sort_by]).click() ButtonUIElement(self.driver, self.locator(self.hot_hits_placements_locators, "sorting_popup_done_button")).click() time.sleep(1)