chore: auto release commit (2026-09-14 15:11:41)
All checks were successful
技能自动化发布 / release (push) Successful in 9s
All checks were successful
技能自动化发布 / release (push) Successful in 9s
This commit is contained in:
93
test_rpa.py
Normal file
93
test_rpa.py
Normal file
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env python3
|
||||
"""测试RPA功能。"""
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 添加scripts目录到Python路径
|
||||
scripts_dir = os.path.join(os.path.dirname(__file__), "scripts")
|
||||
if scripts_dir not in sys.path:
|
||||
sys.path.insert(0, scripts_dir)
|
||||
|
||||
from service.rpa import run_invoice_rpa, close_browser_context
|
||||
from service.rpa.browser_session import start_browser_session
|
||||
|
||||
|
||||
async def test_basic_connection():
|
||||
"""测试基本连接。"""
|
||||
print("测试基本连接...")
|
||||
|
||||
# 注意:需要实际的profile_dir
|
||||
# 这里只是演示结构
|
||||
profile_dir = "test_profile_dir"
|
||||
username = "15527406659"
|
||||
password = "qwer1234"
|
||||
|
||||
try:
|
||||
# 启动浏览器
|
||||
pw, context, page = await start_browser_session(profile_dir, headless=False)
|
||||
print("浏览器启动成功")
|
||||
|
||||
# 关闭浏览器
|
||||
await close_browser_context(pw, context)
|
||||
print("浏览器关闭成功")
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"测试失败: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
async def test_invoice_extraction():
|
||||
"""测试发票提取。"""
|
||||
print("测试发票提取...")
|
||||
|
||||
# 注意:需要实际的profile_dir
|
||||
profile_dir = "test_profile_dir"
|
||||
username = "15527406659"
|
||||
password = "qwer1234"
|
||||
|
||||
try:
|
||||
result = await run_invoice_rpa(
|
||||
username=username,
|
||||
password=password,
|
||||
profile_dir=profile_dir,
|
||||
headless=False,
|
||||
detail_mode=False,
|
||||
)
|
||||
|
||||
if result.success:
|
||||
print(f"提取成功: {result.data}")
|
||||
return True
|
||||
else:
|
||||
print(f"提取失败: {result.error}")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"测试异常: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
"""主测试函数。"""
|
||||
print("=" * 50)
|
||||
print("RPA功能测试")
|
||||
print("=" * 50)
|
||||
|
||||
# 运行测试
|
||||
success = asyncio.run(test_basic_connection())
|
||||
|
||||
if success:
|
||||
print("\n基本连接测试通过")
|
||||
else:
|
||||
print("\n基本连接测试失败")
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
print("注意:实际运行需要有效的浏览器配置目录")
|
||||
print("请确保已通过account-manager获取profile_dir")
|
||||
print("=" * 50)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user