- CLI + Web 双平台,基于 LLM 的 TDD+DDD 自动化测试生成 - 集成 unified-test-platform 903 个 D-Cloud 用例 + 13 个 Robogo 场景 - Agent 5 步流水线: 扫描 -> DDD -> LLM 生成测试 - 精确回归 + UI 变更检查 - 可视化 HTML 测试报告 - 暗色/亮色主题切换 - 19 个 API 端点 + 6 个 SPA 页面 - 15/15 项 TDD+DDD 合规
217 lines
7.3 KiB
Python
217 lines
7.3 KiB
Python
"""云桌面页面对象模型"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from playwright.sync_api import Page, Locator
|
|
from tests.base.base_page import BasePage
|
|
|
|
|
|
class CloudDesktopPage(BasePage):
|
|
"""云桌面页面 - /d-cloud/cloud-desktop/list
|
|
|
|
功能:
|
|
- 下载客户端
|
|
- 创建云桌面
|
|
- 管理桌面实例 (启动/停止/删除)
|
|
- SSH连接
|
|
"""
|
|
|
|
URL_PATH = "/d-cloud/cloud-desktop/list"
|
|
|
|
def __init__(self, page: Page):
|
|
super().__init__(page)
|
|
self.path = self.URL_PATH
|
|
|
|
# 顶部操作按钮
|
|
self.download_client_button = page.get_by_role("button", name="下载客户端")
|
|
self.create_desktop_button = page.get_by_role("button", name="创建桌面")
|
|
self.search_input = page.locator("input[placeholder*='搜索']")
|
|
self.reload_button = page.locator("img[cursor=pointer]").first
|
|
|
|
# 表格
|
|
self.table = page.locator(".ant-table")
|
|
self.table_headers = page.locator(".ant-table-thead th")
|
|
self.table_rows = page.locator(".ant-table-tbody tr")
|
|
self.no_data = page.locator(".ant-empty-description")
|
|
|
|
def navigate(self, url: str | None = None) -> None:
|
|
target_url = url if url else f"{self.base_url}{self.path}"
|
|
self.page.goto(target_url, wait_until="domcontentloaded", timeout=30000)
|
|
try:
|
|
self.page.wait_for_load_state("networkidle", timeout=10000)
|
|
except Exception:
|
|
pass
|
|
|
|
def is_download_client_button_visible(self) -> bool:
|
|
"""检查下载客户端按钮是否可见"""
|
|
return self.download_client_button.is_visible()
|
|
|
|
def is_create_desktop_button_visible(self) -> bool:
|
|
"""检查创建桌面按钮是否可见"""
|
|
return self.create_desktop_button.is_visible()
|
|
|
|
def click_create_desktop(self) -> None:
|
|
"""点击创建桌面按钮"""
|
|
self.create_desktop_button.click()
|
|
|
|
def click_download_client(self) -> None:
|
|
"""点击下载客户端按钮"""
|
|
self.download_client_button.click()
|
|
|
|
def get_table_headers(self) -> list[str]:
|
|
"""获取表格表头"""
|
|
headers = self.table_headers.all_text_contents()
|
|
return [h.strip() for h in headers if h.strip()]
|
|
|
|
def has_data(self) -> bool:
|
|
"""检查表格是否有数据"""
|
|
return not self.no_data.is_visible()
|
|
|
|
def search_desktop(self, keyword: str) -> None:
|
|
"""搜索桌面"""
|
|
if self.search_input.count() > 0 and self.search_input.is_visible():
|
|
self.search_input.fill(keyword)
|
|
self.page.keyboard.press("Enter")
|
|
|
|
def click_reload(self) -> None:
|
|
"""点击刷新按钮"""
|
|
self.reload_button.click()
|
|
|
|
def is_dialog_visible(self) -> bool:
|
|
"""检查对话框是否可见"""
|
|
dialog = self.page.locator(".ant-modal:visible")
|
|
return dialog.is_visible()
|
|
|
|
|
|
class CreateDesktopDialog:
|
|
"""创建云桌面对话框
|
|
|
|
字段:
|
|
- 桌面名称 (必填, 最多64字符, 字母/中文开头)
|
|
- 资源规格 (必选)
|
|
- 镜像 (必选, 可选镜像列表)
|
|
- 系统盘(GB) (默认500, 禁用)
|
|
- 数据盘 (可选路径)
|
|
- 自动关机 (必选, 默认"不自动关机")
|
|
- 计费方式 (必选, 按量计费/连续包月)
|
|
|
|
按钮:
|
|
- 取消
|
|
- 创建并开机
|
|
"""
|
|
|
|
def __init__(self, page: Page):
|
|
self.page = page
|
|
self.dialog = page.locator(".ant-modal:has-text('创建云桌面')")
|
|
|
|
# 表单字段
|
|
self.name_input = page.get_by_role("textbox", name="请输入桌面名称")
|
|
self.spec_select = page.locator(".ant-select:has-text('请选择规格')")
|
|
self.image_select = page.locator(".ant-select:has-text('请选择镜像')")
|
|
self.system_disk_input = page.locator("input[value='500']")
|
|
self.data_disk_input = page.get_by_role("textbox", name="请选择路径")
|
|
self.auto_shutdown_select = page.locator(".ant-select:has-text('不自动关机')")
|
|
self.billing_type_yearly = page.locator("label:has-text('连续包月')")
|
|
self.billing_type_on_demand = page.locator("label:has-text('按量计费')")
|
|
|
|
# 按钮
|
|
self.cancel_button = page.get_by_role("button", name="取 消")
|
|
self.create_button = page.get_by_role("button", name="创建并开机")
|
|
|
|
def is_visible(self) -> bool:
|
|
"""检查对话框是否可见"""
|
|
return self.dialog.is_visible()
|
|
|
|
def fill_name(self, name: str) -> None:
|
|
"""填写桌面名称"""
|
|
if self.name_input.count() > 0 and self.name_input.is_visible():
|
|
self.name_input.fill(name)
|
|
|
|
def select_image(self, image_name: str) -> None:
|
|
"""选择镜像"""
|
|
self.image_select.click()
|
|
self.page.get_by_text(image_name, exact=True).click()
|
|
|
|
def select_billing_type(self, billing_type: str) -> None:
|
|
"""选择计费方式
|
|
|
|
Args:
|
|
billing_type: 'on_demand' 或 'yearly'
|
|
"""
|
|
if billing_type == "yearly":
|
|
self.billing_type_yearly.click()
|
|
else:
|
|
self.billing_type_on_demand.click()
|
|
|
|
def cancel(self) -> None:
|
|
"""取消对话框"""
|
|
self.cancel_button.click()
|
|
|
|
def create(self) -> None:
|
|
"""点击创建并开机"""
|
|
self.create_button.click()
|
|
|
|
def get_validation_error(self) -> str:
|
|
"""获取验证错误信息"""
|
|
error = self.page.locator(".ant-form-item-explain-error").first
|
|
if error.is_visible():
|
|
text = error.text_content()
|
|
return text if text else ""
|
|
return ""
|
|
|
|
def is_create_button_enabled(self) -> bool:
|
|
"""检查创建按钮是否可用"""
|
|
return self.create_button.is_enabled()
|
|
|
|
def get_available_images(self) -> list[str]:
|
|
"""获取可用镜像列表"""
|
|
self.image_select.click()
|
|
self.page.wait_for_load_state("domcontentloaded")
|
|
options = self.page.locator(
|
|
".ant-select-dropdown:visible .ant-select-item"
|
|
).all_text_contents()
|
|
return [o.strip() for o in options if o.strip()]
|
|
|
|
def get_available_specs(self) -> list[str]:
|
|
"""获取可用规格列表"""
|
|
self.spec_select.click()
|
|
self.page.wait_for_load_state("domcontentloaded")
|
|
options = self.page.locator(
|
|
".ant-select-dropdown:visible .ant-select-item"
|
|
).all_text_contents()
|
|
return [o.strip() for o in options if o.strip()]
|
|
|
|
def fill_complete_form(
|
|
self, name: str, image: str | None = None, billing: str = "on_demand"
|
|
) -> bool:
|
|
"""填写完整表单,返回是否成功"""
|
|
self.fill_name(name)
|
|
|
|
if image:
|
|
try:
|
|
self.select_image(image)
|
|
except Exception:
|
|
pass
|
|
|
|
self.select_billing_type(billing)
|
|
return self.is_create_button_enabled()
|
|
|
|
def create_desktop_full(self, name: str) -> bool:
|
|
"""完整创建桌面流程,返回是否成功"""
|
|
self.fill_name(name)
|
|
|
|
self.image_select.click()
|
|
self.page.wait_for_load_state("domcontentloaded")
|
|
first_image = self.page.locator(
|
|
".ant-select-dropdown:visible .ant-select-item"
|
|
).first
|
|
if first_image.is_visible():
|
|
first_image.click()
|
|
|
|
self.select_billing_type("on_demand")
|
|
|
|
if self.is_create_button_enabled():
|
|
self.create_button.click()
|
|
return True
|
|
return False
|