Compare commits
No commits in common. "2bdc364ca4779701b4428e99b8da81bf893a7076" and "a5c73285628801b61738a67c1ff310b100b2e723" have entirely different histories.
2bdc364ca4
...
a5c7328562
|
|
@ -17,7 +17,7 @@ class DropdownList(BaseComponent):
|
|||
методы для выбора и проверки элементов списка.
|
||||
"""
|
||||
|
||||
def __init__(self, page: Page) -> None:
|
||||
def __init__(self, page: Page):
|
||||
"""Инициализирует компонент выпадающего списка.
|
||||
|
||||
Args:
|
||||
|
|
@ -37,39 +37,9 @@ class DropdownList(BaseComponent):
|
|||
element = self.page.get_by_role("listitem").filter(has_text=text)
|
||||
if element.count() > 1:
|
||||
rtext = f"^{text}$"
|
||||
element = self.page.get_by_role("listitem").filter(
|
||||
has_text=re.compile(rtext)
|
||||
)
|
||||
element = self.page.get_by_role("listitem").filter(has_text=re.compile(rtext))
|
||||
element.click()
|
||||
|
||||
def get_combobox_options(self, combobox_locator: str | Locator,
|
||||
listbox_locator: str | Locator,
|
||||
icon_locator: str | Locator = None) -> list[str]:
|
||||
"""
|
||||
Получает список доступных опций из combobox.
|
||||
|
||||
Args:
|
||||
combobox_locator: Локатор combobox
|
||||
listbox_locator: Локатор выпадающего списка
|
||||
icon_locator: Локатор иконки для клика (опционально)
|
||||
|
||||
Returns:
|
||||
list[str]: Список доступных опций
|
||||
"""
|
||||
logger.info("Getting combobox options list...")
|
||||
|
||||
# Открываем combobox (если еще не открыт)
|
||||
self.open_combobox(combobox_locator, listbox_locator, icon_locator)
|
||||
|
||||
options_list = self.get_item_names(listbox_locator)
|
||||
|
||||
# Закрываем combobox (кликаем вне его)
|
||||
self.page.mouse.click(10, 10)
|
||||
self.page.wait_for_timeout(500)
|
||||
|
||||
logger.info(f"Found options: {len(options_list)} - {options_list}")
|
||||
return options_list
|
||||
|
||||
def get_item_names(self, locator: str | Locator) -> list[str]:
|
||||
"""Возвращает тексты всех элементов по указанному локатору.
|
||||
|
||||
|
|
@ -84,90 +54,6 @@ class DropdownList(BaseComponent):
|
|||
texts = loc.all_inner_texts()
|
||||
return texts[0].splitlines()
|
||||
|
||||
def get_selected_combobox_value(self, combobox_locator: str | Locator,
|
||||
value_locator: str | Locator = None) -> str:
|
||||
"""
|
||||
Получает выбранное значение из combobox.
|
||||
|
||||
Args:
|
||||
combobox_locator: Локатор combobox
|
||||
value_locator: Локатор элемента с выбранным значением (опционально)
|
||||
|
||||
Returns:
|
||||
str: Выбранное значение или пустая строка если ничего не выбрано
|
||||
"""
|
||||
combobox = self.get_locator(combobox_locator)
|
||||
|
||||
selected_value = ""
|
||||
|
||||
if value_locator:
|
||||
# Используем переданный локатор для значения
|
||||
value_element = combobox.locator(value_locator)
|
||||
if value_element.count() > 0:
|
||||
selected_value = value_element.first.text_content().strip()
|
||||
else:
|
||||
# Ищем в span элементах по умолчанию
|
||||
span_locator = combobox.locator("span")
|
||||
if span_locator.count() > 0:
|
||||
for i in range(span_locator.count()):
|
||||
span_text = span_locator.nth(i).text_content().strip()
|
||||
if span_text and span_text not in ["Класс объекта учета"]:
|
||||
selected_value = span_text
|
||||
break
|
||||
|
||||
logger.info(f"Selected combobox value: '{selected_value}'")
|
||||
return selected_value
|
||||
|
||||
def open_combobox(self, combobox_locator: str | Locator,
|
||||
listbox_locator: str | Locator,
|
||||
icon_locator: str | Locator = None) -> None:
|
||||
"""
|
||||
Открывает выпадающий список combobox.
|
||||
|
||||
Args:
|
||||
combobox_locator: Локатор combobox
|
||||
listbox_locator: Локатор выпадающего списка
|
||||
icon_locator: Локатор иконки для клика (опционально)
|
||||
"""
|
||||
logger.info("Opening combobox...")
|
||||
|
||||
combobox = self.get_locator(combobox_locator)
|
||||
listbox = self.get_locator(listbox_locator)
|
||||
|
||||
# Прокручиваем до combobox
|
||||
combobox.scroll_into_view_if_needed()
|
||||
self.page.wait_for_timeout(1000)
|
||||
|
||||
# Проверяем, не открыт ли уже список
|
||||
listbox_already_open = False
|
||||
listbox_count = listbox.count()
|
||||
|
||||
if listbox_count > 0:
|
||||
listbox_already_open = listbox.first.is_visible()
|
||||
|
||||
if not listbox_already_open:
|
||||
# Если указан локатор иконки, кликаем на него, иначе на сам combobox
|
||||
if icon_locator:
|
||||
icon = combobox.locator(icon_locator)
|
||||
icon.scroll_into_view_if_needed()
|
||||
icon.click(timeout=10000)
|
||||
else:
|
||||
combobox.click(timeout=10000)
|
||||
logger.info("Combobox click completed")
|
||||
self.page.wait_for_timeout(1000)
|
||||
|
||||
# Проверяем что список открылся
|
||||
listbox_count_after = listbox.count()
|
||||
listbox_visible = False
|
||||
|
||||
if listbox_count_after > 0:
|
||||
listbox_visible = listbox.first.is_visible()
|
||||
|
||||
if listbox_visible:
|
||||
logger.info("Dropdown list found and opened")
|
||||
else:
|
||||
logger.warning("Failed to open dropdown list")
|
||||
|
||||
def scroll_until_end(self, locator: str | Locator) -> None:
|
||||
"""
|
||||
Скроллит список до тех пор, пока не перестанут подгружаться новые элементы.
|
||||
|
|
@ -196,9 +82,7 @@ class DropdownList(BaseComponent):
|
|||
attempts = 0
|
||||
|
||||
last_item_name = item_names[current_count-1]
|
||||
element = self.page.get_by_role("listitem").filter(
|
||||
has_text=last_item_name
|
||||
)
|
||||
element = self.page.get_by_role("listitem").filter(has_text=last_item_name)
|
||||
element.scroll_into_view_if_needed()
|
||||
|
||||
self.page.wait_for_timeout(300)
|
||||
|
|
@ -214,13 +98,11 @@ class DropdownList(BaseComponent):
|
|||
Raises:
|
||||
AssertionError: Если элемент отсутствует или недоступен.
|
||||
"""
|
||||
|
||||
|
||||
element = self.page.get_by_role("listitem").filter(has_text=text)
|
||||
if element.count() > 1:
|
||||
rtext = f"^{text}$"
|
||||
element = self.page.get_by_role("listitem").filter(
|
||||
has_text=re.compile(rtext)
|
||||
)
|
||||
element = self.page.get_by_role("listitem").filter(has_text=re.compile(rtext))
|
||||
enabled = element.is_enabled()
|
||||
if not enabled:
|
||||
assert False, f"Dropdown list item '{text}' is missing or disabled"
|
||||
|
|
|
|||
Loading…
Reference in New Issue