Skip to content

EditUserModalWindow

Модуль modal_edit_user содержит класс для работы с окном редактирования пользователя.

Класс EditUserModalWindow наследует базовый функционал ModalWindowComponent и реализует методы для редактирования данных пользователя.

EditUserModalWindow

Bases: ModalWindowComponent

Модальное окно редактирования пользователя.

Наследует ModalWindowComponent и добавляет: - Поля редактирования данных - Чекбоксы настроек - Выпадающий список ролей - Кнопки действий (Сохранить, Удалить и др.)

Source code in components_derived\modal_edit_user.py
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
class EditUserModalWindow(ModalWindowComponent):
    """Модальное окно редактирования пользователя.

    Наследует ModalWindowComponent и добавляет:
    - Поля редактирования данных
    - Чекбоксы настроек
    - Выпадающий список ролей
    - Кнопки действий (Сохранить, Удалить и др.)
    """

    def __init__(self, page: Page, user_name: str):
        """Инициализирует элементы формы редактирования пользователя."""

        super().__init__(page)

        # Локаторы элементов формы
        # text_field_locator = ModalWindowLocators.TEXT_FIELD_INPUT_FORM_USER_DATA
        text_field_locator = f"xpath={ModalWindowLocators.TEXT_FIELD_INPUT_FORM_USER_DATA}"
        input_form_locator = ModalWindowLocators.INPUT_FORM_USER_DATA
        label_locator = ModalWindowLocators.LABEL_INPUT_FORM_USER_DATA

        # Настройка заголовка и кнопки закрытия
        self.window_title = user_name
        locator_button_toolbar_close = (
            self.page.get_by_role("navigation")
            .filter(has_text=re.compile(self.window_title))
            .get_by_role("button")
        )

        self.add_toolbar_title(self.window_title)
        self.add_toolbar_button(locator_button_toolbar_close, "close")

        # Добавление полей формы
        # Поле Имя
        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)

        # Поле Роль
        role_loc = self.page.locator(input_form_locator).get_by_role("combobox").nth(0)
        role_input = TextInput(page, role_loc, "role_input")
        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)
        )
        commentary_input = TextInput(page, loc, "commentary_input")
        self.add_content_item("commentary_input", commentary_input)

        # Поле E-mail
        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)
        )
        phone_input = TextInput(page, loc, "phone_input")
        self.add_content_item("phone_input", phone_input)

        # Добавление чекбоксов и их меток

        # Чекбокс "Блокировка" - теперь индекс 0 (т.к. нет Active Directory)
        checkbox_1 = Checkbox(
            page,
            self.page.locator(ModalWindowLocators.INPUT_FORM_USER_DATA)
            .get_by_role("checkbox").nth(0),
            "blocking"
        )
        self.add_content_item("blocking_checkbox", checkbox_1)

        # Метка "Блокировка" - индекс 0
        label_1 = Text(
            page,
            self.page.locator(label_locator).nth(0),
            "blocking_checkbox_label"
        )
        self.add_content_item("blocking_checkbox_label", label_1)

        # Чекбокс "Подписка на Push-уведомления" - индекс 1
        checkbox_2 = Checkbox(
            page,
            self.page.locator(ModalWindowLocators.INPUT_FORM_USER_DATA)
            .get_by_role("checkbox").nth(1),
            "push_notification"
        )
        self.add_content_item("push_notification_checkbox", checkbox_2)

        # Метка "Подписка на Push-уведомления" - индекс 1
        label_2 = Text(
            page,
            self.page.locator(label_locator).nth(1),
            "push_notification_checkbox_label"
        )
        self.add_content_item("push_notification_checkbox_label", label_2)

        # Добавление кнопок действий
        locator_button_save = self.page.get_by_role("button", name="Сохранить")
        self.add_button(locator_button_save, "save")

        locator_button_delete = self.page.get_by_role("button", name="Удалить")
        self.add_button(locator_button_delete, "delete")

        locator_button_reset = self.page.get_by_role("button", name="Сбросить пароль")
        self.add_button(locator_button_reset, "reset_password")

        locator_button_close = self.page.get_by_role("button", name="Закрыть")
        self.add_button(locator_button_close, "close")

        # Инициализация компонентов подтверждения
        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):
        """Закрывает окно через кнопку 'Закрыть'."""

        close_button = self.get_button_by_name("close")
        close_button.click()

    def close_window_by_toolbar_button(self):
        """Закрывает окно через кнопку в тулбаре."""

        self.click_toolbar_close_button()

    def delete_user(self):
        """Удаляет пользователя с подтверждением."""

        delete_button = self.get_button_by_name("delete")
        delete_button.click()

        title = "Удаление"
        self.delete_user_confirm.check_title(
            title,
            f"Confirmation dialog window with title '{title}' is missing"
        )
        self.delete_user_confirm.click_allow_button()

    def edit_user(self, user_data):
        """Редактирует данные пользователя.

        Args:
            user_data (dict): Данные для обновления (имя, роль и др.)
        """

        fields = user_data.keys()

        if "name" in fields:
            input_field = self.get_content_item("name_input")
            input_field.input_value(user_data["name"])

        if "role" in fields:
            role_field = self.get_content_item("role_input")
            role_field.click()

            roles_list = self.get_content_item("roles_list")
            roles_list.check_item_with_text(user_data["role"])
            roles_list.click_item_with_text(user_data["role"])

        if "commentary" in fields:
            input_field = self.get_content_item("commentary_input")
            input_field.input_value(user_data["commentary"])

        if "email" in fields:
            input_field = self.get_content_item("email_input")
            input_field.input_value(user_data["email"])

        if "phone_number" in fields:
            input_field = self.get_content_item("phone_input")
            input_field.input_value(user_data["phone_number"])

        if "blocking_checked" in fields:
            checkbox = self.get_content_item("blocking_checkbox")
            if user_data["blocking_checked"]:
                checkbox.check()
            else:
                checkbox.uncheck()

        if "push_notification_checked" in fields:
            checkbox = self.get_content_item("push_notification_checkbox")
            if user_data["push_notification_checked"]:
                checkbox.check()
            else:
                checkbox.uncheck()

        save_button = self.get_button_by_name("save")
        save_button.click()

        title = "Сохранение"
        self.save_user_confirm.check_title(
            title,
            f"Confirmation dialog window with title '{title}' is missing"
        )
        self.save_user_confirm.click_allow_button()

    def reset_password(self):
        """Инициирует сброс пароля пользователя."""

        reset_password_button = self.get_button_by_name("reset_password")
        reset_password_button.click()

    # Проверки:
    def check_content(self, user_name, role):
        """Проверяет наличие и корректность элементов окна.

        Args:
            user_name (str): Ожидаемое имя пользователя
            role (str): Ожидаемая роль пользователя
        """

        menu_locator = self.page.locator(ModalWindowLocators.MENU_INPUT_FORM_USER_DATA)

        self.check_by_window_title()
        self.check_toolbar_button_visibility("close")
        self.check_toolbar_button_tooltip("close", "Закрыть")

        for name in self.content_items:
            item = self.get_content_item(name)

            if name == "push_notification_checkbox_label":
                item.check_have_text(
                    "Подписка на Push-уведомления",
                    "Label 'Подписка на Push-уведомления' is missing"
                )
            elif name == "blocking_checkbox_label":
                item.check_have_text(
                    "Блокировка",
                    "Label 'Блокировка' is missing"
                )
            elif name == "name_input":
                name_field = self.get_content_item("name_input")
                text_value = name_field.get_input_value()
                assert text_value == user_name, (
                    f"Expected user name '{user_name}' is not equal "
                    f"real user name '{text_value}'"
                )
            elif name == "role_input":
                item.click()
                roles_list = self.get_content_item("roles_list")
                roles_list.check_visibility(menu_locator, "Roles list is missing")
                roles_list.check_item_with_text(role)
            elif name == "roles_list":
                continue
            else:
                item.check_visibility(
                    f"Modal window content item with name '{name}' is missing"
                )

        self.check_button_visibility("save")
        self.check_button_visibility("delete")
        self.check_button_visibility("reset_password")
        self.check_button_visibility("close")

__init__(page, user_name)

Инициализирует элементы формы редактирования пользователя.

Source code in components_derived\modal_edit_user.py
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
def __init__(self, page: Page, user_name: str):
    """Инициализирует элементы формы редактирования пользователя."""

    super().__init__(page)

    # Локаторы элементов формы
    # text_field_locator = ModalWindowLocators.TEXT_FIELD_INPUT_FORM_USER_DATA
    text_field_locator = f"xpath={ModalWindowLocators.TEXT_FIELD_INPUT_FORM_USER_DATA}"
    input_form_locator = ModalWindowLocators.INPUT_FORM_USER_DATA
    label_locator = ModalWindowLocators.LABEL_INPUT_FORM_USER_DATA

    # Настройка заголовка и кнопки закрытия
    self.window_title = user_name
    locator_button_toolbar_close = (
        self.page.get_by_role("navigation")
        .filter(has_text=re.compile(self.window_title))
        .get_by_role("button")
    )

    self.add_toolbar_title(self.window_title)
    self.add_toolbar_button(locator_button_toolbar_close, "close")

    # Добавление полей формы
    # Поле Имя
    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)

    # Поле Роль
    role_loc = self.page.locator(input_form_locator).get_by_role("combobox").nth(0)
    role_input = TextInput(page, role_loc, "role_input")
    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)
    )
    commentary_input = TextInput(page, loc, "commentary_input")
    self.add_content_item("commentary_input", commentary_input)

    # Поле E-mail
    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)
    )
    phone_input = TextInput(page, loc, "phone_input")
    self.add_content_item("phone_input", phone_input)

    # Добавление чекбоксов и их меток

    # Чекбокс "Блокировка" - теперь индекс 0 (т.к. нет Active Directory)
    checkbox_1 = Checkbox(
        page,
        self.page.locator(ModalWindowLocators.INPUT_FORM_USER_DATA)
        .get_by_role("checkbox").nth(0),
        "blocking"
    )
    self.add_content_item("blocking_checkbox", checkbox_1)

    # Метка "Блокировка" - индекс 0
    label_1 = Text(
        page,
        self.page.locator(label_locator).nth(0),
        "blocking_checkbox_label"
    )
    self.add_content_item("blocking_checkbox_label", label_1)

    # Чекбокс "Подписка на Push-уведомления" - индекс 1
    checkbox_2 = Checkbox(
        page,
        self.page.locator(ModalWindowLocators.INPUT_FORM_USER_DATA)
        .get_by_role("checkbox").nth(1),
        "push_notification"
    )
    self.add_content_item("push_notification_checkbox", checkbox_2)

    # Метка "Подписка на Push-уведомления" - индекс 1
    label_2 = Text(
        page,
        self.page.locator(label_locator).nth(1),
        "push_notification_checkbox_label"
    )
    self.add_content_item("push_notification_checkbox_label", label_2)

    # Добавление кнопок действий
    locator_button_save = self.page.get_by_role("button", name="Сохранить")
    self.add_button(locator_button_save, "save")

    locator_button_delete = self.page.get_by_role("button", name="Удалить")
    self.add_button(locator_button_delete, "delete")

    locator_button_reset = self.page.get_by_role("button", name="Сбросить пароль")
    self.add_button(locator_button_reset, "reset_password")

    locator_button_close = self.page.get_by_role("button", name="Закрыть")
    self.add_button(locator_button_close, "close")

    # Инициализация компонентов подтверждения
    self.save_user_confirm = ConfirmComponent(page, " Отмена ", " Сохранить ")
    self.delete_user_confirm = ConfirmComponent(page, " Отмена ", " Удалить ")

check_blocking_checkbox()

Включает чек-бокс Блокировка.

Source code in components_derived\modal_edit_user.py
150
151
152
153
def check_blocking_checkbox(self):
    """Включает чек-бокс Блокировка."""

    self.get_content_item("blocking_checkbox").check(force=True)

check_content(user_name, role)

Проверяет наличие и корректность элементов окна.

Parameters:

Name Type Description Default
user_name str

Ожидаемое имя пользователя

required
role str

Ожидаемая роль пользователя

required
Source code in components_derived\modal_edit_user.py
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
def check_content(self, user_name, role):
    """Проверяет наличие и корректность элементов окна.

    Args:
        user_name (str): Ожидаемое имя пользователя
        role (str): Ожидаемая роль пользователя
    """

    menu_locator = self.page.locator(ModalWindowLocators.MENU_INPUT_FORM_USER_DATA)

    self.check_by_window_title()
    self.check_toolbar_button_visibility("close")
    self.check_toolbar_button_tooltip("close", "Закрыть")

    for name in self.content_items:
        item = self.get_content_item(name)

        if name == "push_notification_checkbox_label":
            item.check_have_text(
                "Подписка на Push-уведомления",
                "Label 'Подписка на Push-уведомления' is missing"
            )
        elif name == "blocking_checkbox_label":
            item.check_have_text(
                "Блокировка",
                "Label 'Блокировка' is missing"
            )
        elif name == "name_input":
            name_field = self.get_content_item("name_input")
            text_value = name_field.get_input_value()
            assert text_value == user_name, (
                f"Expected user name '{user_name}' is not equal "
                f"real user name '{text_value}'"
            )
        elif name == "role_input":
            item.click()
            roles_list = self.get_content_item("roles_list")
            roles_list.check_visibility(menu_locator, "Roles list is missing")
            roles_list.check_item_with_text(role)
        elif name == "roles_list":
            continue
        else:
            item.check_visibility(
                f"Modal window content item with name '{name}' is missing"
            )

    self.check_button_visibility("save")
    self.check_button_visibility("delete")
    self.check_button_visibility("reset_password")
    self.check_button_visibility("close")

check_push_notification_checkbox()

Включает чек-бокс Push-уведомления.

Source code in components_derived\modal_edit_user.py
160
161
162
163
def check_push_notification_checkbox(self):
    """Включает чек-бокс Push-уведомления."""

    self.get_content_item("push_notification_checkbox").check(force=True)

close_window()

Закрывает окно через кнопку 'Закрыть'.

Source code in components_derived\modal_edit_user.py
170
171
172
173
174
def close_window(self):
    """Закрывает окно через кнопку 'Закрыть'."""

    close_button = self.get_button_by_name("close")
    close_button.click()

close_window_by_toolbar_button()

Закрывает окно через кнопку в тулбаре.

Source code in components_derived\modal_edit_user.py
176
177
178
179
def close_window_by_toolbar_button(self):
    """Закрывает окно через кнопку в тулбаре."""

    self.click_toolbar_close_button()

delete_user()

Удаляет пользователя с подтверждением.

Source code in components_derived\modal_edit_user.py
181
182
183
184
185
186
187
188
189
190
191
192
def delete_user(self):
    """Удаляет пользователя с подтверждением."""

    delete_button = self.get_button_by_name("delete")
    delete_button.click()

    title = "Удаление"
    self.delete_user_confirm.check_title(
        title,
        f"Confirmation dialog window with title '{title}' is missing"
    )
    self.delete_user_confirm.click_allow_button()

edit_user(user_data)

Редактирует данные пользователя.

Parameters:

Name Type Description Default
user_data dict

Данные для обновления (имя, роль и др.)

required
Source code in components_derived\modal_edit_user.py
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
def edit_user(self, user_data):
    """Редактирует данные пользователя.

    Args:
        user_data (dict): Данные для обновления (имя, роль и др.)
    """

    fields = user_data.keys()

    if "name" in fields:
        input_field = self.get_content_item("name_input")
        input_field.input_value(user_data["name"])

    if "role" in fields:
        role_field = self.get_content_item("role_input")
        role_field.click()

        roles_list = self.get_content_item("roles_list")
        roles_list.check_item_with_text(user_data["role"])
        roles_list.click_item_with_text(user_data["role"])

    if "commentary" in fields:
        input_field = self.get_content_item("commentary_input")
        input_field.input_value(user_data["commentary"])

    if "email" in fields:
        input_field = self.get_content_item("email_input")
        input_field.input_value(user_data["email"])

    if "phone_number" in fields:
        input_field = self.get_content_item("phone_input")
        input_field.input_value(user_data["phone_number"])

    if "blocking_checked" in fields:
        checkbox = self.get_content_item("blocking_checkbox")
        if user_data["blocking_checked"]:
            checkbox.check()
        else:
            checkbox.uncheck()

    if "push_notification_checked" in fields:
        checkbox = self.get_content_item("push_notification_checkbox")
        if user_data["push_notification_checked"]:
            checkbox.check()
        else:
            checkbox.uncheck()

    save_button = self.get_button_by_name("save")
    save_button.click()

    title = "Сохранение"
    self.save_user_confirm.check_title(
        title,
        f"Confirmation dialog window with title '{title}' is missing"
    )
    self.save_user_confirm.click_allow_button()

reset_password()

Инициирует сброс пароля пользователя.

Source code in components_derived\modal_edit_user.py
251
252
253
254
255
def reset_password(self):
    """Инициирует сброс пароля пользователя."""

    reset_password_button = self.get_button_by_name("reset_password")
    reset_password_button.click()

uncheck_blocking_checkbox()

Выключает чек-бокс Блокировка.

Source code in components_derived\modal_edit_user.py
155
156
157
158
def uncheck_blocking_checkbox(self):
    """Выключает чек-бокс Блокировка."""

    self.get_content_item("blocking_checkbox").uncheck(force=True)

uncheck_push_notification_checkbox()

Выключает чек-бокс Push-уведомления.

Source code in components_derived\modal_edit_user.py
165
166
167
168
def uncheck_push_notification_checkbox(self):
    """Выключает чек-бокс Push-уведомления."""

    self.get_content_item("push_notification_checkbox").uncheck(force=True)