feat: добавление метода is_item_visible в навигационную панель
- Добавлен метод для проверки видимости элемента без исключений - Возвращает boolean значение для условных проверокradislav/tests_rack
parent
d555a2c6b0
commit
7ee92ef6a5
|
|
@ -21,20 +21,6 @@ class NavigationPanelComponent(BaseComponent):
|
|||
super().__init__(page)
|
||||
|
||||
# Действия:
|
||||
def get_item_names(self, locator: str | Locator) -> list[str]:
|
||||
"""Возвращает тексты всех элементов по указанному локатору.
|
||||
|
||||
Args:
|
||||
locator: Локатор элементов или строка с CSS/XPath.
|
||||
|
||||
Returns:
|
||||
Список текстов элементов.
|
||||
"""
|
||||
|
||||
loc = self.get_locator(locator)
|
||||
return loc.all_inner_texts()
|
||||
|
||||
|
||||
def click_item(self, locator: str | Locator, item_name: str) -> None:
|
||||
"""Кликает по элементу с указанным текстом.
|
||||
|
||||
|
|
@ -50,13 +36,12 @@ class NavigationPanelComponent(BaseComponent):
|
|||
"""Кликает по вложенному элементу с указанным текстом.
|
||||
|
||||
Args:
|
||||
node_root_locator: Локатор для поиска корневых элементов дерева (Локатор элемента или строка с CSS/XPath).
|
||||
node_root_locator: Локатор для поиска корневых элементов дерева.
|
||||
item_name: Текст элемента для клика.
|
||||
"""
|
||||
|
||||
def find_and_click_item(page, root_locator, item_name: str, parent: None|str) -> Locator|None:
|
||||
# Находим все локаторы корневых узлов на текущем уровне
|
||||
#root_node = root_locator.locator('>div.v-treeview-node')
|
||||
nodes_count = root_locator.locator('>div.v-treeview-node').count()
|
||||
|
||||
# Если искомый элемент находится на данном уровне, вычисляем локатор и делаем клик
|
||||
|
|
@ -69,9 +54,9 @@ class NavigationPanelComponent(BaseComponent):
|
|||
if item_name == node_text:
|
||||
node_attr = node.get_attribute('class')
|
||||
if "v-treeview-node--leaf" not in node_attr:
|
||||
toggle_button = node.\
|
||||
locator(NavigationPanelLocators.NODE_ROOT). \
|
||||
locator(NavigationPanelLocators.TOGGLE_BUTTON).first
|
||||
toggle_button = node.locator(
|
||||
NavigationPanelLocators.NODE_ROOT
|
||||
).locator(NavigationPanelLocators.TOGGLE_BUTTON).first
|
||||
toogle_class_attr = toggle_button.get_attribute('class')
|
||||
if "v-treeview-node__toggle--open" not in toogle_class_attr:
|
||||
toggle_button.click()
|
||||
|
|
@ -93,17 +78,17 @@ class NavigationPanelComponent(BaseComponent):
|
|||
# Проверяем лист это или начало поддерева
|
||||
if "v-treeview-node--leaf" not in node_class_attr:
|
||||
# Проверяем, является ли узел раскрытым
|
||||
class_attr = node.\
|
||||
locator(NavigationPanelLocators.NODE_ROOT). \
|
||||
locator(NavigationPanelLocators.TOGGLE_BUTTON).first.get_attribute('class')
|
||||
class_attr = node.locator(
|
||||
NavigationPanelLocators.NODE_ROOT
|
||||
).locator(NavigationPanelLocators.TOGGLE_BUTTON).first.get_attribute('class')
|
||||
if "v-treeview-node__toggle--open" in class_attr:
|
||||
is_expanded = True
|
||||
|
||||
# Если узел закрыт можем его раскрыть
|
||||
if is_expanded is False:
|
||||
toggle_button = node.\
|
||||
locator(NavigationPanelLocators.NODE_ROOT). \
|
||||
locator(NavigationPanelLocators.TOGGLE_BUTTON).first
|
||||
toggle_button = node.locator(
|
||||
NavigationPanelLocators.NODE_ROOT
|
||||
).locator(NavigationPanelLocators.TOGGLE_BUTTON).first
|
||||
toggle_button.click()
|
||||
# Ждем, пока дочерние элементы прогрузятся/появятся
|
||||
page.wait_for_timeout(1000)
|
||||
|
|
@ -118,21 +103,27 @@ class NavigationPanelComponent(BaseComponent):
|
|||
# Рекурсивный вызов для дочерних элементов
|
||||
# Ищем дочерние элементы *внутри* текущего узла
|
||||
if has_children and is_expanded:
|
||||
child_nodes_locator = root_locator.locator(f">div:nth-child({index + 1})").locator('>div.v-treeview-node__children')
|
||||
found_loc = find_and_click_item(page, child_nodes_locator, item_name, parent=None)
|
||||
child_nodes_locator = root_locator.locator(
|
||||
f">div:nth-child({index + 1})"
|
||||
).locator('>div.v-treeview-node__children')
|
||||
found_loc = find_and_click_item(
|
||||
page, child_nodes_locator, item_name, parent=None
|
||||
)
|
||||
if found_loc:
|
||||
if parent is None:
|
||||
return found_loc
|
||||
else:
|
||||
root_texts = root_locator.locator(f">div:nth-child({index + 1})").inner_text().splitlines()
|
||||
root_texts = root_locator.locator(
|
||||
f">div:nth-child({index + 1})"
|
||||
).inner_text().splitlines()
|
||||
if parent in root_texts:
|
||||
return found_loc
|
||||
|
||||
# закрываем узел, если в нем ничего не нашли
|
||||
if is_expanded:
|
||||
toggle_button = node.\
|
||||
locator(NavigationPanelLocators.NODE_ROOT). \
|
||||
locator(NavigationPanelLocators.TOGGLE_BUTTON).first
|
||||
toggle_button = node.locator(
|
||||
NavigationPanelLocators.NODE_ROOT
|
||||
).locator(NavigationPanelLocators.TOGGLE_BUTTON).first
|
||||
toggle_button.click()
|
||||
page.wait_for_timeout(1000)
|
||||
|
||||
|
|
@ -142,17 +133,33 @@ class NavigationPanelComponent(BaseComponent):
|
|||
root_locator = self.get_locator(node_root_locator)
|
||||
if parent:
|
||||
parent_loc = find_and_click_item(self.page, root_locator, parent, parent=None)
|
||||
found = find_and_click_item(self.page, parent_loc.locator('>div.v-treeview-node__children'), item_name, parent=None)
|
||||
found = find_and_click_item(
|
||||
self.page, parent_loc.locator('>div.v-treeview-node__children'),
|
||||
item_name, parent=None
|
||||
)
|
||||
else:
|
||||
found = find_and_click_item(self.page, root_locator, item_name, parent=None)
|
||||
assert found, f"Navigation panel item {item_name} is missing"
|
||||
|
||||
def traverse_panel_tree(self, node_root_locator: str | Locator, level=0, debug=False):
|
||||
"""
|
||||
Рекурсивно обходит дерево v-treeview и выводит информацию об элементах в режиме отладки (debug=True).
|
||||
def get_item_names(self, locator: str | Locator) -> list[str]:
|
||||
"""Возвращает тексты всех элементов по указанному локатору.
|
||||
|
||||
Args:
|
||||
node_root_locator: Локатор для поиска корневых элементов дерева (Локатор элемента или строка с CSS/XPath).
|
||||
locator: Локатор элементов или строка с CSS/XPath.
|
||||
|
||||
Returns:
|
||||
Список текстов элементов.
|
||||
"""
|
||||
|
||||
loc = self.get_locator(locator)
|
||||
return loc.all_inner_texts()
|
||||
|
||||
def traverse_panel_tree(self, node_root_locator: str | Locator, level=0, debug=False):
|
||||
"""
|
||||
Рекурсивно обходит дерево v-treeview и выводит информацию об элементах.
|
||||
|
||||
Args:
|
||||
node_root_locator: Локатор для поиска корневых элементов дерева.
|
||||
"""
|
||||
def traverse_tree(page, root_locator, level=0, debug=False):
|
||||
# Находим все локаторы корневых узлов на текущем уровне
|
||||
|
|
@ -204,7 +211,9 @@ class NavigationPanelComponent(BaseComponent):
|
|||
# Рекурсивный вызов для дочерних элементов
|
||||
# Ищем дочерние элементы *внутри* текущего узла
|
||||
if has_children and is_expanded:
|
||||
child_nodes_locator = root_locator.locator(f">div:nth-child({index + 1})").locator('>div.v-treeview-node__children')
|
||||
child_nodes_locator = root_locator.locator(
|
||||
f">div:nth-child({index + 1})"
|
||||
).locator('>div.v-treeview-node__children')
|
||||
traverse_tree(page, child_nodes_locator, level+1, debug)
|
||||
|
||||
root_locator = self.get_locator(node_root_locator)
|
||||
|
|
@ -253,4 +262,4 @@ class NavigationPanelComponent(BaseComponent):
|
|||
if element_locator.count() == 0:
|
||||
return False
|
||||
|
||||
return element_locator.is_visible()
|
||||
return element_locator.is_visible()
|
||||
|
|
|
|||
Loading…
Reference in New Issue