优化UI测试逻辑,移除用户数据参数,支持浏览器会话复用
This commit is contained in:
parent
b7263f1814
commit
a0cb6f8760
@ -135,7 +135,7 @@ class TestActivities:
|
|||||||
|
|
||||||
# 调用实际的UI测试逻辑,执行浏览器自动化测试并返回本地文件路径
|
# 调用实际的UI测试逻辑,执行浏览器自动化测试并返回本地文件路径
|
||||||
ui_test_success, log_output, screenshot_path, html_report_path = await execute_ui_test_case(
|
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
|
||||||
)
|
)
|
||||||
|
|
||||||
# 填充基本测试结果
|
# 填充基本测试结果
|
||||||
|
@ -9,7 +9,7 @@ from typing import Optional
|
|||||||
_browser_sessions = {}
|
_browser_sessions = {}
|
||||||
_playwright_instance = None
|
_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测试的函数。
|
实际执行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()
|
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)
|
await page.goto(full_url)
|
||||||
log_output.append(f"Navigated to: {full_url}")
|
log_output.append(f"Navigated to: {full_url}")
|
||||||
|
|
||||||
|
@ -86,7 +86,6 @@ func TestRunWorkflow(ctx workflow.Context, input *pb.TestRunInput) (*pb.TestRunO
|
|||||||
UrlPath: "/dashboard", // 要测试的页面路径
|
UrlPath: "/dashboard", // 要测试的页面路径
|
||||||
BrowserType: "chromium", // 使用的浏览器类型
|
BrowserType: "chromium", // 使用的浏览器类型
|
||||||
Headless: true, // 是否使用无头模式运行浏览器
|
Headless: true, // 是否使用无头模式运行浏览器
|
||||||
UserData: map[string]string{"user": "test", "pass": "password"}, // 测试用的用户数据
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 声明变量用于接收 UI 测试的结果
|
// 声明变量用于接收 UI 测试的结果
|
||||||
|
Loading…
Reference in New Issue
Block a user