Skip to content

AddADUserModalWindow

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

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

AddADUserModalWindow

Bases: ModalWindowComponent

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

Наследует ModalWindowComponent и добавляет элементы формы: - Поля ввода (имя, пароль, email и др.) - Чекбоксы (Active Directory, Push-уведомления) - Выпадающие списки групп, пользователей AD, ролей - Кнопки действий

Source code in components_derived\modal_add_AD_user.py
 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
class AddADUserModalWindow(ModalWindowComponent):
    """Модальное окно добавления нового пользователя.

    Наследует ModalWindowComponent и добавляет элементы формы:
    - Поля ввода (имя, пароль, email и др.)
    - Чекбоксы (Active Directory, Push-уведомления)
    - Выпадающие списки групп, пользователей AD, ролей
    - Кнопки действий
    """

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

        super().__init__(page)

        # Локаторы элементов формы
        input_form_locator = page.locator(ModalWindowLocators.INPUT_FORM_USER_DATA)
        text_field_locator = ModalWindowLocators.TEXT_FIELD_INPUT_FORM_USER_DATA
        label_locator = ModalWindowLocators.LABEL_INPUT_FORM_USER_DATA

        # Настройка заголовка и кнопки закрытия тулбара
        self.window_title = "Добавить нового пользователя"
        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")

        # Добавление элементов формы
        checkbox_1 = Checkbox(
            page,
            input_form_locator.get_by_role("checkbox").nth(0),
            "active_directory"
        )
        self.add_content_item("active_directory_checkbox", checkbox_1)

        label_1 = Text(
            page,
            self.page.locator(label_locator).nth(0),
            "active_directory_checkbox_label"
        )
        self.add_content_item("active_directory_checkbox_label", label_1)

        # Начальный набор полей формы
        # Поле Группа
        group_loc = 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(
            "group_list",
            DropdownList(page)
        )

        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)
        name_input = TextInput(page, loc, "name_input")
        self.add_content_item("name_input", name_input)

        # Чекбокс "Блокировка" - индекс 1
        checkbox_2 = Checkbox(
            page,
            input_form_locator.get_by_role("checkbox").nth(1),
            "blocking"
        )
        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)

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

        # Поле E-mail
        loc = input_form_locator.locator("xpath=div[8]").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[9]").locator(text_field_locator)
        phone_input = TextInput(page, loc, "phone_input")
        self.add_content_item("phone_input", phone_input)

        # Чекбокс "Подписка на Push-уведомления" - индекс 2
        checkbox_3 = Checkbox(
            page,
            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_3)

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

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

        self.new_user_confirm = ConfirmComponent(page, " Отмена ", " Добавить ")

    # Действия:
    def check_active_directory_checkbox(self):
        """Включает чек-бокс Active Directory. """

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

    def uncheck_active_directory_checkbox(self):
        """Выключает чек-бокс Active Directory. """

        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):
        """Персчитывает локаторы полей формы ввода при добавлении/удалении дополнительного поля. """

        input_form_locator = self.page.locator(ModalWindowLocators.INPUT_FORM_USER_DATA)
        text_field_locator = ModalWindowLocators.TEXT_FIELD_INPUT_FORM_USER_DATA

        if expand:
            new_loc = input_form_locator.locator("xpath=div[4]").locator(text_field_locator)
            self.get_content_item("name_input").update_locator(new_loc)

            new_loc = input_form_locator.locator("xpath=div[8]").locator(text_field_locator)
            self.get_content_item("commentary_input").update_locator(new_loc)

            new_loc = input_form_locator.locator("xpath=div[9]").locator(text_field_locator)
            self.get_content_item("email_input").update_locator(new_loc)

            new_loc = input_form_locator.locator("xpath=div[10]").locator(text_field_locator)
            self.get_content_item("phone_input").update_locator(new_loc)

            role_loc = input_form_locator.get_by_role("combobox").nth(2)
            self.get_content_item("role_input").update_locator(role_loc)
        else:
            new_loc = input_form_locator.locator("xpath=div[3]").locator(text_field_locator)
            self.get_content_item("name_input").update_locator(new_loc)

            new_loc = input_form_locator.locator("xpath=div[7]").locator(text_field_locator)
            self.get_content_item("commentary_input").update_locator(new_loc)

            new_loc = input_form_locator.locator("xpath=div[8]").locator(text_field_locator)
            self.get_content_item("email_input").update_locator(new_loc)

            new_loc = input_form_locator.locator("xpath=div[9]").locator(text_field_locator)
            self.get_content_item("phone_input").update_locator(new_loc)

            role_loc = input_form_locator.get_by_role("combobox").nth(1)
            self.get_content_item("role_input").update_locator(role_loc)

    def new_user(self, user_data):
        """Заполняет форму и добавляет нового пользователя.

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

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

        # Поле "Группа" - выбор из списка
        group_name = user_data.get("group")
        if group_name is None:
            assert False, "Value of 'group' is missing"

        # Поле "Пользователи AD" - выбор из списка
        name_AD = user_data.get("name_AD")
        if name_AD is None:
            assert False, "Value of 'name_AD' is missing"

        # Поле "Имя" - если определено (не None) вводим вручную
        name = user_data.get("name")

        # Поле "Роль" - выбор из списка
        role = user_data.get("role")
        if role is None:
            assert False, "Value of 'role' is missing"

        # Поиск и выбор заданной группы из списка существующих
        group_field = self.get_content_item("group_input")
        group_field.click()

        group_list = self.get_content_item("group_list")
        group_list.scroll_until_end(menu_locator)
        group_names = group_list.get_item_names(menu_locator)
        if group_name not in group_names:
            assert False, f"Required group name {group_name} is missing"

        group_list.check_item_with_text(group_name)
        group_list.click_item_with_text(group_name)

        # Нажатие кнопки "Поиск"
        search_button = self.get_button_by_name("search")
        search_button.click()

        count = input_form_locator.get_by_role("combobox").count()
        if count == 2:
            assert False, f"Selected group {group_name} is empty. Use another group."

        # Если в группе есть пользователи, открывается новое поле, персчет локаторов
        self.update_input_form_fields(expand=True)

        # Поиск и выбор заданного пользователя AD из списка существующих
        user_AD_loc = input_form_locator.get_by_role("combobox").nth(1)
        user_AD_input = TextInput(self.page, user_AD_loc, "user_AD_input")
        self.add_content_item("user_AD_input", user_AD_input)
        self.add_content_item(
            "user_AD_list",
            DropdownList(self.page)
        )

        user_AD_input.click()
        user_AD_list = self.get_content_item("user_AD_list")
        user_AD_list.scroll_until_end(menu_locator)
        user_AD_names = group_list.get_item_names(menu_locator)
        if name_AD not in user_AD_names:
            assert False, f"Required user name {name_AD} is missing"

        user_AD_list.check_item_with_text(name_AD)
        user_AD_list.click_item_with_text(name_AD)

        # Заполнение поля "Имя" (ручной ввод) если задано
        if name:
            name_field = self.get_content_item("name_input")
            name_field.input_value(name)

        # Поиск и выбор заданной роли из списка существующих
        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 user_data.get("commentary"):
            input_field = self.get_content_item("commentary_input")
            input_field.input_value(user_data["commentary"])

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

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

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

        if user_data.get("push_notification_checked"):
            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()

        # Подтверждение действия
        title = "Добавить нового пользователя"
        self.new_user_confirm.check_title(
            title,
            f"Confirmation dialog window with title '{title}' is missing"
        )
        self.new_user_confirm.click_allow_button()

    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 check_content(self):
        """Проверяет наличие и корректность всех элементов формы."""

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

        self.check_by_window_title()

        is_checked = self.get_content_item("active_directory_checkbox").is_checked()
        if not is_checked:
            assert False, \
            "The checkbox 'Active Directory'should be checked for the add user from Active Directory window"

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

        no_op_names = ["roles_list", "group_list"]

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

            if name == "active_directory_checkbox_label":
                item.check_have_text(
                    "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-уведомления",
                    "Label 'Подписка на Push-уведомления' is missing"
                )
            elif name == "group_input":
                item.click()
                group_list = self.get_content_item("group_list")
                group_list.check_visibility(menu_locator,
                                          "Groups list is missing")

                is_scrollable_vertically = group_list.check_vertical_scrolling(menu_locator)
                assert is_scrollable_vertically, "Groups list should be scrollable_vertically"
                self.page.keyboard.press("Escape")
            elif name == "role_input":
                item.click()
                roles_list = self.get_content_item("roles_list")
                roles_list.check_visibility(menu_locator,
                                          "Roles list is missing")

                is_scrollable_vertically = roles_list.check_vertical_scrolling(menu_locator)
                assert not is_scrollable_vertically, \
                            "Roles list should not be scrollable_vertically"

                for role in roles_dict.values():
                    # временно, пока есть несоответствие со списком ролей в вкладке Сессии
                    if role == "Пользователь":
                        continue
                    roles_list.check_item_with_text(role)
                self.page.keyboard.press("Escape")
            elif name in no_op_names:
                continue
            else:
                print(f"check item: {name}")
                item.check_visibility(
                    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("search")
        self.check_button_visibility("add")
        self.check_button_visibility("close")

        search_button = self.get_button_by_name("search")
        search_button.click()

        # Проверка что поле "Пользователи AD" появилось после поиска
        user_AD_loc = input_form_locator.get_by_role("combobox").nth(1)
        user_AD_input = TextInput(self.page, user_AD_loc, "user_AD_input")
        self.add_content_item("user_AD_input", user_AD_input)
        self.add_content_item(
            "user_AD_list",
            DropdownList(self.page)
        )

        user_AD_input.click()
        user_AD_list = self.get_content_item("user_AD_list")
        user_AD_list.check_visibility(menu_locator,
                                  "Users AD list is missing")
        is_scrollable_vertically = user_AD_list.check_vertical_scrolling(menu_locator)
        assert is_scrollable_vertically, "Users AD list should be scrollable_vertically"
        self.page.keyboard.press("Escape")

        self.update_input_form_fields(expand=True)

        self.get_content_item("name_input").check_visibility(
                                           "Modal window content item with name 'name_input' is missing")
        self.get_content_item("role_input").check_visibility(
                                           "Modal window content item with name 'role_input' is missing")
        self.get_content_item("commentary_input").check_visibility(
                                           "Modal window content item with name 'commentary_input' is missing")
        self.get_content_item("email_input").check_visibility(
                                           "Modal window content item with name 'email_input' is missing")
        self.get_content_item("phone_input").check_visibility(
                                           "Modal window content item with name 'phone_input' is missing")

__init__(page)

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

Source code in components_derived\modal_add_AD_user.py
 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
def __init__(self, page: Page):
    """Инициализирует элементы формы добавления пользователя."""

    super().__init__(page)

    # Локаторы элементов формы
    input_form_locator = page.locator(ModalWindowLocators.INPUT_FORM_USER_DATA)
    text_field_locator = ModalWindowLocators.TEXT_FIELD_INPUT_FORM_USER_DATA
    label_locator = ModalWindowLocators.LABEL_INPUT_FORM_USER_DATA

    # Настройка заголовка и кнопки закрытия тулбара
    self.window_title = "Добавить нового пользователя"
    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")

    # Добавление элементов формы
    checkbox_1 = Checkbox(
        page,
        input_form_locator.get_by_role("checkbox").nth(0),
        "active_directory"
    )
    self.add_content_item("active_directory_checkbox", checkbox_1)

    label_1 = Text(
        page,
        self.page.locator(label_locator).nth(0),
        "active_directory_checkbox_label"
    )
    self.add_content_item("active_directory_checkbox_label", label_1)

    # Начальный набор полей формы
    # Поле Группа
    group_loc = 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(
        "group_list",
        DropdownList(page)
    )

    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)
    name_input = TextInput(page, loc, "name_input")
    self.add_content_item("name_input", name_input)

    # Чекбокс "Блокировка" - индекс 1
    checkbox_2 = Checkbox(
        page,
        input_form_locator.get_by_role("checkbox").nth(1),
        "blocking"
    )
    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)

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

    # Поле E-mail
    loc = input_form_locator.locator("xpath=div[8]").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[9]").locator(text_field_locator)
    phone_input = TextInput(page, loc, "phone_input")
    self.add_content_item("phone_input", phone_input)

    # Чекбокс "Подписка на Push-уведомления" - индекс 2
    checkbox_3 = Checkbox(
        page,
        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_3)

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

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

    self.new_user_confirm = ConfirmComponent(page, " Отмена ", " Добавить ")

check_active_directory_checkbox()

Включает чек-бокс Active Directory.

Source code in components_derived\modal_add_AD_user.py
151
152
153
154
def check_active_directory_checkbox(self):
    """Включает чек-бокс Active Directory. """

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

check_blocking_checkbox()

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

Source code in components_derived\modal_add_AD_user.py
161
162
163
164
def check_blocking_checkbox(self):
    """Включает чек-бокс Блокировка."""

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

check_content()

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

Source code in components_derived\modal_add_AD_user.py
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
def check_content(self):
    """Проверяет наличие и корректность всех элементов формы."""

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

    self.check_by_window_title()

    is_checked = self.get_content_item("active_directory_checkbox").is_checked()
    if not is_checked:
        assert False, \
        "The checkbox 'Active Directory'should be checked for the add user from Active Directory window"

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

    no_op_names = ["roles_list", "group_list"]

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

        if name == "active_directory_checkbox_label":
            item.check_have_text(
                "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-уведомления",
                "Label 'Подписка на Push-уведомления' is missing"
            )
        elif name == "group_input":
            item.click()
            group_list = self.get_content_item("group_list")
            group_list.check_visibility(menu_locator,
                                      "Groups list is missing")

            is_scrollable_vertically = group_list.check_vertical_scrolling(menu_locator)
            assert is_scrollable_vertically, "Groups list should be scrollable_vertically"
            self.page.keyboard.press("Escape")
        elif name == "role_input":
            item.click()
            roles_list = self.get_content_item("roles_list")
            roles_list.check_visibility(menu_locator,
                                      "Roles list is missing")

            is_scrollable_vertically = roles_list.check_vertical_scrolling(menu_locator)
            assert not is_scrollable_vertically, \
                        "Roles list should not be scrollable_vertically"

            for role in roles_dict.values():
                # временно, пока есть несоответствие со списком ролей в вкладке Сессии
                if role == "Пользователь":
                    continue
                roles_list.check_item_with_text(role)
            self.page.keyboard.press("Escape")
        elif name in no_op_names:
            continue
        else:
            print(f"check item: {name}")
            item.check_visibility(
                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("search")
    self.check_button_visibility("add")
    self.check_button_visibility("close")

    search_button = self.get_button_by_name("search")
    search_button.click()

    # Проверка что поле "Пользователи AD" появилось после поиска
    user_AD_loc = input_form_locator.get_by_role("combobox").nth(1)
    user_AD_input = TextInput(self.page, user_AD_loc, "user_AD_input")
    self.add_content_item("user_AD_input", user_AD_input)
    self.add_content_item(
        "user_AD_list",
        DropdownList(self.page)
    )

    user_AD_input.click()
    user_AD_list = self.get_content_item("user_AD_list")
    user_AD_list.check_visibility(menu_locator,
                              "Users AD list is missing")
    is_scrollable_vertically = user_AD_list.check_vertical_scrolling(menu_locator)
    assert is_scrollable_vertically, "Users AD list should be scrollable_vertically"
    self.page.keyboard.press("Escape")

    self.update_input_form_fields(expand=True)

    self.get_content_item("name_input").check_visibility(
                                       "Modal window content item with name 'name_input' is missing")
    self.get_content_item("role_input").check_visibility(
                                       "Modal window content item with name 'role_input' is missing")
    self.get_content_item("commentary_input").check_visibility(
                                       "Modal window content item with name 'commentary_input' is missing")
    self.get_content_item("email_input").check_visibility(
                                       "Modal window content item with name 'email_input' is missing")
    self.get_content_item("phone_input").check_visibility(
                                       "Modal window content item with name 'phone_input' is missing")

check_push_notification_checkbox()

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

Source code in components_derived\modal_add_AD_user.py
171
172
173
174
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_add_AD_user.py
340
341
342
343
344
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_add_AD_user.py
346
347
348
349
def close_window_by_toolbar_button(self):
    """Закрывает модальное окно через кнопку в тулбаре."""

    self.click_toolbar_close_button()

new_user(user_data)

Заполняет форму и добавляет нового пользователя.

Parameters:

Name Type Description Default
user_data dict

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

required
Source code in components_derived\modal_add_AD_user.py
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
def new_user(self, user_data):
    """Заполняет форму и добавляет нового пользователя.

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

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

    # Поле "Группа" - выбор из списка
    group_name = user_data.get("group")
    if group_name is None:
        assert False, "Value of 'group' is missing"

    # Поле "Пользователи AD" - выбор из списка
    name_AD = user_data.get("name_AD")
    if name_AD is None:
        assert False, "Value of 'name_AD' is missing"

    # Поле "Имя" - если определено (не None) вводим вручную
    name = user_data.get("name")

    # Поле "Роль" - выбор из списка
    role = user_data.get("role")
    if role is None:
        assert False, "Value of 'role' is missing"

    # Поиск и выбор заданной группы из списка существующих
    group_field = self.get_content_item("group_input")
    group_field.click()

    group_list = self.get_content_item("group_list")
    group_list.scroll_until_end(menu_locator)
    group_names = group_list.get_item_names(menu_locator)
    if group_name not in group_names:
        assert False, f"Required group name {group_name} is missing"

    group_list.check_item_with_text(group_name)
    group_list.click_item_with_text(group_name)

    # Нажатие кнопки "Поиск"
    search_button = self.get_button_by_name("search")
    search_button.click()

    count = input_form_locator.get_by_role("combobox").count()
    if count == 2:
        assert False, f"Selected group {group_name} is empty. Use another group."

    # Если в группе есть пользователи, открывается новое поле, персчет локаторов
    self.update_input_form_fields(expand=True)

    # Поиск и выбор заданного пользователя AD из списка существующих
    user_AD_loc = input_form_locator.get_by_role("combobox").nth(1)
    user_AD_input = TextInput(self.page, user_AD_loc, "user_AD_input")
    self.add_content_item("user_AD_input", user_AD_input)
    self.add_content_item(
        "user_AD_list",
        DropdownList(self.page)
    )

    user_AD_input.click()
    user_AD_list = self.get_content_item("user_AD_list")
    user_AD_list.scroll_until_end(menu_locator)
    user_AD_names = group_list.get_item_names(menu_locator)
    if name_AD not in user_AD_names:
        assert False, f"Required user name {name_AD} is missing"

    user_AD_list.check_item_with_text(name_AD)
    user_AD_list.click_item_with_text(name_AD)

    # Заполнение поля "Имя" (ручной ввод) если задано
    if name:
        name_field = self.get_content_item("name_input")
        name_field.input_value(name)

    # Поиск и выбор заданной роли из списка существующих
    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 user_data.get("commentary"):
        input_field = self.get_content_item("commentary_input")
        input_field.input_value(user_data["commentary"])

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

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

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

    if user_data.get("push_notification_checked"):
        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()

    # Подтверждение действия
    title = "Добавить нового пользователя"
    self.new_user_confirm.check_title(
        title,
        f"Confirmation dialog window with title '{title}' is missing"
    )
    self.new_user_confirm.click_allow_button()

uncheck_active_directory_checkbox()

Выключает чек-бокс Active Directory.

Source code in components_derived\modal_add_AD_user.py
156
157
158
159
def uncheck_active_directory_checkbox(self):
    """Выключает чек-бокс Active Directory. """

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

uncheck_blocking_checkbox()

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

Source code in components_derived\modal_add_AD_user.py
166
167
168
169
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_add_AD_user.py
176
177
178
179
def uncheck_push_notification_checkbox(self):
    """Выключает чек-бокс Push-уведомления."""

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

update_input_form_fields(expand)

Персчитывает локаторы полей формы ввода при добавлении/удалении дополнительного поля.

Source code in components_derived\modal_add_AD_user.py
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
def update_input_form_fields(self, expand):
    """Персчитывает локаторы полей формы ввода при добавлении/удалении дополнительного поля. """

    input_form_locator = self.page.locator(ModalWindowLocators.INPUT_FORM_USER_DATA)
    text_field_locator = ModalWindowLocators.TEXT_FIELD_INPUT_FORM_USER_DATA

    if expand:
        new_loc = input_form_locator.locator("xpath=div[4]").locator(text_field_locator)
        self.get_content_item("name_input").update_locator(new_loc)

        new_loc = input_form_locator.locator("xpath=div[8]").locator(text_field_locator)
        self.get_content_item("commentary_input").update_locator(new_loc)

        new_loc = input_form_locator.locator("xpath=div[9]").locator(text_field_locator)
        self.get_content_item("email_input").update_locator(new_loc)

        new_loc = input_form_locator.locator("xpath=div[10]").locator(text_field_locator)
        self.get_content_item("phone_input").update_locator(new_loc)

        role_loc = input_form_locator.get_by_role("combobox").nth(2)
        self.get_content_item("role_input").update_locator(role_loc)
    else:
        new_loc = input_form_locator.locator("xpath=div[3]").locator(text_field_locator)
        self.get_content_item("name_input").update_locator(new_loc)

        new_loc = input_form_locator.locator("xpath=div[7]").locator(text_field_locator)
        self.get_content_item("commentary_input").update_locator(new_loc)

        new_loc = input_form_locator.locator("xpath=div[8]").locator(text_field_locator)
        self.get_content_item("email_input").update_locator(new_loc)

        new_loc = input_form_locator.locator("xpath=div[9]").locator(text_field_locator)
        self.get_content_item("phone_input").update_locator(new_loc)

        role_loc = input_form_locator.get_by_role("combobox").nth(1)
        self.get_content_item("role_input").update_locator(role_loc)