From e28d9ef339d78ec96a7b3942a233d3317c967c78 Mon Sep 17 00:00:00 2001 From: Radislav Date: Mon, 21 Jul 2025 15:33:17 +0300 Subject: [PATCH] =?UTF-8?q?feat(table=5Fcomponent):=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=B0=D0=BD=D0=BD=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=D1=86=D0=B8=D0=B8=20=D1=82=D0=B8=D0=BF=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=D0=B0=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Добавлены аннотации параметров: * locator: str | Locator во всех методах * row_index: int в check_row_highlighting() - Добавлены возвращаемые типы: * -> list[list[str]] для read() * -> None для методов проверок Изменения улучшают документирование API и помогают в статическом анализе кода. --- components/table_component.py | 70 ++++++----------------------------- 1 file changed, 12 insertions(+), 58 deletions(-) diff --git a/components/table_component.py b/components/table_component.py index fe05787..422b531 100644 --- a/components/table_component.py +++ b/components/table_component.py @@ -1,4 +1,4 @@ -from playwright.sync_api import Page, expect +from playwright.sync_api import Page, expect, Locator from components.base_component import BaseComponent @@ -8,33 +8,14 @@ logger = get_logger("TABLE") class TableComponent(BaseComponent): - """Компонент таблицы. - - Предоставляет методы для взаимодействия с таблицами и проверки их состояния. - Наследуется от BaseComponent. - - Атрибуты: - page: Page - экземпляр страницы Playwright - """ + """Компонент таблицы.""" def __init__(self, page: Page): - """Инициализация компонента таблицы. - - Args: - page: Page - экземпляр страницы Playwright - """ super().__init__(page) # Действия: - def read(self, locator) -> []: - """Читает данные из таблицы, включая заголовки и содержимое ячеек. - - Args: - locator: Локатор таблицы - - Returns: - list: Двумерный список с данными таблицы (первый элемент - заголовки) - """ + def read(self, locator: str | Locator) -> list[list[str]]: + """Читает данные из таблицы.""" table_data = [] table = self.get_locator(locator) @@ -45,7 +26,7 @@ class TableComponent(BaseComponent): header_data = header_cell_text.split('\n') table_data.append(header_data) - # Чтение ячеек таблицы по строкам + # Чтение ячеек таблицы rows = table.locator("//tbody/tr") for i in range(rows.count()): row = rows.nth(i) @@ -59,56 +40,29 @@ class TableComponent(BaseComponent): return table_data # Проверки: - def check_first_row_visibility(self, locator): - """Проверяет видимость первой строки таблицы. - - Args: - locator: Локатор таблицы - - Raises: - AssertionError: Если первая строка не видима - """ + def check_first_row_visibility(self, locator: str | Locator) -> None: + """Проверяет видимость первой строки таблицы.""" table = self.get_locator(locator) first_row = table.locator("//tbody/tr").first expect(first_row).to_be_visible(), "The first table row is not visible" - def check_last_row_visibility(self, locator): - """Проверяет видимость последней строки таблицы. - - Args: - locator: Локатор таблицы - - Raises: - AssertionError: Если последняя строка не видима - """ + def check_last_row_visibility(self, locator: str | Locator) -> None: + """Проверяет видимость последней строки таблицы.""" table = self.get_locator(locator) last_row = table.locator("//tbody/tr").last expect(last_row).to_be_visible(), "The last table row is not visible" - def check_row_highlighting(self, locator, row_index): - """Проверяет изменение цвета строки при наведении курсора. - - Args: - locator: Локатор таблицы - row_index: Индекс проверяемой строки - - Raises: - AssertionError: Если цвет строки не изменился при наведении - """ + def check_row_highlighting(self, locator: str | Locator, row_index: int) -> None: + """Проверяет подсветку строки при наведении.""" table = self.get_locator(locator) row = table.locator("//tbody/tr").nth(row_index) row.scroll_into_view_if_needed() - - # Получение элемента с подсветкой и его цвета hover_element = row.locator(".body-row-hover") initial_color = hover_element.evaluate("el => window.getComputedStyle(el).backgroundColor") - # Наведение на строку row.hover() - self.page.wait_for_timeout(300) # 0.3 секунды + self.page.wait_for_timeout(300) - # Получение нового цвета new_color = hover_element.evaluate("el => window.getComputedStyle(el).backgroundColor") - assert initial_color == new_color, "Color of row did not change when hovering the cursor" \ No newline at end of file