From 9ffa043dc4c54a24e0c99631cf69112b9c099f22 Mon Sep 17 00:00:00 2001 From: nsubbot Date: Wed, 22 Oct 2025 08:32:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=90=D0=BA=D1=82=D1=83=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B7=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D1=8B=20=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D1=8B=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B8=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D1=81=D1=82=D0=BE=D0=BB=D0=B1=D1=86=D0=B0=20=D1=82?= =?UTF-8?q?=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=D1=8B=20=D0=B8=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=B3=D0=B8=D0=BD=D0=B0=D1=86=D0=B8=D0=B8=20=D1=82=D0=B0=D0=B1?= =?UTF-8?q?=D0=BB=D0=B8=D1=87=D0=BD=D1=8B=D1=85=20=D0=B4=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/events_container_component.py | 16 +++------ components/table_component.py | 33 +++++++++++++++++-- tests/e2e/test_system_log_events_container.py | 20 +++++++---- 3 files changed, 48 insertions(+), 21 deletions(-) diff --git a/components/events_container_component.py b/components/events_container_component.py index 3bf2d4b..9bdf27d 100644 --- a/components/events_container_component.py +++ b/components/events_container_component.py @@ -1,7 +1,6 @@ """Модуль компонента контейнера с перечнем событий. Содержит класс для работы с контейнерами, их элементами и проверками.""" -from datetime import datetime from playwright.sync_api import Page, Locator from tools.logger import get_logger from locators.toolbar_locators import ToolbarLocators @@ -83,15 +82,6 @@ class EventsContainerComponent(BaseComponent): loc = self.container_locator.locator(self.table_locator) self.events_table.click_arrow_button(loc, index) - def datetime2timestamp(self, date_string: str) -> float: - """ Конвертация строкового представления даты и времени в Unix timestamp """ - - # Формат, соответствующий строке с датой и временем - format_string = "%d.%m.%Y %H:%M:%S" - - date_object = datetime.strptime(date_string, format_string) - return date_object.timestamp() - def get_current_data_set_number(self) -> int: """Получение номера текущего набора данных""" @@ -176,18 +166,20 @@ class EventsContainerComponent(BaseComponent): self.events_table.check_table_headers(actual_headers, expected_headers) def check_events_table_column_descending_order(self, - index: int) -> bool: + 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) + return self.events_table.check_column_descending_order(loc, index, convert2timestamp) def check_events_table_row_highlighting(self, row_index: int) -> None: """Проверяет выделение указанной строки таблицы. diff --git a/components/table_component.py b/components/table_component.py index 38f2a72..d099168 100644 --- a/components/table_component.py +++ b/components/table_component.py @@ -1,5 +1,6 @@ """Модуль компонента таблицы. Содержит класс для работы с табличными данными.""" +from datetime import datetime from playwright.sync_api import Page, expect, Locator from tools.logger import get_logger from components.base_component import BaseComponent @@ -33,6 +34,25 @@ class TableComponent(BaseComponent): assert arrow_button.is_enabled(), f"Arrow button is missing in {index} header cell" arrow_button.click() + def datetime2timestamp(self, date_string: str) -> float|None: + """ Конвертация строкового представления даты и времени в Unix timestamp + Args: + date_string: Строка с датой и временем в формате d.m.Y H:M:S. + + Returns: + float: Unix timestamp. + None: конвертация невозможна + """ + + # Формат, соответствующий строке с датой и временем + format_string = "%d.%m.%Y %H:%M:%S" + + try: + date_object = datetime.strptime(date_string, format_string) + return date_object.timestamp() + except ValueError: + return None + def get_arrow_button_state(self, table_locator: str | Locator, index: int) -> str: """ Получение состояния кнопки-стрелочки вверх/вниз в ячейке заголовка таблицы @@ -201,12 +221,14 @@ class TableComponent(BaseComponent): def check_column_descending_order(self, locator: str | Locator, - index: int) -> bool: + index: int, + convert2timestamp=False) -> bool: """Проверка, что заданный столбец таблицы упорядочен по убыванию. Args: locator: Локатор таблицы. index: Индекс столбца. + convert2timestamp: Конвертировать строковое представление даты и времени в Unix timestamp Returns: True, если столбец таблицы упорядочен по убыванию. Иначе: False @@ -223,9 +245,14 @@ class TableComponent(BaseComponent): "Column index is out of range" column = [] for i in range(len(table_content)): - column.append(table_content[i][index]) + if convert2timestamp: + timestamp = self.datetime2timestamp(table_content[i][index]) + assert timestamp, f"Error conversation to timestamp for {table_content[i][index]}" + column.append(timestamp) + else: + column.append(table_content[i][index]) - return all([x > y for x, y in zip(column, column[1:])]) + return all(column[i] >= column[i+1] for i in range(len(column) - 1)) def check_first_row_visibility(self, locator: str | Locator) -> None: """Проверяет видимость первой строки таблицы. diff --git a/tests/e2e/test_system_log_events_container.py b/tests/e2e/test_system_log_events_container.py index f5f5dca..40bd561 100644 --- a/tests/e2e/test_system_log_events_container.py +++ b/tests/e2e/test_system_log_events_container.py @@ -128,6 +128,7 @@ class TestSystemLogEventsContainer: # Проверка видимости первой строки после прокрутки system_log_events_container.check_events_table_first_row_visibility() + # @pytest.mark.develop def test_events_table_column_sorting(self, browser: Page): """Проверяет сортировку колонки 'Время' в таблице событий. @@ -148,21 +149,23 @@ class TestSystemLogEventsContainer: assert state == "down", "Arrow button should be down" system_log_events_container.click_event_table_header_arrow(index) - browser.wait_for_timeout(300) + browser.wait_for_timeout(500) state = system_log_events_container.get_arrow_button_state(index) assert state == "up", "Arrow button should be up" - is_descending_order = system_log_events_container.check_events_table_column_descending_order(index) + is_descending_order = system_log_events_container.check_events_table_column_descending_order(index, + convert2timestamp=True) assert not is_descending_order, "Column data should be in ascending order" system_log_events_container.click_event_table_header_arrow(index) - browser.wait_for_timeout(300) + browser.wait_for_timeout(500) state = system_log_events_container.get_arrow_button_state(index) assert state == "down", "Arrow button should be down" - is_descending_order = system_log_events_container.check_events_table_column_descending_order(index) + is_descending_order = system_log_events_container.check_events_table_column_descending_order(index, + convert2timestamp=True) assert is_descending_order, "Column data should be in descending order" - @pytest.mark.develop + # @pytest.mark.develop def test_events_table_pagination(self, browser: Page): """Проверяет возможность пагинации таблицы событий. @@ -193,8 +196,12 @@ class TestSystemLogEventsContainer: # загрузка страниц от начала и до конца # to_do: проверка, что происходит обновление содержимого таблицы counter = 1 - while not is_chevron_right_disabled: + # temporarily + max_pages = 20 + while not is_chevron_right_disabled and counter <= max_pages: + # while not is_chevron_right_disabled: system_log_events_container.click_chevron_right() + browser.wait_for_timeout(1500) counter += 1 is_chevron_left_disabled = system_log_events_container.is_chevron_left_disabled() @@ -209,6 +216,7 @@ class TestSystemLogEventsContainer: # to_do: проверка, что происходит обновление содержимого таблицы while not is_chevron_left_disabled: system_log_events_container.click_chevron_left() + browser.wait_for_timeout(1500) counter -= 1 is_chevron_left_disabled = system_log_events_container.is_chevron_left_disabled()