import logging from contextlib import suppress import allure from ui_automation_framework.utils import logger as cl from waiting import TimeoutExpired from src.helpers.waiting_wrapper import wait from src.locators.countries_locators import CountriesLocators from src.pages.common_page import CommonPage 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.label_ui_element import LabelUIByText from src.ui_elements.list_ui_element import ListUIElement class CountriesPage(CommonPage): log = cl.Logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver @property def lb_track_row(self): return LabelUIByText(self.driver, CountriesLocators.TOP_TRACK) @property def lb_countries(self): return LabelUIElement(self.driver, CountriesLocators.COUNTRIES_LB, "Countries") @property def in_search_by_market(self): return InputUIElement(self.driver, CountriesLocators.SEARCH_BY_MARKET, "Search Country") @property def list_countries(self): return ListUIElement(self.driver, all_elements_locator=CountriesLocators.SEARCH_LIST, by_position_locator=CountriesLocators.SEARCH_LIST_BY_POSITION, by_text_locator=CountriesLocators.SEARCH_LIST_BY_TEXT) @property def first_element_in_list(self): return LabelUIElement(self.driver, CountriesLocators.FIRST_ELEMENT_IN_SEARCH_LIST, "First country in a list") @allure.step("Check Countries label presence") def is_countries_label_present(self): with suppress(TimeoutExpired): return wait(self.lb_countries.is_visible) return False @allure.step("Selecting country by name") def select_country_by_name(self, name): self.first_element_in_list.wait() self.in_search_by_market.click() self.in_search_by_market.send_text(name) self.press_return_to_hide_keyboard() self.list_countries.select_by_text(name) return self @allure.step("Check {track} presence") def is_track_present(self, track): with suppress(TimeoutExpired): element = self.lb_track_row.get_item_by_text(track.split(' ')[0]) # check only 1 word of the track's name return wait(element.is_visible) return False