113 lines
3.3 KiB
Python
113 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
UI测试工具配置文件
|
||
统一管理所有配置参数
|
||
"""
|
||
|
||
from pathlib import Path
|
||
|
||
class Config:
|
||
"""配置管理类"""
|
||
|
||
# Appium连接配置
|
||
APPIUM_SERVER_URL = 'http://localhost:4723'
|
||
|
||
# 设备配置
|
||
DEVICE_CAPABILITIES = {
|
||
'platformName': 'Android',
|
||
'automationName': 'uiautomator2',
|
||
'deviceName': 'emulator-5554',
|
||
'appPackage': 'com.example.myapplication',
|
||
'appActivity': '.MainActivity',
|
||
'noReset': True,
|
||
'newCommandTimeout': 300
|
||
}
|
||
|
||
# 目录配置
|
||
BASE_DIR = Path(".")
|
||
SCREENSHOTS_DIR = BASE_DIR / "screenshots"
|
||
XML_LAYOUTS_DIR = BASE_DIR / "xml_layouts"
|
||
DESIGN_REFERENCES_DIR = BASE_DIR / "design_references"
|
||
VISUAL_COMPARISONS_DIR = BASE_DIR / "visual_comparisons"
|
||
REPORTS_DIR = BASE_DIR / "reports"
|
||
|
||
# 热键配置
|
||
HOTKEYS = {
|
||
'screenshot': 'F1',
|
||
'save_xml': 'F2',
|
||
'get_activity': 'F3',
|
||
'element_info': 'F4',
|
||
'visual_compare': 'F5',
|
||
'analyze_page': 'F6',
|
||
'monitor_performance': 'F7',
|
||
'click_element': 'F8',
|
||
'generate_report': 'F9',
|
||
'quit': 'ctrl+q'
|
||
}
|
||
|
||
# 视觉比对配置
|
||
VISUAL_COMPARISON = {
|
||
'similarity_threshold': 0.95, # 相似度阈值
|
||
'excellent_threshold': 0.95, # 优秀相似度阈值
|
||
'good_threshold': 0.85, # 良好相似度阈值
|
||
'diff_threshold': 50, # 差异检测阈值
|
||
'min_diff_area': 100, # 最小差异区域面积
|
||
'supported_formats': ['.svg']
|
||
}
|
||
|
||
# XML分析配置
|
||
XML_ANALYSIS = {
|
||
'min_clickable_size': 48, # 最小可点击尺寸
|
||
'max_text_length': 50, # 最大文本长度
|
||
'check_accessibility': True, # 检查可访问性
|
||
'check_duplicates': True # 检查重复ID
|
||
}
|
||
|
||
# 性能监控配置
|
||
PERFORMANCE = {
|
||
'enable_monitoring': True,
|
||
'memory_check_interval': 5, # 内存检查间隔(秒)
|
||
'operation_timeout': 30 # 操作超时时间(秒)
|
||
}
|
||
|
||
# 报告配置
|
||
REPORT = {
|
||
'default_format': 'html', # 默认报告格式
|
||
'generate_html': True, # 生成HTML报告
|
||
'include_screenshots': True, # 包含截图
|
||
'include_xml': True, # 包含XML分析
|
||
'include_performance': True # 包含性能数据
|
||
}
|
||
|
||
# 日志配置
|
||
LOGGING = {
|
||
'level': 'INFO',
|
||
'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||
'file': 'ui_test.log'
|
||
}
|
||
|
||
@classmethod
|
||
def setup_directories(cls):
|
||
"""创建必要的目录"""
|
||
directories = [
|
||
cls.SCREENSHOTS_DIR,
|
||
cls.XML_LAYOUTS_DIR,
|
||
cls.DESIGN_REFERENCES_DIR,
|
||
cls.VISUAL_COMPARISONS_DIR,
|
||
cls.REPORTS_DIR
|
||
]
|
||
|
||
for directory in directories:
|
||
directory.mkdir(exist_ok=True)
|
||
|
||
return directories
|
||
|
||
@classmethod
|
||
def get_supported_design_formats(cls):
|
||
"""获取支持的设计文件格式"""
|
||
return cls.VISUAL_COMPARISON['supported_formats']
|
||
|
||
@classmethod
|
||
def is_svg_preferred(cls):
|
||
"""SVG是否为首选格式"""
|
||
return True # SVG矢量格式,文件小,可缩放 |