08ea5fbe98
添加用户管理视图、API和状态管理文件
149 lines
5.3 KiB
Python
149 lines
5.3 KiB
Python
"""
|
|
菜单管理页面
|
|
|
|
Admin后台菜单管理页面的页面对象模型。
|
|
"""
|
|
|
|
from playwright.sync_api import Page
|
|
from ..base_page import BasePage
|
|
|
|
|
|
class MenuManagementPage(BasePage):
|
|
"""菜单管理页面"""
|
|
|
|
# 页面路径
|
|
PATH = "/system/menu"
|
|
|
|
# 元素定位器
|
|
LOCATORS = {
|
|
"page_title": ".page-title, h1",
|
|
"create_button": ".el-button--primary, .el-button:has-text('新增')",
|
|
"menu_tree": ".el-tree, .tree-container",
|
|
"tree_nodes": ".el-tree-node, .tree-node",
|
|
"dialog": ".el-dialog",
|
|
"dialog_title": ".el-dialog__title",
|
|
"form_name": 'input[name="name"], input[placeholder*="名称"]',
|
|
"form_path": 'input[name="path"], input[placeholder*="路径"]',
|
|
"form_component": 'input[name="component"], input[placeholder*="组件"]',
|
|
"form_icon": 'input[name="icon"], input[placeholder*="图标"]',
|
|
"form_sort": 'input[name="sort"], input[placeholder*="排序"]',
|
|
"form_type": '.el-radio-group',
|
|
"form_parent": '.el-select',
|
|
"form_submit": '.el-dialog__footer .el-button--primary',
|
|
"form_cancel": '.el-dialog__footer .el-button--default',
|
|
"delete_confirm": ".el-message-box__btns .el-button--primary",
|
|
"success_message": ".el-message--success",
|
|
"error_message": ".el-message--error",
|
|
}
|
|
|
|
def __init__(self, page: Page, base_url: str = ""):
|
|
super().__init__(page, base_url)
|
|
|
|
def navigate(self, path: str = "") -> None:
|
|
"""导航到菜单管理页面"""
|
|
target_path = path if path else self.PATH
|
|
self.page.goto(f"{self.base_url}{target_path}")
|
|
self.wait_for_load()
|
|
|
|
def is_loaded(self) -> bool:
|
|
"""检查页面是否加载完成"""
|
|
return self.is_element_visible(self.LOCATORS["menu_tree"])
|
|
|
|
def click_create_button(self) -> None:
|
|
"""点击新建按钮"""
|
|
self.click_element(self.LOCATORS["create_button"])
|
|
|
|
def expand_tree_node(self, node_name: str) -> None:
|
|
"""展开树节点"""
|
|
node = self.page.locator(self.LOCATORS["menu_tree"]).locator(
|
|
".el-tree-node__label"
|
|
).filter(has_text=node_name).locator("..").locator("..").locator(
|
|
".el-tree-node__expand-icon"
|
|
).first
|
|
node.click()
|
|
|
|
def click_node_edit(self, node_name: str) -> None:
|
|
"""点击节点编辑"""
|
|
node = self.page.locator(self.LOCATORS["menu_tree"]).locator(
|
|
".el-tree-node__label"
|
|
).filter(has_text=node_name).locator("..").locator("..")
|
|
edit_btn = node.locator(".el-button--primary").first
|
|
edit_btn.click()
|
|
|
|
def click_node_delete(self, node_name: str) -> None:
|
|
"""点击节点删除"""
|
|
node = self.page.locator(self.LOCATORS["menu_tree"]).locator(
|
|
".el-tree-node__label"
|
|
).filter(has_text=node_name).locator("..").locator("..")
|
|
delete_btn = node.locator(".el-button--danger").first
|
|
delete_btn.click()
|
|
|
|
def confirm_delete(self) -> None:
|
|
"""确认删除"""
|
|
self.click_element(self.LOCATORS["delete_confirm"])
|
|
|
|
def fill_form_name(self, name: str) -> None:
|
|
"""填写表单菜单名称"""
|
|
self.fill_input(self.LOCATORS["form_name"], name)
|
|
|
|
def fill_form_path(self, path: str) -> None:
|
|
"""填写表单菜单路径"""
|
|
self.fill_input(self.LOCATORS["form_path"], path)
|
|
|
|
def fill_form_component(self, component: str) -> None:
|
|
"""填写表单组件"""
|
|
self.fill_input(self.LOCATORS["form_component"], component)
|
|
|
|
def fill_form_icon(self, icon: str) -> None:
|
|
"""填写表单图标"""
|
|
self.fill_input(self.LOCATORS["form_icon"], icon)
|
|
|
|
def fill_form_sort(self, sort: int) -> None:
|
|
"""填写表单排序"""
|
|
self.fill_input(self.LOCATORS["form_sort"], str(sort))
|
|
|
|
def select_form_type(self, menu_type: str) -> None:
|
|
"""选择表单菜单类型"""
|
|
self.page.locator(self.LOCATORS["form_type"]).locator(
|
|
".el-radio"
|
|
).filter(has_text=menu_type).click()
|
|
|
|
def select_form_parent(self, parent_name: str) -> None:
|
|
"""选择表单父级菜单"""
|
|
self.click_element(self.LOCATORS["form_parent"])
|
|
self.page.locator(".el-select-dropdown__item").filter(
|
|
has_text=parent_name
|
|
).click()
|
|
|
|
def click_form_submit(self) -> None:
|
|
"""点击表单提交按钮"""
|
|
self.click_element(self.LOCATORS["form_submit"])
|
|
|
|
def click_form_cancel(self) -> None:
|
|
"""点击表单取消按钮"""
|
|
self.click_element(self.LOCATORS["form_cancel"])
|
|
|
|
def is_dialog_visible(self) -> bool:
|
|
"""检查对话框是否可见"""
|
|
return self.is_element_visible(self.LOCATORS["dialog"])
|
|
|
|
def get_dialog_title(self) -> str:
|
|
"""获取对话框标题"""
|
|
return self.get_text(self.LOCATORS["dialog_title"])
|
|
|
|
def has_success_message(self) -> bool:
|
|
"""检查是否有成功消息"""
|
|
return self.is_element_visible(
|
|
self.LOCATORS["success_message"], timeout=3000
|
|
)
|
|
|
|
def has_error_message(self) -> bool:
|
|
"""检查是否有错误消息"""
|
|
return self.is_element_visible(
|
|
self.LOCATORS["error_message"], timeout=3000
|
|
)
|
|
|
|
def get_tree_nodes_count(self) -> int:
|
|
"""获取树节点数量"""
|
|
return self.get_elements_count(self.LOCATORS["tree_nodes"])
|