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
|
from components.base_component import BaseComponent
|
||||||
|
|
||||||
|
|
@ -8,33 +8,14 @@ logger = get_logger("TABLE")
|
||||||
|
|
||||||
|
|
||||||
class TableComponent(BaseComponent):
|
class TableComponent(BaseComponent):
|
||||||
"""Компонент таблицы.
|
"""Компонент таблицы."""
|
||||||
|
|
||||||
Предоставляет методы для взаимодействия с таблицами и проверки их состояния.
|
|
||||||
Наследуется от BaseComponent.
|
|
||||||
|
|
||||||
Атрибуты:
|
|
||||||
page: Page - экземпляр страницы Playwright
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, page: Page):
|
def __init__(self, page: Page):
|
||||||
"""Инициализация компонента таблицы.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
page: Page - экземпляр страницы Playwright
|
|
||||||
"""
|
|
||||||
super().__init__(page)
|
super().__init__(page)
|
||||||
|
|
||||||
# Действия:
|
# Действия:
|
||||||
def read(self, locator) -> []:
|
def read(self, locator: str | Locator) -> list[list[str]]:
|
||||||
"""Читает данные из таблицы, включая заголовки и содержимое ячеек.
|
"""Читает данные из таблицы."""
|
||||||
|
|
||||||
Args:
|
|
||||||
locator: Локатор таблицы
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
list: Двумерный список с данными таблицы (первый элемент - заголовки)
|
|
||||||
"""
|
|
||||||
table_data = []
|
table_data = []
|
||||||
|
|
||||||
table = self.get_locator(locator)
|
table = self.get_locator(locator)
|
||||||
|
|
@ -45,7 +26,7 @@ class TableComponent(BaseComponent):
|
||||||
header_data = header_cell_text.split('\n')
|
header_data = header_cell_text.split('\n')
|
||||||
table_data.append(header_data)
|
table_data.append(header_data)
|
||||||
|
|
||||||
# Чтение ячеек таблицы по строкам
|
# Чтение ячеек таблицы
|
||||||
rows = table.locator("//tbody/tr")
|
rows = table.locator("//tbody/tr")
|
||||||
for i in range(rows.count()):
|
for i in range(rows.count()):
|
||||||
row = rows.nth(i)
|
row = rows.nth(i)
|
||||||
|
|
@ -59,56 +40,29 @@ class TableComponent(BaseComponent):
|
||||||
return table_data
|
return table_data
|
||||||
|
|
||||||
# Проверки:
|
# Проверки:
|
||||||
def check_first_row_visibility(self, locator):
|
def check_first_row_visibility(self, locator: str | Locator) -> None:
|
||||||
"""Проверяет видимость первой строки таблицы.
|
"""Проверяет видимость первой строки таблицы."""
|
||||||
|
|
||||||
Args:
|
|
||||||
locator: Локатор таблицы
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
AssertionError: Если первая строка не видима
|
|
||||||
"""
|
|
||||||
table = self.get_locator(locator)
|
table = self.get_locator(locator)
|
||||||
first_row = table.locator("//tbody/tr").first
|
first_row = table.locator("//tbody/tr").first
|
||||||
expect(first_row).to_be_visible(), "The first table row is not visible"
|
expect(first_row).to_be_visible(), "The first table row is not visible"
|
||||||
|
|
||||||
def check_last_row_visibility(self, locator):
|
def check_last_row_visibility(self, locator: str | Locator) -> None:
|
||||||
"""Проверяет видимость последней строки таблицы.
|
"""Проверяет видимость последней строки таблицы."""
|
||||||
|
|
||||||
Args:
|
|
||||||
locator: Локатор таблицы
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
AssertionError: Если последняя строка не видима
|
|
||||||
"""
|
|
||||||
table = self.get_locator(locator)
|
table = self.get_locator(locator)
|
||||||
last_row = table.locator("//tbody/tr").last
|
last_row = table.locator("//tbody/tr").last
|
||||||
expect(last_row).to_be_visible(), "The last table row is not visible"
|
expect(last_row).to_be_visible(), "The last table row is not visible"
|
||||||
|
|
||||||
def check_row_highlighting(self, locator, row_index):
|
def check_row_highlighting(self, locator: str | Locator, row_index: int) -> None:
|
||||||
"""Проверяет изменение цвета строки при наведении курсора.
|
"""Проверяет подсветку строки при наведении."""
|
||||||
|
|
||||||
Args:
|
|
||||||
locator: Локатор таблицы
|
|
||||||
row_index: Индекс проверяемой строки
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
AssertionError: Если цвет строки не изменился при наведении
|
|
||||||
"""
|
|
||||||
table = self.get_locator(locator)
|
table = self.get_locator(locator)
|
||||||
row = table.locator("//tbody/tr").nth(row_index)
|
row = table.locator("//tbody/tr").nth(row_index)
|
||||||
|
|
||||||
row.scroll_into_view_if_needed()
|
row.scroll_into_view_if_needed()
|
||||||
|
|
||||||
# Получение элемента с подсветкой и его цвета
|
|
||||||
hover_element = row.locator(".body-row-hover")
|
hover_element = row.locator(".body-row-hover")
|
||||||
initial_color = hover_element.evaluate("el => window.getComputedStyle(el).backgroundColor")
|
initial_color = hover_element.evaluate("el => window.getComputedStyle(el).backgroundColor")
|
||||||
|
|
||||||
# Наведение на строку
|
|
||||||
row.hover()
|
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")
|
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"
|
assert initial_color == new_color, "Color of row did not change when hovering the cursor"
|
||||||
Loading…
Reference in New Issue