import logging from contextlib import suppress import allure from ui_automation_framework.utils import logger as cl from waiting import TimeoutExpired, ALL from src.helpers.waiting_wrapper import wait from src.locators.video_view_locators import VideoViewLocators from src.ui_elements.button_ui_element import ButtonUIElement from src.ui_elements.input_ui_element import InputUIElement from src.ui_elements.label_ui_element import LabelUIElement from src.ui_elements.list_ui_element import ListUIElement from src.pages.track_view_page import TrackViewPage class VideoViewPage(TrackViewPage): log = cl.Logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver @property def video_charts_list(self): return ListUIElement(self.driver, by_position_locator=VideoViewLocators.VIDEO_CHARTS_BY_POSITION, by_text_locator=VideoViewLocators.VIDEO_CHARTS_DATA_BY_NAME, all_elements_locator=VideoViewLocators.VIDEO_CHARTS_LIST) @property def bn_youtube_link(self): return ButtonUIElement(self.driver, VideoViewLocators.BN_YOUTUBE_LINK, "YouTube link") @property def lb_youtube(self): return LabelUIElement(self.driver, VideoViewLocators.LB_YOUTUBE, "YouTube page") @property def lb_web_safari(self): return LabelUIElement(self.driver, VideoViewLocators.WEB_VIEW_SAFARI, "Safari Web View") # for internal use to see all chart elements on the page def print_all_video_charts_on_page(self): video_charts = self.video_charts_list.elements for el in video_charts: print(el.text) @allure.step("Check Video statistic presence for {chart_name}") def is_video_chart_statistics_present(self, chart_name): with suppress(TimeoutExpired): chart = self.video_charts_list.get_item_by_text(chart_name) print("video has chart: {}".format(chart.text)) return chart.is_visible return False def get_video_chart_text(self, chart_name): with suppress(TimeoutExpired): chart = self.video_charts_list.get_item_by_text(chart_name) print(chart.text) return chart.text @allure.step("Check {source} Demographics all elements presence") def are_demographic_elements_present_for_video(self, source): chart_text = self.get_video_chart_text(source + " Demographics") return self.check_demographic_elements_presence(source, chart_text) def click_youtube_video_link(self): self.bn_youtube_link.click() return self @allure.step("Check YouTube webview is opened") def is_youtube_web_view_opened(self): with suppress(TimeoutExpired): return wait(self.lb_web_safari.is_visible) return False