SMA AutoUI
Smart Mobile Automation UI Framework
安装
pip install -r requirements.txt
或者从源码安装:
pip install .
开发安装
pip install -e .
构建
删除旧的构建产物
Remove-Item -Recurse -Force build, dist, *.egg-info -ErrorAction SilentlyContinue
然后重新打包
python -m build --wheel python setup.py bdist_wheel
Appium Session 管理
概述
框架支持跨任务复用 Appium 会话,避免反复启动 App 和 UiAutomator2 服务器。通过 event_mode 参数控制会话生命周期。
Session 文件
- 存储路径:
~/.sma_autoui/sessions/{udid}.json - 文件内容:
{ "session_id": "abc123...", "appium_url": "http://appium-server:4723", "systemPort": "8200", "udid": "172.25.2.20:5555", "saved_at": "2024-07-21 10:30:00" }
会话生命周期
| event_mode | keep_app_alive | newCommandTimeout | Session 保存 | 任务结束行为 |
|---|---|---|---|---|
ONE_TIME_TASK |
False |
240s (4min) | 不保存 | 删除 session 文件 + App 关闭 |
LONG_STAY |
True |
2400s (40min) | 保存 | 保留 session 文件 + App 保持运行 |
Session 复用条件
复用需同时满足以下条件:
- 存在 session 文件:上一次任务以
LONG_STAY模式结束 - Appium URL 一致:当前任务的 Appium 服务器地址与文件记录一致
- systemPort 一致:当前
-s参数与文件记录一致 - 会话仍有效:Appium 服务器上的会话未超时(
newCommandTimeout内)
复用流程
connect() 调用
↓
检查 session 文件是否存在
↓
有文件 → 校验 URL + systemPort 是否一致
↓ ↓
一致 不一致
↓ ↓
尝试复用会话 创建新会话
↓ ↓
成功 连接成功
↓ ↓
App 不重启 App 正常启动
(复用现有状态)
Session 删除时机
- 任务正常结束(ONE_TIME_TASK):
disconnect()调用quit()销毁会话后删除文件 - 复用失败:会话已超时/失效时,清理旧文件
- 手动关闭 App:通过
close_app.py脚本
典型场景
场景 1:连续执行多个 LONG_STAY 任务
任务1 (LONG_STAY) → 进入直播间 → 结束 → App 保持, session 文件保留
↓
任务2 (LONG_STAY) → 检测 session 文件 → 复用会话 → 直接执行(App 不重启)
场景 2:ONE_TIME_TASK 任务
任务 (ONE_TIME_TASK) → 执行任务 → 结束 → session 文件删除, App 关闭
场景 3:切换设备/端口
任务1 (-s 8200) → 保存 session 文件 (systemPort=8200)
↓
任务2 (-s 8201) → 检测 systemPort 不一致 → 忽略旧 session → 创建新会话
pip install sma_autoui-0.1.0-py3-none-any.whl
pip install --force-reinstall
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sma_autoui-0.1.0.tar.gz.
File metadata
- Download URL: sma_autoui-0.1.0.tar.gz
- Upload date:
- Size: 2.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3855e48c200967235bd12b282fbc4c8e4a904d2554ca85a2074cf4e884abb96
|
|
| MD5 |
42ba05d7b8f52fc0b49cc30869f0125c
|
|
| BLAKE2b-256 |
613a4b5d3e8842bd69ceaddc1acd389cee12e37cba5f6152139ba5d3c08d80c4
|
File details
Details for the file sma_autoui-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sma_autoui-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.6 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8c4f5f2d6b46de8baeada113eeeb1aaa40926883f40ca6a5e9729e198e732e4
|
|
| MD5 |
5d962da27e9745ac3b28a11a12629630
|
|
| BLAKE2b-256 |
470b77c018289d503956eb89a971e64be30c46f91ffd03fabc763b539073af93
|