Skip to main content

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 复用条件

复用需同时满足以下条件:

  1. 存在 session 文件:上一次任务以 LONG_STAY 模式结束
  2. Appium URL 一致:当前任务的 Appium 服务器地址与文件记录一致
  3. systemPort 一致:当前 -s 参数与文件记录一致
  4. 会话仍有效:Appium 服务器上的会话未超时(newCommandTimeout 内)

复用流程

connect() 调用
    ↓
检查 session 文件是否存在
    ↓
  有文件 → 校验 URL + systemPort 是否一致
    ↓                    ↓
   一致               不一致
    ↓                    ↓
尝试复用会话      创建新会话
    ↓                    ↓
  成功               连接成功
    ↓                    ↓
App 不重启         App 正常启动
(复用现有状态)

Session 删除时机

  1. 任务正常结束(ONE_TIME_TASK)disconnect() 调用 quit() 销毁会话后删除文件
  2. 复用失败:会话已超时/失效时,清理旧文件
  3. 手动关闭 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

sma_autoui-0.1.0.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sma_autoui-0.1.0-py3-none-any.whl (2.6 MB view details)

Uploaded Python 3

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

Hashes for sma_autoui-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c3855e48c200967235bd12b282fbc4c8e4a904d2554ca85a2074cf4e884abb96
MD5 42ba05d7b8f52fc0b49cc30869f0125c
BLAKE2b-256 613a4b5d3e8842bd69ceaddc1acd389cee12e37cba5f6152139ba5d3c08d80c4

See more details on using hashes here.

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

Hashes for sma_autoui-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8c4f5f2d6b46de8baeada113eeeb1aaa40926883f40ca6a5e9729e198e732e4
MD5 5d962da27e9745ac3b28a11a12629630
BLAKE2b-256 470b77c018289d503956eb89a971e64be30c46f91ffd03fabc763b539073af93

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.9

2 files

0.2.8

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page