- 15个文件添加 from __future__ import annotations 修复 Python 3.9 管道语法 - DCloudDashboard 首页新增总览分组,E2E 全量测试入口卡片 - 同步更新 README/history/测试用例文档
109 lines
4.0 KiB
Python
109 lines
4.0 KiB
Python
"""监控看板页面对象"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from playwright.sync_api import Page, Locator
|
|
from tests.base.base_page import BasePage
|
|
|
|
|
|
class MonitorDashboardPage(BasePage):
|
|
"""监控看板页面 - 查看资源监控"""
|
|
|
|
URL_PATH = "/d-cloud/monitor-dashboard"
|
|
|
|
RADIO_YEARLY = "label:has-text('包年包月资源') input[type='radio']"
|
|
RADIO_ELASTIC = "label:has-text('弹性资源') input[type='radio']"
|
|
|
|
TIME_RANGE_SELECT = ".ant-select"
|
|
REFRESH_INTERVAL_SELECT = ".ant-select"
|
|
NO_DATA = ".ant-empty-description"
|
|
|
|
def __init__(self, page: Page):
|
|
super().__init__(page)
|
|
self.url = f"{self.base_url}{self.URL_PATH}"
|
|
|
|
def navigate(self, url: str | None = None) -> None:
|
|
target_url = url if url else self.url
|
|
self.page.goto(target_url)
|
|
self.page.wait_for_load_state("networkidle")
|
|
|
|
def is_yearly_resource_selected(self) -> bool:
|
|
return self.page.get_by_role("radio", name="包年包月资源").is_checked()
|
|
|
|
def is_elastic_resource_selected(self) -> bool:
|
|
return self.page.get_by_role("radio", name="弹性资源").is_checked()
|
|
|
|
def select_yearly_resource(self) -> None:
|
|
self.page.get_by_role("radio", name="包年包月资源").click()
|
|
|
|
def select_elastic_resource(self) -> None:
|
|
self.page.get_by_role("radio", name="弹性资源").click()
|
|
|
|
def has_data(self) -> bool:
|
|
return not self.page.locator(self.NO_DATA).is_visible()
|
|
|
|
def get_current_resource_type(self) -> str:
|
|
if self.is_yearly_resource_selected():
|
|
return "包年包月资源"
|
|
elif self.is_elastic_resource_selected():
|
|
return "弹性资源"
|
|
return "unknown"
|
|
|
|
def select_resource_type(self, resource_type: str) -> None:
|
|
"""选择资源类型"""
|
|
if resource_type in ["yearly", "包年包月资源"]:
|
|
self.select_yearly_resource()
|
|
else:
|
|
self.select_elastic_resource()
|
|
|
|
def change_time_range(self, time_range: str) -> None:
|
|
"""更改时间范围"""
|
|
time_select = self.page.locator(".ant-select").first
|
|
time_select.click()
|
|
self.page.get_by_role("option", name=time_range).click()
|
|
|
|
def change_refresh_interval(self, interval: str) -> None:
|
|
"""更改刷新间隔"""
|
|
interval_select = self.page.locator(".ant-select").nth(1)
|
|
interval_select.click()
|
|
self.page.get_by_role("option", name=interval, exact=True).click()
|
|
|
|
def is_resource_type_selected(self, resource_type: str) -> bool:
|
|
"""检查指定资源类型是否被选中"""
|
|
if resource_type in ["yearly", "包年包月资源"]:
|
|
return self.is_yearly_resource_selected()
|
|
else:
|
|
return self.is_elastic_resource_selected()
|
|
|
|
def is_time_range_selected(self, time_range: str) -> bool:
|
|
"""检查指定时间范围是否被选中"""
|
|
selected = self.page.locator(".ant-select-selection-item").first
|
|
if selected.is_visible():
|
|
text = selected.text_content()
|
|
return text is not None and time_range in text
|
|
return False
|
|
|
|
def is_refresh_interval_selected(self, interval: str) -> bool:
|
|
"""检查指定刷新间隔是否被选中"""
|
|
selected = self.page.locator(".ant-select-selection-item").nth(1)
|
|
if selected.is_visible():
|
|
text = selected.text_content()
|
|
return text is not None and interval in text
|
|
return False
|
|
|
|
def open_time_range_dropdown(self) -> None:
|
|
"""打开时间范围下拉框"""
|
|
self.page.locator(".ant-select").first.click()
|
|
|
|
def open_refresh_interval_dropdown(self) -> None:
|
|
"""打开刷新间隔下拉框"""
|
|
self.page.locator(".ant-select").nth(1).click()
|
|
|
|
def close_dropdown(self) -> None:
|
|
"""关闭当前打开的下拉框"""
|
|
self.page.keyboard.press("Escape")
|
|
|
|
def is_dropdown_open(self) -> bool:
|
|
"""检查 Ant Design 下拉框是否打开"""
|
|
return self.page.locator(".ant-select-dropdown:not(.ant-select-dropdown-hidden)").is_visible()
|