优化UI测试逻辑,移除用户数据参数,支持浏览器会话复用

This commit is contained in:
longpeng 2025-06-30 00:07:22 +08:00
parent b7263f1814
commit a0cb6f8760
3 changed files with 6 additions and 16 deletions

View File

@ -135,7 +135,7 @@ class TestActivities:
# 调用实际的UI测试逻辑执行浏览器自动化测试并返回本地文件路径
ui_test_success, log_output, screenshot_path, html_report_path = await execute_ui_test_case(
req.test_case_id, req.url_path, req.browser_type, req.headless, scalar_map_to_dict(req.user_data)
req.test_case_id, req.url_path, req.browser_type, req.headless
)
# 填充基本测试结果

View File

@ -9,7 +9,7 @@ from typing import Optional
_browser_sessions = {}
_playwright_instance = None
async def execute_ui_test_case(test_case_id: str, url_path: str, browser_type: str, headless: bool, user_data: dict, browser_session_id: Optional[str] = None):
async def execute_ui_test_case(test_case_id: str, url_path: str, browser_type: str, headless: bool, browser_session_id: Optional[str] = None):
"""
实际执行UI测试的函数
支持浏览器会话复用
@ -54,15 +54,6 @@ async def execute_ui_test_case(test_case_id: str, url_path: str, browser_type: s
page = await browser.new_page()
# 模拟登录(如果需要)
if user_data:
log_output.append(f"Attempting to log in with user: {user_data.get('user')}")
await page.goto(f"{base_url}/login")
await page.fill('input[name="username"]', user_data.get('user', ''))
await page.fill('input[name="password"]', user_data.get('pass', ''))
await page.click('button[type="submit"]')
await page.wait_for_url(full_url)
await page.goto(full_url)
log_output.append(f"Navigated to: {full_url}")

View File

@ -82,11 +82,10 @@ func TestRunWorkflow(ctx workflow.Context, input *pb.TestRunInput) (*pb.TestRunO
// 构造 UI 测试的请求参数
// 包含浏览器配置和测试页面信息
uiTestInput := &pb.UiTestRequest{
TestCaseId: "ui-example-1", // UI 测试用例标识
UrlPath: "/dashboard", // 要测试的页面路径
BrowserType: "chromium", // 使用的浏览器类型
Headless: true, // 是否使用无头模式运行浏览器
UserData: map[string]string{"user": "test", "pass": "password"}, // 测试用的用户数据
TestCaseId: "ui-example-1", // UI 测试用例标识
UrlPath: "/dashboard", // 要测试的页面路径
BrowserType: "chromium", // 使用的浏览器类型
Headless: true, // 是否使用无头模式运行浏览器
}
// 声明变量用于接收 UI 测试的结果