361 lines
16 KiB
Python
361 lines
16 KiB
Python
"""Модуль компонента контейнера с перечнем событий. Содержит класс для работы с контейнерами,
|
||
их элементами и проверками."""
|
||
|
||
from playwright.sync_api import Page, Locator
|
||
from tools.logger import get_logger
|
||
from locators.toolbar_locators import ToolbarLocators
|
||
from elements.tooltip_button_element import TooltipButton
|
||
from elements.tab_button_element import TabButton
|
||
from elements.button_element import Button
|
||
from components.toolbar_component import ToolbarComponent
|
||
from components.table_component import TableComponent
|
||
from components.base_component import BaseComponent
|
||
|
||
logger = get_logger("EVENTS_CONTANER")
|
||
|
||
|
||
class EventsContainerComponent(BaseComponent):
|
||
"""Компонент контейнера с перечнем событий. Предоставляет методы для взаимодействия с контейнером,
|
||
его содержимым и проверок."""
|
||
|
||
def __init__(self, page: Page, locator: str | Locator):
|
||
"""Инициализирует базовый контейнер.
|
||
|
||
Args:
|
||
page: Экземпляр страницы Playwright
|
||
locator: Локатор контейнера (строка или объект Locator)
|
||
"""
|
||
super().__init__(page)
|
||
|
||
self.container_locator = self.get_locator(locator)
|
||
|
||
# тулбар
|
||
self.toolbar = ToolbarComponent(page, "")
|
||
filter_button_locator = self.container_locator.locator(ToolbarLocators.TITLE).\
|
||
get_by_role("button")
|
||
self.toolbar.add_button(filter_button_locator, "filter_button")
|
||
|
||
export_buttons = self.container_locator.locator(ToolbarLocators.ITEMS).\
|
||
get_by_role("button").all()
|
||
self.toolbar.add_tooltip_button(export_buttons[1], "export_to_csv_button")
|
||
self.toolbar.add_tooltip_button(export_buttons[0], "export_to_pdf_button")
|
||
|
||
# Таблица событий
|
||
self.events_table = TableComponent(page)
|
||
self.table_locator = "//div[@class='scrolltable']/div/table"
|
||
|
||
# Кнопки пагинации в нижней части контейнера
|
||
self.chevron_left = Button(page,
|
||
self.container_locator.get_by_role("button").filter(has_text='chevron_left'),
|
||
"chevron_left")
|
||
self.chevron_right = Button(page,
|
||
self.container_locator.get_by_role("button").filter(has_text='chevron_right'),
|
||
"chevron_right")
|
||
|
||
self.first_page = Button(page,
|
||
self.container_locator.get_by_role("button").filter(has_text='first_page'),
|
||
"first_page")
|
||
self.last_page = Button(page,
|
||
self.container_locator.get_by_role("button").filter(has_text='last_page'),
|
||
"last_page")
|
||
|
||
loc = self.container_locator.get_by_role("button").filter(has_text='chevron_left').\
|
||
locator("xpath=..").get_by_role("button").nth(2)
|
||
self.data_set_number = Button(page, loc, "data_set_number")
|
||
|
||
# Действия:
|
||
def add_tab_to_toolbar(self, locator: str | Locator, name: str) -> None:
|
||
"""Добавление кнопки типа v-tabs к тулбару"""
|
||
|
||
tabs_locator = self.get_locator(locator)
|
||
self.toolbar.add_tab_button(self.container_locator.locator(tabs_locator), name)
|
||
|
||
def click_chevron_left(self) -> None:
|
||
"""Нажатие кнопки получения предыдущего набора данных"""
|
||
|
||
self.chevron_left.click()
|
||
|
||
def click_chevron_right(self) -> None:
|
||
"""Нажатие кнопки получения следующего набора данных"""
|
||
|
||
self.chevron_right.click()
|
||
|
||
def click_first_page(self) -> None:
|
||
"""Нажатие кнопки перехода на первую сраницу"""
|
||
|
||
self.first_page.click()
|
||
|
||
def click_last_page(self) -> None:
|
||
"""Нажатие кнопки перехода на последнюю страницу"""
|
||
|
||
self.last_page.click()
|
||
|
||
def click_event_table_header_arrow(self, index: int) -> None:
|
||
""" Нажатие кнопки-стрелочки вверх/вниз в ячейке заголовка таблицы
|
||
|
||
Args:
|
||
index: Индекс ячейки в заголовке.
|
||
"""
|
||
loc = self.container_locator.locator(self.table_locator)
|
||
self.events_table.click_arrow_button(loc, index)
|
||
|
||
def get_current_data_set_number(self) -> int:
|
||
"""Получение номера текущего набора данных"""
|
||
|
||
try:
|
||
data_set_number = int(self.data_set_number.get_text(0))
|
||
except ValueError as e:
|
||
assert False, f"Value Error: {e}"
|
||
|
||
return data_set_number
|
||
|
||
def get_arrow_button_state(self, index: int) -> str:
|
||
""" Получение состояния кнопки-стрелочки вверх/вниз в ячейке заголовка таблицы
|
||
|
||
Args:
|
||
index: Индекс ячейки в заголовке.
|
||
|
||
Returns:
|
||
up, если это стрелочка вверх. down, если это стрелочка вниз.
|
||
"""
|
||
loc = self.container_locator.locator(self.table_locator)
|
||
return self.events_table.get_arrow_button_state(loc, index)
|
||
|
||
def get_events_table_content(self) -> list[list[str]]:
|
||
"""Возвращает содержимое таблицы, включая заголовки.
|
||
|
||
Returns:
|
||
Двумерный список с содержимым таблицы.
|
||
"""
|
||
|
||
loc = self.container_locator.locator(self.table_locator)
|
||
return self.events_table.read(loc)
|
||
|
||
def get_events_table_rows_count(self) -> int:
|
||
"""Возвращает количество строк в таблице (без заголовка).
|
||
|
||
Returns:
|
||
int: Количество строк с данными.
|
||
|
||
Raises:
|
||
AssertionError: Если таблица пуста.
|
||
"""
|
||
|
||
loc = self.container_locator.locator(self.table_locator)
|
||
return self.events_table.get_rows_count(loc)
|
||
|
||
def get_toolbar_filter_button(self) -> Button:
|
||
"""Возвращает кнопку фильтрации."""
|
||
|
||
return self.toolbar.get_button_by_name("filter_button")
|
||
|
||
def get_toolbar_export_to_csv_button(self) -> TooltipButton:
|
||
"""Возвращает кнопку экспорта в csv."""
|
||
|
||
return self.toolbar.get_button_by_name("export_to_csv_button")
|
||
|
||
def get_toolbar_export_to_pdf_button(self) -> TooltipButton:
|
||
"""Возвращает кнопку экспорта в pdf."""
|
||
|
||
return self.toolbar.get_button_by_name("export_to_pdf_button")
|
||
|
||
def get_toolbar_tab_button(self, name: str) -> TabButton:
|
||
"""Возвращает кнопку типа v-tabs по имени."""
|
||
|
||
return self.toolbar.get_button_by_name(name)
|
||
|
||
def scroll_events_table_up(self) -> None:
|
||
"""Прокручивает таблицу событий вверх."""
|
||
|
||
loc = self.container_locator.locator("//div[@class='scrolltable']//table/tbody")
|
||
self.events_table.scroll_up(loc)
|
||
|
||
def scroll_events_table_down(self) -> None:
|
||
"""Прокручивает таблицу событий вниз."""
|
||
|
||
loc = self.container_locator.locator("//div[@class='scrolltable']//table/tbody")
|
||
self.events_table.scroll_down(loc)
|
||
|
||
# Проверки:
|
||
def check_events_table_headers(self, actual_headers, expected_headers) -> None:
|
||
""" Проверка соответствия заголовка таблицы ожидаемому"""
|
||
|
||
self.events_table.check_table_headers(actual_headers, expected_headers)
|
||
|
||
def check_events_table_column_descending_order(self,
|
||
index: int,
|
||
convert2timestamp=False) -> bool:
|
||
"""Проверка, что заданный столбец таблицы упорядочен по убыванию.
|
||
|
||
Args:
|
||
index: Индекс столбца.
|
||
convert2timestamp: Конвертировать строковое представление даты и времени в Unix timestamp.
|
||
|
||
Returns:
|
||
True, если столбец таблицы упорядочен по убыванию. Иначе: False
|
||
"""
|
||
|
||
loc = self.container_locator.locator(self.table_locator)
|
||
return self.events_table.check_column_descending_order(loc, index, convert2timestamp)
|
||
|
||
def check_events_table_row_highlighting(self, row_index: int) -> None:
|
||
"""Проверяет выделение указанной строки таблицы.
|
||
|
||
Args:
|
||
row_index: Индекс проверяемой строки.
|
||
|
||
Raises:
|
||
AssertionError: Если строка не выделена.
|
||
"""
|
||
|
||
loc = self.container_locator.locator(self.table_locator)
|
||
self.events_table.check_row_highlighting(loc, row_index)
|
||
|
||
def check_events_table_first_row_visibility(self) -> None:
|
||
"""Проверяет видимость первой строки таблицы.
|
||
|
||
Raises:
|
||
AssertionError: Если строка не видна.
|
||
"""
|
||
|
||
loc = self.container_locator.locator(self.table_locator)
|
||
self.events_table.check_first_row_visibility(loc)
|
||
|
||
def check_events_table_last_row_visibility(self) -> None:
|
||
"""Проверяет видимость последней строки таблицы.
|
||
|
||
Raises:
|
||
AssertionError: Если строка не видна.
|
||
"""
|
||
|
||
loc = self.container_locator.locator(self.table_locator)
|
||
self.events_table.check_last_row_visibility(loc)
|
||
|
||
def check_events_table_verticall_scrolling(self) -> bool:
|
||
"""Проверяет возможность вертикальной прокрутки таблицы.
|
||
|
||
Returns:
|
||
bool: True если прокрутка возможна, иначе False.
|
||
"""
|
||
|
||
loc = self.container_locator.locator("//div[@class='scrolltable']//table/tbody")
|
||
return self.events_table.is_scrollable_vertically(loc)
|
||
|
||
def is_chevron_left_disabled(self) -> bool:
|
||
"""Проверка видимости кнопки получения предыдущего набора данных"""
|
||
|
||
return self.chevron_left.is_disabled()
|
||
|
||
def is_chevron_right_disabled(self) -> bool:
|
||
"""Проверка видимости кнопки получения следующего набора данных"""
|
||
|
||
return self.chevron_right.is_disabled()
|
||
|
||
def is_first_page_disabled(self) -> bool:
|
||
"""Проверка видимости кнопки получения первой страницы с набором данных"""
|
||
|
||
return self.first_page.is_disabled()
|
||
|
||
def is_last_page_disabled(self) -> bool:
|
||
"""Проверка видимости кнопки получения последней страницы с набором данных"""
|
||
|
||
return self.last_page.is_disabled()
|
||
|
||
def should_be_all_disabled(self) -> None:
|
||
"""Проверка видимости кнопок пагинации: все кнопки disabled"""
|
||
|
||
is_first_page_disabled = self.is_first_page_disabled()
|
||
assert is_first_page_disabled, "First Page button should be disabled"
|
||
|
||
is_chevron_left_disabled = self.is_chevron_left_disabled()
|
||
assert is_chevron_left_disabled, "Arrow Left button should be disabled"
|
||
|
||
is_chevron_right_disabled = self.is_chevron_right_disabled()
|
||
assert is_chevron_right_disabled, "Arrow Right button should be disabled"
|
||
|
||
is_last_page_disabled = self.is_last_page_disabled()
|
||
assert is_last_page_disabled, "Last Page button should be disabled"
|
||
|
||
def should_be_all_enabled(self) -> None:
|
||
"""Проверка видимости кнопок пагинации: все кнопки enabled"""
|
||
|
||
is_first_page_disabled = self.is_first_page_disabled()
|
||
assert not is_first_page_disabled, "First Page button should be enabled"
|
||
|
||
is_chevron_left_disabled = self.is_chevron_left_disabled()
|
||
assert not is_chevron_left_disabled, "Arrow Left button should be enabled"
|
||
|
||
is_chevron_right_disabled = self.is_chevron_right_disabled()
|
||
assert not is_chevron_right_disabled, "Arrow Right button should be enabled"
|
||
|
||
is_last_page_disabled = self.is_last_page_disabled()
|
||
assert not is_last_page_disabled, "Last Page button should be enabled"
|
||
|
||
|
||
def should_be_initial_state(self) -> None:
|
||
"""Проверка видимости кнопок для первой страницы"""
|
||
|
||
is_first_page_disabled = self.is_first_page_disabled()
|
||
assert is_first_page_disabled, "First Page button should be disabled"
|
||
|
||
is_chevron_left_disabled = self.is_chevron_left_disabled()
|
||
assert is_chevron_left_disabled, "Arrow Left button should be disabled"
|
||
|
||
is_chevron_right_disabled = self.is_chevron_right_disabled()
|
||
assert not is_chevron_right_disabled, "Arrow Right button should be enabled"
|
||
|
||
is_last_page_disabled = self.is_last_page_disabled()
|
||
assert not is_last_page_disabled, "Last Page button should be enabled"
|
||
|
||
def should_be_final_state(self) -> None:
|
||
"""Проверка видимости кнопок для последней страницы"""
|
||
|
||
is_first_page_disabled = self.is_first_page_disabled()
|
||
assert not is_first_page_disabled, "First Page button should be enabled"
|
||
|
||
is_chevron_left_disabled = self.is_chevron_left_disabled()
|
||
assert not is_chevron_left_disabled, "Arrow Left button should be enabled"
|
||
|
||
is_chevron_right_disabled = self.is_chevron_right_disabled()
|
||
assert is_chevron_right_disabled, "Arrow Right button should be disabled"
|
||
|
||
is_last_page_disabled = self.is_last_page_disabled()
|
||
assert is_last_page_disabled, "Last Page button should be disabled"
|
||
|
||
def should_be_events_table(self) -> None:
|
||
"""Проверяет наличие таблицы событий.
|
||
|
||
Raises:
|
||
AssertionError: Если таблица отсутствует.
|
||
"""
|
||
|
||
loc = self.container_locator.locator(self.table_locator)
|
||
self.events_table.check_visibility(loc,
|
||
"Events table is missing"
|
||
)
|
||
|
||
def should_be_toolbar(self) -> None:
|
||
"""Проверка наличия тулбара"""
|
||
|
||
loc = self.container_locator.locator("//nav[contains(@class, 'v-toolbar')]").nth(0)
|
||
self.toolbar.check_toolbar_presence_by_locator(loc, "Toolbar is missing")
|
||
|
||
def should_be_base_toolbar_buttons(self) -> None:
|
||
"""Проверяет наличие и видимость базовых кнопок тулбара."""
|
||
|
||
self.toolbar.check_button_visibility("filter_button")
|
||
self.toolbar.check_button_visibility("export_to_pdf_button")
|
||
self.toolbar.check_button_tooltip("export_to_pdf_button", "Скачать в формате PDF")
|
||
self.toolbar.check_button_visibility("export_to_csv_button")
|
||
self.toolbar.check_button_tooltip("export_to_csv_button", "Скачать в формате CSV")
|
||
|
||
|
||
def should_be_pagination_buttons(self) -> None:
|
||
"""Проверяет наличие и видимость кнопок пагинации."""
|
||
|
||
self.first_page.check_visibility("Pagination button 'first page' is missing")
|
||
self.chevron_left.check_visibility("Pagination button 'chevron left' is missing")
|
||
self.data_set_number.check_visibility("Pagination button 'data set number' is missing")
|
||
self.chevron_right.check_visibility("Pagination button 'chevron right' is missing")
|
||
self.last_page.check_visibility("Pagination button 'last page' is missing")
|