from pages.base_page import BasePage from components.toolbar_component import ToolbarComponent from components.table_component import TableComponent from locators.table_locators import TableLocators from playwright.sync_api import Page class ServiceStatusTab(BasePage): """Класс для работы с вкладкой 'Статус обслуживания'. Предоставляет методы для взаимодействия с таблицей сервисов и проверки её состояния. Args: page (Page): Экземпляр страницы Playwright. """ def __init__(self, page: Page) -> None: """Инициализация компонентов вкладки 'Статус обслуживания'.""" super().__init__(page) self.toolbar = ToolbarComponent(page, "Статус обслуживания") self.services_table = TableComponent(page) def get_rows_count(self) -> int: """Возвращает количество строк в таблице сервисов (без учёта заголовка). Returns: int: Количество строк с данными. Raises: AssertionError: Если таблица пуста. """ table_content = self.services_table.read(TableLocators.TABLE_WORK_AREA) rows_count = len(table_content) if rows_count == 0: assert False, "The contents of the table are missing" return rows_count - 1 def scroll_services_table_up(self) -> None: """Прокручивает таблицу сервисов вверх.""" self.services_table.scroll_up(TableLocators.TABLE_SCROLL_CONTAINER) def scroll_services_table_down(self) -> None: """Прокручивает таблицу сервисов вниз.""" self.services_table.scroll_down(TableLocators.TABLE_SCROLL_CONTAINER) def check_services_table_content(self) -> None: """Проверяет содержимое таблицы сервисов. Проверяет: - Наличие заголовков таблицы - Соответствие заголовков ожидаемым значениям - Наличие хотя бы одной строки с данными Raises: AssertionError: Если таблица пуста или заголовки не соответствуют ожидаемым. """ expected_headers = [ 'Контейнер', 'Время создания', 'Статус', 'Время работы', 'Image ID', 'Image ТЭГ' ] table_content = self.services_table.read(TableLocators.TABLE_WORK_AREA) if len(table_content) == 0: assert False, "The contents of the table are missing" actual_headers = table_content[0] self.check_equals( actual_headers, expected_headers, f"Expected table headers {expected_headers} are not equal {actual_headers}" ) if len(table_content) == 1: assert False, "Table body is missing" def check_services_table_verticall_scrolling(self) -> bool: """Проверяет возможность вертикальной прокрутки таблицы. Returns: bool: True если прокрутка возможна, иначе False. """ return self.services_table.is_scrollable_vertically( TableLocators.TABLE_SCROLL_CONTAINER ) def check_services_table_first_row_visibility(self) -> None: """Проверяет видимость первой строки таблицы. Raises: AssertionError: Если первая строка не видна. """ self.services_table.check_first_row_visibility(TableLocators.TABLE_WORK_AREA) def check_services_table_last_row_visibility(self) -> None: """Проверяет видимость последней строки таблицы. Raises: AssertionError: Если последняя строка не видна. """ self.services_table.check_last_row_visibility(TableLocators.TABLE_WORK_AREA) def check_services_table_row_highlighting(self, row_index: int) -> None: """Проверяет выделение указанной строки таблицы. Args: row_index (int): Индекс проверяемой строки. Raises: AssertionError: Если строка не выделена. """ self.services_table.check_row_highlighting( TableLocators.TABLE_WORK_AREA, row_index ) def should_be_toolbar(self) -> None: """Проверяет наличие тулбара на вкладке. Raises: AssertionError: Если тулбар отсутствует. """ self.toolbar.check_presence("Toolbar is missing") def should_be_services_table(self) -> None: """Проверяет наличие таблицы сервисов. Raises: AssertionError: Если таблица отсутствует. """ self.services_table.check_presence( TableLocators.TABLE_WORK_AREA, "Service statuses table is missing" )