feat(table_component): добавлены аннотации типов для компонента таблицы
- Добавлены аннотации параметров: * locator: str | Locator во всех методах * row_index: int в check_row_highlighting() - Добавлены возвращаемые типы: * -> list[list[str]] для read() * -> None для методов проверок Изменения улучшают документирование API и помогают в статическом анализе кода.pull/1/head
parent
025b171724
commit
e28d9ef339
|
|
@ -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"
|
||||
Loading…
Reference in New Issue