jiawei.chen 6f6053ff51 feat: TestAgent 智能测试平台 v1.0
- 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 合规
2026-07-08 11:27:38 +08:00

78 lines
2.1 KiB
Python

"""元素定位 Mixin"""
from playwright.sync_api import Locator
class LocatorMixin:
"""元素定位相关操作
提供多种语义化的元素定位方法,优先使用 Playwright 的智能定位器。
"""
def find(self, selector: str) -> Locator:
"""查找单个元素
Args:
selector: CSS 选择器或 XPath
Returns:
Locator: Playwright Locator 对象
"""
return self.page.locator(selector)
def find_by_text(self, text: str, exact: bool = False) -> Locator:
"""按文本内容查找元素
Args:
text: 要查找的文本
exact: 是否精确匹配
Returns:
Locator: Playwright Locator 对象
"""
return self.page.get_by_text(text, exact=exact)
def find_by_role(self, role: str, **kwargs) -> Locator:
"""按 ARIA role 查找元素
Args:
role: ARIA role (button, link, textbox 等)
**kwargs: 额外参数 (name, exact 等)
Returns:
Locator: Playwright Locator 对象
"""
return self.page.get_by_role(role, **kwargs)
def find_by_placeholder(self, placeholder: str) -> Locator:
"""按 placeholder 查找输入框
Args:
placeholder: placeholder 文本
Returns:
Locator: Playwright Locator 对象
"""
return self.page.get_by_placeholder(placeholder)
def find_by_label(self, label: str) -> Locator:
"""按 label 查找元素
Args:
label: label 文本
Returns:
Locator: Playwright Locator 对象
"""
return self.page.get_by_label(label)
def find_by_testid(self, test_id: str) -> Locator:
"""按 data-testid 查找
Args:
test_id: data-testid 属性值
Returns:
Locator: Playwright Locator 对象
"""
return self.page.get_by_test_id(test_id)