用户要求:"进行每一步的时候先校验上一步有没有完成,比如相册界面肯定有特征,如果没有到相册界面
就出现执行,你看看怎么处理" → 方案 A:新增只做校验、不带副作用的步骤。
· tasks/generic/task.py:新步骤 expect_el
- 参数:特征元素选择器 / timeout(10) / what("在等什么") / on_missing
- on_missing:skip_rest(默认,**跳过本轮剩余步骤** —— 这一条不发、换下一个号) / notify / stop
- 为此加了 worker 级的 `_skip_rest`:_exec_steps 每步前检查,foreach_account 每轮复位
· 骨架:关键点击前各插一个 —— 相册页(//*[@text='所有照片']) → 素材已选中(desc 选择/预览)
→ 剪辑页(desc 文字/话题) → 发布页(含'添加标题'/'添加作品描述') → 发布按钮
· 通知:新增 task.page.mismatch(页面不对,本轮剩余步骤已跳过)
· 昵称选择器改**两版通吃**(实测 A06=40.7.0):xpath 联合
`//*[@resource-id="…:id/tkv"] | //*[@resource-id="…:id/tk+"]`
—— 40.7 是 tkv、40.6 是 tk+,联合在 40.7 上实测能读到名字;.env(dev)已改,切号入口两版同为 desc=切换账号
· 前端:编辑器面板 + 参数表单 + 发布页就地编辑字段表都认 expect_el
· 文档:TASK_DEV §3(27→28 种)+ §4.7("每步先校验上一步")、NOTIFY、research §七·补(40.7.0 对照表
+ 联合 xpath + 各页特征 + "别按坐标点页签"的坑)、.env.example
· 测试:新增 scripts/tests/test_expect_el.py(特征在/不在、三种 on_missing、选择器为空),全套 7 个用例通过
49 lines
2.1 KiB
Python
49 lines
2.1 KiB
Python
"""发布计划「按名字发」相关用例:一次跑完,汇总结果。
|
||
|
||
用法(项目根目录):
|
||
.venv/Scripts/python scripts/tests/run_all.py # Windows
|
||
.venv/bin/python scripts/tests/run_all.py # Linux/macOS
|
||
|
||
这些用例的**铁律**(与 doc/DEVELOPMENT.md 的测试约定一致):
|
||
· 一律**临时 SQLite + 临时目录**(`DATABASE_URL` / `DATA_VIDEO_DIR` 指向 tempfile 建的目录),
|
||
**绝不碰用户的真实库与真实素材目录**;
|
||
· 需要设备的地方一律用**假设备**(桩对象/stub),**不连真机、不下发 adb**;
|
||
· 每个用例自己退出码非 0 表示失败,本脚本据此汇总。
|
||
|
||
覆盖:
|
||
test_parse_name 文件名/标题行解析(`名字_日期_编号`、`标题 || 正文_...`、各种拒收)
|
||
test_upload_name 上传 + 配标题落库(不再依赖任何账号台账)
|
||
test_name_scope 读本机账号名字、按名字取计划、推送前核对
|
||
test_switch_account 切换账号(按名字点控件、回读校验、登录页停设备)
|
||
test_foreach_account 循环本机待发的号(一轮跑完、试过不回头、干净退出)
|
||
test_push_by_name 按名字找设备推送(matched/unmatched、缓存)
|
||
test_expect_el 「校验页面」:特征在就过;不在就按 on_missing 处置(默认跳过本轮剩余步骤)
|
||
"""
|
||
import os
|
||
import subprocess
|
||
import sys
|
||
|
||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||
CASES = ["test_parse_name.py", "test_upload_name.py", "test_name_scope.py",
|
||
"test_switch_account.py", "test_foreach_account.py", "test_push_by_name.py",
|
||
"test_expect_el.py"]
|
||
|
||
if hasattr(sys.stdout, "reconfigure"):
|
||
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
||
|
||
failed = []
|
||
for name in CASES:
|
||
print("=" * 66)
|
||
print("▶", name)
|
||
print("=" * 66)
|
||
r = subprocess.run([sys.executable, os.path.join(HERE, name)])
|
||
if r.returncode != 0:
|
||
failed.append(name)
|
||
|
||
print()
|
||
print("=" * 66)
|
||
if failed:
|
||
print("❌ 失败 %d / %d:%s" % (len(failed), len(CASES), "、".join(failed)))
|
||
sys.exit(1)
|
||
print("✅ 全部 %d 个用例通过" % len(CASES))
|