From 3cb8eabfd00ce56719d6cec5c6c265f2d7b891c8 Mon Sep 17 00:00:00 2001 From: Radislav Date: Sun, 12 Oct 2025 12:56:32 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=87=D0=B5=D0=BA=D0=B1=D0=BE=D0=BA=D1=81=20'=D0=91?= =?UTF-8?q?=D0=BB=D0=BE=D0=BA=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components_derived/modal_add_AD_user.py | 95 +++++++++++++++++----- components_derived/modal_add_local_user.py | 67 +++++++-------- components_derived/modal_edit_user.py | 69 +++++++--------- tests/e2e/test_users_tab.py | 21 ++--- 4 files changed, 138 insertions(+), 114 deletions(-) diff --git a/components_derived/modal_add_AD_user.py b/components_derived/modal_add_AD_user.py index b614a3b..804ed1e 100644 --- a/components_derived/modal_add_AD_user.py +++ b/components_derived/modal_add_AD_user.py @@ -25,7 +25,7 @@ class AddADUserModalWindow(ModalWindowComponent): Наследует ModalWindowComponent и добавляет элементы формы: - Поля ввода (имя, пароль, email и др.) - - Чекбоксы (Active Directory, Push-уведомления) + - Чекбоксы (Active Directory, Блокировка, Push-уведомления) - Выпадающие списки групп, пользователей AD, ролей - Кнопки действий """ @@ -36,7 +36,7 @@ class AddADUserModalWindow(ModalWindowComponent): super().__init__(page) # Локаторы элементов формы - input_form_locator = page.locator(ModalWindowLocators.INPUT_FORM_USER_DATA) + input_form_locator = ModalWindowLocators.INPUT_FORM_USER_DATA text_field_locator = ModalWindowLocators.TEXT_FIELD_INPUT_FORM_USER_DATA label_locator = ModalWindowLocators.LABEL_INPUT_FORM_USER_DATA @@ -52,7 +52,7 @@ class AddADUserModalWindow(ModalWindowComponent): # Добавление элементов формы checkbox_1 = Checkbox( page, - self.page.get_by_role("checkbox").nth(0), + self.page.locator(input_form_locator).get_by_role("checkbox").nth(0), "active_directory" ) self.add_content_item("active_directory_checkbox", checkbox_1) @@ -65,7 +65,7 @@ class AddADUserModalWindow(ModalWindowComponent): self.add_content_item("active_directory_checkbox_label", label_1) # Начальный набор полей формы - group_loc = input_form_locator.get_by_role("combobox").nth(0) + group_loc = self.page.locator(input_form_locator).get_by_role("combobox").nth(0) group_input = TextInput(page, group_loc, "group_input") self.add_content_item("group_input", group_input) self.add_content_item( @@ -76,43 +76,59 @@ class AddADUserModalWindow(ModalWindowComponent): locator_button_search = self.page.get_by_role("button", name="Поиск") self.add_button(locator_button_search, "search") - loc = input_form_locator.locator("xpath=div[3]").locator(text_field_locator) + loc = self.page.locator(input_form_locator).locator("xpath=div[3]").locator(text_field_locator) name_input = TextInput(page, loc, "name_input") self.add_content_item("name_input", name_input) - role_loc = input_form_locator.get_by_role("combobox").nth(1) + role_loc = self.page.locator(input_form_locator).get_by_role("combobox").nth(2) role_input = TextInput(page, role_loc, "role_input") self.add_content_item("role_input", role_input) - self.add_content_item( - "roles_list", - DropdownList(page) - ) + self.add_content_item("roles_list", DropdownList(page)) - loc = input_form_locator.locator("xpath=div[6]").locator(text_field_locator) + + loc = self.page.locator(input_form_locator).locator("xpath=div[6]").locator(text_field_locator) commentary_input = TextInput(page, loc, "commentary_input") self.add_content_item("commentary_input", commentary_input) - loc = input_form_locator.locator("xpath=div[7]").locator(text_field_locator) + loc = self.page.locator(input_form_locator).locator("xpath=div[7]").locator(text_field_locator) email_input = TextInput(page, loc, "email_input") self.add_content_item("email_input", email_input) - loc = input_form_locator.locator("xpath=div[8]").locator(text_field_locator) + loc = self.page.locator(input_form_locator).locator("xpath=div[8]").locator(text_field_locator) phone_input = TextInput(page, loc, "phone_input") self.add_content_item("phone_input", phone_input) + # Чекбокс "Блокировка" - индекс 1 checkbox_2 = Checkbox( page, - page.get_by_role("checkbox").nth(1), - "push_notification" + self.page.locator(input_form_locator).get_by_role("checkbox").nth(1), + "blocking" ) - self.add_content_item("push_notification_checkbox", checkbox_2) + self.add_content_item("blocking_checkbox", checkbox_2) + # Метка "Блокировка" - индекс 1 label_2 = Text( page, self.page.locator(label_locator).nth(1), + "blocking_checkbox_label" + ) + self.add_content_item("blocking_checkbox_label", label_2) + + # Чекбокс "Push-уведомления" - индекс 2 + checkbox_3 = Checkbox( + page, + self.page.locator(input_form_locator).get_by_role("checkbox").nth(2), + "push_notification" + ) + self.add_content_item("push_notification_checkbox", checkbox_3) + + # Метка "Push-уведомления" - индекс 2 + label_3 = Text( + page, + self.page.locator(label_locator).nth(2), "push_notification_checkbox_label" ) - self.add_content_item("push_notification_checkbox_label", label_2) + self.add_content_item("push_notification_checkbox_label", label_3) # Добавление кнопок действий locator_button_add = self.page.get_by_role("button", name="Добавить") @@ -134,6 +150,26 @@ class AddADUserModalWindow(ModalWindowComponent): self.get_content_item("active_directory_checkbox").uncheck(force=True) + def check_blocking_checkbox(self): + """Включает чек-бокс Блокировка.""" + + self.get_content_item("blocking_checkbox").check(force=True) + + def uncheck_blocking_checkbox(self): + """Выключает чек-бокс Блокировка.""" + + self.get_content_item("blocking_checkbox").uncheck(force=True) + + def check_push_notification_checkbox(self): + """Включает чек-бокс Push-уведомления.""" + + self.get_content_item("push_notification_checkbox").check(force=True) + + def uncheck_push_notification_checkbox(self): + """Выключает чек-бокс Push-уведомления.""" + + self.get_content_item("push_notification_checkbox").uncheck(force=True) + def update_input_form_fields(self, expand): """Персчитывает локаторы полей формы ввода при добавлении/удалении дополнительного поля. """ @@ -237,6 +273,22 @@ class AddADUserModalWindow(ModalWindowComponent): roles_list.check_item_with_text(user_data["role"]) roles_list.click_item_with_text(user_data["role"]) + # Управление чекбоксом "Блокировка" + if "blocking_checked" in user_data: + checkbox = self.get_content_item("blocking_checkbox") + if user_data["blocking_checked"]: + checkbox.check() + else: + checkbox.uncheck() + + # Управление чекбоксом "Push-уведомления" + if "push_notification_checked" in user_data: + checkbox = self.get_content_item("push_notification_checkbox") + if user_data["push_notification_checked"]: + checkbox.check() + else: + checkbox.uncheck() + # Отправка формы add_button = self.get_button_by_name("add") add_button.click() @@ -248,9 +300,7 @@ class AddADUserModalWindow(ModalWindowComponent): f"Confirmation dialog window with title '{title}' is missing" ) - # На первом этапе реального пользователя не создаем - self.new_user_confirm.click_cancel_button() - self.close_window() + self.new_user_confirm.click_allow_button() def close_window(self): """Закрывает модальное окно через кнопку 'Закрыть'.""" @@ -290,6 +340,11 @@ class AddADUserModalWindow(ModalWindowComponent): "Active Directory", "Label 'Active Directory' is missing" ) + elif name == "blocking_checkbox_label": + item.check_have_text( + "Блокировка", + "Label 'Блокировка' is missing" + ) elif name == "push_notification_checkbox_label": item.check_have_text( "Подписка на Push-уведомления", diff --git a/components_derived/modal_add_local_user.py b/components_derived/modal_add_local_user.py index 90714ce..19ef35f 100644 --- a/components_derived/modal_add_local_user.py +++ b/components_derived/modal_add_local_user.py @@ -81,43 +81,26 @@ class AddLocalUserModalWindow(ModalWindowComponent): self.add_content_item("role_input", role_input) self.add_content_item("roles_list", DropdownList(page)) - loc = ( - self.page.locator(input_form_locator) - .locator("xpath=div[5]") - .locator(text_field_locator) - ) + loc = self.page.locator(input_form_locator).locator("xpath=div[5]").locator(text_field_locator) password_input = TextInput(page, loc, "password_input") self.add_content_item("password_input", password_input) - loc = ( - self.page.locator(input_form_locator) - .locator("xpath=div[6]") - .locator(text_field_locator) - ) + loc = self.page.locator(input_form_locator).locator("xpath=div[6]").locator(text_field_locator) commentary_input = TextInput(page, loc, "commentary_input") self.add_content_item("commentary_input", commentary_input) - loc = ( - self.page.locator(input_form_locator) - .locator("xpath=div[7]") - .locator(text_field_locator) - ) + loc = self.page.locator(input_form_locator).locator("xpath=div[7]").locator(text_field_locator) email_input = TextInput(page, loc, "email_input") self.add_content_item("email_input", email_input) - loc = ( - self.page.locator(input_form_locator) - .locator("xpath=div[8]") - .locator(text_field_locator) - ) + loc = self.page.locator(input_form_locator).locator("xpath=div[8]").locator(text_field_locator) phone_input = TextInput(page, loc, "phone_input") self.add_content_item("phone_input", phone_input) # Чекбокс "Блокировка" - индекс 1 checkbox_2 = Checkbox( page, - self.page.locator(ModalWindowLocators.INPUT_FORM_USER_DATA) - .get_by_role("checkbox").nth(1), + self.page.locator(input_form_locator).get_by_role("checkbox").nth(1), "blocking" ) self.add_content_item("blocking_checkbox", checkbox_2) @@ -130,16 +113,15 @@ class AddLocalUserModalWindow(ModalWindowComponent): ) self.add_content_item("blocking_checkbox_label", label_2) - # Чекбокс "Подписка на Push-уведомления" - индекс 2 + # Чекбокс "Push-уведомления" - индекс 2 checkbox_3 = Checkbox( page, - self.page.locator(ModalWindowLocators.INPUT_FORM_USER_DATA) - .get_by_role("checkbox").nth(2), + self.page.locator(input_form_locator).get_by_role("checkbox").nth(2), "push_notification" ) self.add_content_item("push_notification_checkbox", checkbox_3) - # Метка "Подписка на Push-уведомления" - индекс 2 + # Метка "Push-уведомления" - индекс 2 label_3 = Text( page, self.page.locator(label_locator).nth(2), @@ -167,6 +149,26 @@ class AddLocalUserModalWindow(ModalWindowComponent): self.get_content_item("active_directory_checkbox").uncheck(force=True) + def check_blocking_checkbox(self): + """Включает чек-бокс Блокировка.""" + + self.get_content_item("blocking_checkbox").check(force=True) + + def uncheck_blocking_checkbox(self): + """Выключает чек-бокс Блокировка.""" + + self.get_content_item("blocking_checkbox").uncheck(force=True) + + def check_push_notification_checkbox(self): + """Включает чек-бокс Push-уведомления.""" + + self.get_content_item("push_notification_checkbox").check(force=True) + + def uncheck_push_notification_checkbox(self): + """Выключает чек-бокс Push-уведомления.""" + + self.get_content_item("push_notification_checkbox").uncheck(force=True) + def new_user(self, user_data): """Заполняет форму и добавляет нового пользователя. @@ -299,18 +301,5 @@ class AddLocalUserModalWindow(ModalWindowComponent): f"Modal window content item with name '{name}' is missing" ) - # Дополнительная проверка состояния чекбоксов - blocking_checkbox = self.get_content_item("blocking_checkbox") - is_blocking_checked = blocking_checkbox.is_checked() - assert not is_blocking_checked, ( - "Checkbox 'Блокировка' should not be checked by default" - ) - - push_checkbox = self.get_content_item("push_notification_checkbox") - is_push_checked = push_checkbox.is_checked() - assert not is_push_checked, ( - "Checkbox 'Подписка на Push-уведомления' should not be checked by default" - ) - self.check_button_visibility("add") self.check_button_visibility("close") diff --git a/components_derived/modal_edit_user.py b/components_derived/modal_edit_user.py index b7b35b4..a787156 100644 --- a/components_derived/modal_edit_user.py +++ b/components_derived/modal_edit_user.py @@ -50,11 +50,7 @@ class EditUserModalWindow(ModalWindowComponent): self.add_toolbar_button(locator_button_toolbar_close, "close") # Добавление полей формы - loc = ( - self.page.locator(input_form_locator) - .locator("xpath=div[1]") - .locator(text_field_locator) - ) + loc = self.page.locator(input_form_locator).locator("xpath=div[1]").locator(text_field_locator) name_input = TextInput(page, loc, "name_input") self.add_content_item("name_input", name_input) @@ -63,37 +59,24 @@ class EditUserModalWindow(ModalWindowComponent): self.add_content_item("role_input", role_input) self.add_content_item("roles_list", DropdownList(page)) - loc = ( - self.page.locator(input_form_locator) - .locator("xpath=div[4]") - .locator(text_field_locator) - ) + loc = self.page.locator(input_form_locator).locator("xpath=div[4]").locator(text_field_locator) commentary_input = TextInput(page, loc, "commentary_input") self.add_content_item("commentary_input", commentary_input) - loc = ( - self.page.locator(input_form_locator) - .locator("xpath=div[5]") - .locator(text_field_locator) - ) + loc = self.page.locator(input_form_locator).locator("xpath=div[5]").locator(text_field_locator) email_input = TextInput(page, loc, "email_input") self.add_content_item("email_input", email_input) - loc = ( - self.page.locator(input_form_locator) - .locator("xpath=div[6]") - .locator(text_field_locator) - ) + loc = self.page.locator(input_form_locator).locator("xpath=div[6]").locator(text_field_locator) phone_input = TextInput(page, loc, "phone_input") self.add_content_item("phone_input", phone_input) # Добавление чекбоксов и их меток - # Чекбокс "Блокировка" - теперь индекс 0 (т.к. нет Active Directory) + # Чекбокс "Блокировка" - индекс 0 checkbox_1 = Checkbox( page, - self.page.locator(ModalWindowLocators.INPUT_FORM_USER_DATA) - .get_by_role("checkbox").nth(0), + self.page.locator(input_form_locator).get_by_role("checkbox").nth(0), "blocking" ) self.add_content_item("blocking_checkbox", checkbox_1) @@ -106,16 +89,15 @@ class EditUserModalWindow(ModalWindowComponent): ) self.add_content_item("blocking_checkbox_label", label_1) - # Чекбокс "Подписка на Push-уведомления" - индекс 1 + # Чекбокс "Push-уведомления" - индекс 1 checkbox_2 = Checkbox( page, - self.page.locator(ModalWindowLocators.INPUT_FORM_USER_DATA) - .get_by_role("checkbox").nth(1), + self.page.locator(input_form_locator).get_by_role("checkbox").nth(1), "push_notification" ) self.add_content_item("push_notification_checkbox", checkbox_2) - # Метка "Подписка на Push-уведомления" - индекс 1 + # Метка "Push-уведомления" - индекс 1 label_2 = Text( page, self.page.locator(label_locator).nth(1), @@ -140,6 +122,26 @@ class EditUserModalWindow(ModalWindowComponent): self.save_user_confirm = ConfirmComponent(page, " Отмена ", " Сохранить ") self.delete_user_confirm = ConfirmComponent(page, " Отмена ", " Удалить ") + def check_blocking_checkbox(self): + """Включает чек-бокс Блокировка.""" + + self.get_content_item("blocking_checkbox").check(force=True) + + def uncheck_blocking_checkbox(self): + """Выключает чек-бокс Блокировка.""" + + self.get_content_item("blocking_checkbox").uncheck(force=True) + + def check_push_notification_checkbox(self): + """Включает чек-бокс Push-уведомления.""" + + self.get_content_item("push_notification_checkbox").check(force=True) + + def uncheck_push_notification_checkbox(self): + """Выключает чек-бокс Push-уведомления.""" + + self.get_content_item("push_notification_checkbox").uncheck(force=True) + def close_window(self): """Закрывает окно через кнопку 'Закрыть'.""" @@ -273,19 +275,6 @@ class EditUserModalWindow(ModalWindowComponent): f"Modal window content item with name '{name}' is missing" ) - # Дополнительная проверка состояния чекбоксов - blocking_checkbox = self.get_content_item("blocking_checkbox") - is_blocking_checked = blocking_checkbox.is_checked() - assert not is_blocking_checked, ( - "Checkbox 'Блокировка' should not be checked by default" - ) - - push_checkbox = self.get_content_item("push_notification_checkbox") - is_push_checked = push_checkbox.is_checked() - assert not is_push_checked, ( - "Checkbox 'Подписка на Push-уведомления' should be checked by default" - ) - self.check_button_visibility("save") self.check_button_visibility("delete") self.check_button_visibility("reset_password") diff --git a/tests/e2e/test_users_tab.py b/tests/e2e/test_users_tab.py index fc666bb..b261ccd 100644 --- a/tests/e2e/test_users_tab.py +++ b/tests/e2e/test_users_tab.py @@ -67,7 +67,7 @@ class TestUsersTab: ut = UsersTab(browser) # Удаляем тестовых пользователей - test_users = ["TestUser", "TestUserAutoOperator", "TestUserAutoAdmin"] + test_users = ["tester1","TestUser", "TestUserAutoOperator", "TestUserAutoAdmin"] for user_name in test_users: # Проверяем существует ли пользователь и удаляем его @@ -76,7 +76,6 @@ class TestUsersTab: ut.open_edit_user_page_by_user(user_name, "Администратор") ut.delete_user(user_name) - #@pytest.mark.skip(reason=" Временно исключено из тестирования") def test_users_tab_content(self, browser: Page) -> None: """Проверяет содержимое вкладки 'Пользователи'. @@ -89,7 +88,6 @@ class TestUsersTab: ut.should_be_users_table() ut.check_users_table_content(True) - #@pytest.mark.skip(reason=" Временно исключено из тестирования") def test_users_tab_toolbar_buttons(self, browser: Page) -> None: """Проверяет кнопки на панели инструментов. @@ -101,7 +99,6 @@ class TestUsersTab: ut.should_be_toolbar_buttons() # @pytest.mark.develop - #@pytest.mark.skip(reason=" Временно исключено из тестирования") def test_add_user_window_content(self, browser: Page) -> None: """Проверяет содержимое окна добавления пользователя. @@ -115,7 +112,6 @@ class TestUsersTab: ut.transform_to_add_AD_user_window() ut.check_add_AD_user_window_content() - #@pytest.mark.skip(reason=" Временно исключено из тестирования") def test_add_user_window_close_buttons(self, browser: Page) -> None: """Проверяет кнопки закрытия окна добавления. @@ -138,7 +134,6 @@ class TestUsersTab: ut.transform_to_add_AD_user_window() ut.close_add_AD_user_window() - #@pytest.mark.skip(reason=" Временно исключено из тестирования") def test_edit_user_window_content(self, browser: Page) -> None: """Проверяет содержимое окна редактирования. @@ -150,7 +145,6 @@ class TestUsersTab: user_name, role = ut.open_edit_user_page_by_index(0) ut.check_edit_user_window_content(user_name, role) - #@pytest.mark.skip(reason=" Временно исключено из тестирования") def test_edit_user_window_close_buttons(self, browser: Page) -> None: """Проверяет кнопки закрытия окна редактирования. @@ -164,8 +158,8 @@ class TestUsersTab: user_name, _ = ut.open_edit_user_page_by_index(0) ut.close_edit_user_window(user_name) - # @pytest.mark.develop - #@pytest.mark.skip(reason=" Временно исключено из тестирования") + #@pytest.mark.develop + @pytest.mark.skip(reason="Временно исключено из тестирования") def test_add_and_delete_user(self, browser: Page, cleanup_users: None) -> None: """Проверяет добавление и удаление пользователя. @@ -213,8 +207,7 @@ class TestUsersTab: mp.click_subpanel_item("Пользователи") ut.should_not_be_user_in_table(user_data["name"], user_data["role"]) - # @pytest.mark.develop - @pytest.mark.skip(reason=" Временно исключено из тестирования") + #@pytest.mark.develop def test_add_AD_user(self, browser: Page, cleanup_users: None) -> None: """Проверяет добавление пользователя Active Directory. @@ -224,8 +217,8 @@ class TestUsersTab: """ user_data: Dict[str, str] = {"auth_type":"active_directory", - "group": "Администраторы", - "name": "Администратор", + "group": "NMS_tester", + "name": "tester1", "role": "Администратор"} ut = UsersTab(browser) @@ -233,7 +226,6 @@ class TestUsersTab: ut.open_add_user_window() ut.add_new_user(user_data) - #@pytest.mark.skip(reason=" Временно исключено из тестирования") def test_reset_password(self, browser: Page, cleanup_users: None) -> None: """Проверяет сброс пароля пользователя. @@ -274,7 +266,6 @@ class TestUsersTab: mp_1.click_subpanel_item("Пользователи") ut_1.should_not_be_user_in_table(user_data["name"], user_data["role"]) - #@pytest.mark.skip(reason=" Временно исключено из тестирования") def test_edit_user_role(self, browser: Page, cleanup_users: None) -> None: """Проверяет изменение роли пользователя.