android-midscene-automation 1.1.8 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -52
- package/README.md +61 -52
- package/package.json +1 -1
- package/server/appium-recorder/appium-runner.ts +14 -0
- package/server/appium-recorder/random-value-replay.test.ts +76 -0
- package/server/appium-recorder/random-value.test.ts +114 -0
- package/server/appium-recorder/random-value.ts +34 -0
- package/server/appium-recorder/repository.ts +4 -0
- package/server/appium-recorder/script-export.ts +6 -1
- package/src/appium-recorder/AppiumPage.vue +111 -5
- package/src/appium-recorder/action-descriptions.ts +1 -0
- package/src/appium-recorder/components/FlowCanvas.vue +52 -28
- package/src/appium-recorder/components/FlowNodeCard.vue +15 -4
- package/src/appium-recorder/components/FlowStepEditor.vue +3 -1
- package/src/appium-recorder/components/NestedConditionBranches.vue +3 -0
- package/src/appium-recorder/components/PresetVariables.vue +6 -5
- package/src/appium-recorder/components/RandomValueSettings.vue +139 -0
- package/src/appium-recorder/components/RecordedSteps.vue +1 -0
- package/src/appium-recorder/flow-graph.ts +3 -2
- package/src/appium-recorder/flow-labels.ts +4 -1
- package/src/appium-recorder/random-value.ts +60 -0
- package/src/appium-recorder/types.ts +3 -0
- package/src/appium-recorder/variable-presets.ts +24 -0
- package/src/components/config/AiDeduplicationSettings.vue +21 -10
- package/src/components/config/AppiumConfigPanel.vue +22 -9
- package/src/pages/ConfigPage.vue +1 -1
package/README.md
CHANGED
|
@@ -1502,19 +1502,28 @@ Linux: ~/.local/share/android-midscene-automation
|
|
|
1502
1502
|
|
|
1503
1503
|
# 项目更新记录
|
|
1504
1504
|
|
|
1505
|
-
##
|
|
1505
|
+
## [1.1.10]
|
|
1506
|
+
- [Appium]新增“获取随机值”操作节点,支持预设文本及 TXT 抽取、随机整数和 UUID。
|
|
1507
|
+
- [发布]修复发布脚本无法识别 `## [版本号]` 格式更新记录的问题,保留旧版本标题格式兼容。
|
|
1508
|
+
|
|
1509
|
+
## [1.1.9]
|
|
1510
|
+
- [Appium]修复横向流程中展开节点及内部折叠选项时连接点偏移的问题。
|
|
1511
|
+
- [Appium]优化节点展开编辑性能,复用未变化节点的配置,仅测量发生变化的节点,减少重复渲染和整图重排。
|
|
1512
|
+
- [Appium]配置页新增“基础配置”和“模型配置”分组,归并流程外观、回放及 AI 相关设置。
|
|
1513
|
+
|
|
1514
|
+
## [1.1.8]
|
|
1506
1515
|
- [Appium]流程布局新增横向显示,默认为纵向。
|
|
1507
1516
|
- [Appium]流程外观配置新增多套预设主题,可统一调整画布背景、节点填充、节点边框和连接线颜色;支持自定义颜色、恢复默认及深色节点文字适配,主画布与流程总览同步生效。
|
|
1508
1517
|
- [Appium]整理流程外观配置界面,统一布局方向、连接线样式等切换按钮,采用紧凑的主题和颜色配置布局。
|
|
1509
1518
|
- [Appium]节点编辑配置统一采用左右排列,优化各类节点的选项间距与折叠分组;折叠项改为即时展开,合并尺寸更新并减少重复测量,降低整图重排和自动聚焦造成的卡顿。
|
|
1510
1519
|
- [Appium]修复新增节点后画布自动回到居中的问题,保留当前插入位置和缩放比例,并保持原节点的编辑展开状态。
|
|
1511
1520
|
|
|
1512
|
-
##
|
|
1521
|
+
## [1.1.7]
|
|
1513
1522
|
- [Appium]修复元素判断临近超时时误报“设备自动化服务无响应”的问题。
|
|
1514
1523
|
- [Appium]流程编辑器新增直线与曲线切换,默认使用曲线,配置自动保存并同步至主画布和流程总览。
|
|
1515
1524
|
- [Appium]优化多分支汇合线:汇合点按左右汇入线居中,增大纵向间距,曲线在底部留白处平滑汇入,减少节点遮挡。
|
|
1516
1525
|
|
|
1517
|
-
##
|
|
1526
|
+
## [1.1.6]
|
|
1518
1527
|
- [Appium]优化流程画布交互:点击节点自动放大并居中,流程总览支持还原位置,AI 识别节点提示词最多展示三行。
|
|
1519
1528
|
- [Appium]统一节点编辑界面:AI 识别、组件定位、节点信息和超时设置使用紧凑分组,优化循环、滑动、缩放等参数布局。
|
|
1520
1529
|
- [Appium]组件树搜索支持上下切换匹配项,组件详情按优先级展示定位方式和组件属性。
|
|
@@ -1522,61 +1531,61 @@ Linux: ~/.local/share/android-midscene-automation
|
|
|
1522
1531
|
- [配置/UI]修复 API Key 显示按钮,统一提示弹窗、选项控件及相关配置区域样式。
|
|
1523
1532
|
- [Artemis]停止输出成功的状态与就绪探测访问日志,保留服务运行和异常日志。
|
|
1524
1533
|
|
|
1525
|
-
##
|
|
1534
|
+
## [1.1.5]
|
|
1526
1535
|
- UI优化
|
|
1527
1536
|
|
|
1528
|
-
##
|
|
1537
|
+
## [1.1.4]
|
|
1529
1538
|
- [Appium]修复持续刷新页面中的操作超时,以及可选元素未出现时误报失败的问题。
|
|
1530
1539
|
- [Appium]脚本列表支持批量导入并自动重建连接脚本关系;导入后保留列表页,不自动加载脚本。
|
|
1531
1540
|
- [Appium]点击节点改为优先使用组件定位,失败后才使用备用坐标;节点配置中显示备用坐标并过滤无效区域。
|
|
1532
1541
|
- [Appium]优化连接脚本参数和返回值配置,使用自适应卡片布局并简化空状态。
|
|
1533
1542
|
|
|
1534
|
-
##
|
|
1543
|
+
## [1.1.3]
|
|
1535
1544
|
- [Appium]修复登录等点击操作已经触发 Activity 跳转后,UiAutomator2 仍等待点击确认、最终误报超时并占用命令队列的问题;元素点击先读取实时区域,再通过 ADB 点击中心坐标,并限制界面空闲等待时间。
|
|
1536
1545
|
|
|
1537
|
-
##
|
|
1546
|
+
## [1.1.2]
|
|
1538
1547
|
- [Appium]修复登录等点击操作已经触发 Activity 跳转后,持续动画或频繁界面事件仍让 UiAutomator2 长时间等待、最终误报点击超时的问题;限制界面空闲等待时间,避免命令队列被长期占用。
|
|
1539
1548
|
|
|
1540
|
-
##
|
|
1549
|
+
## [1.1.1]
|
|
1541
1550
|
- [文档]更新 README.md。
|
|
1542
1551
|
|
|
1543
|
-
##
|
|
1552
|
+
## [1.1.0]
|
|
1544
1553
|
- [Artemis]修复自定义模型返回 `<think>` 思考标签导致 Hopper 等节点 JSON 解析失败的问题:非 Google 模型的 Pydantic 结构化输出接入统一清理、提取和校验流程,显式提供 JSON Schema,格式错误时限次要求模型纠正。
|
|
1545
1554
|
- [Artemis]修复 Flash 步骤摘要和历史压缩仍直接创建 Gemini 客户端的问题:非 Google 模型统一使用配置中的 summarizer 节点及其备用模型;模型初始化错误不再静默切换到 Gemini。
|
|
1546
1555
|
- [Artemis]修复 Artemis 使用 MiniMax、GLM 等非 Google 默认模型时,辅助检查节点仍强制调用 Gemini 并因缺少密钥导致任务启动失败的问题;支持这些节点继承默认模型或使用显式配置。
|
|
1547
1556
|
- [Artemis]集成 Google Artemis。
|
|
1548
1557
|
- [Midscene]Midscene 集成已停止日常维护,现有功能仍保留。
|
|
1549
1558
|
|
|
1550
|
-
##
|
|
1559
|
+
## [0.2.4]
|
|
1551
1560
|
- Midscene Android、Android Playground、Core、Playground、Shared 和 Web 模块统一升级至 1.14.0。
|
|
1552
1561
|
- 修复 Midscene 测试脚本生成过程中切换“AI 生成 / 自定义步骤编排”会清空生成状态和结果的问题;生成任务继续在后台执行,模式切换后保留已生成步骤与代码。
|
|
1553
1562
|
|
|
1554
|
-
##
|
|
1563
|
+
## [0.2.3]
|
|
1555
1564
|
- 修复长时间执行 ADB 操作、延时或 AI 识别后,Appium 因默认 60 秒命令空闲超时销毁会话,导致后续 Home 键、点击等节点报“invalid session id”的问题;托管服务关闭会话空闲计时,外部服务通过心跳保活并保留 60 秒空闲回收,避免创建请求取消或清理失败后遗留永久会话。
|
|
1556
1565
|
- 为启动 App、清理数据、坐标点击与滑动补齐 ADB 超时和取消控制;终止前台检查后不再继续启动 App,异常结束仍清理会话。
|
|
1557
1566
|
- 修复远程回放固定 10 分钟超时后丢失结果的问题:任务随代理心跳续期,离线任务支持恢复连接后终止与补交历史记录,结果上报失败自动重试且不会重复执行脚本。
|
|
1558
1567
|
- 修复远程设备无法手动终止回放的问题,通过独立心跳传递取消信号,兼容任务派发前取消,并阻止同一设备重复提交回放。
|
|
1559
1568
|
|
|
1560
|
-
##
|
|
1569
|
+
## [0.2.2]
|
|
1561
1570
|
- 新增“概览 → 分析页”,根据已保存脚本和真实执行记录分别汇总 Midscene、Appium 测试数据。
|
|
1562
1571
|
- 修复配置加载失败后出现空白可保存表单的问题,增加独立错误提示和重试;后端断线后自动尝试重连并支持手动重连,保留页面编辑内容。
|
|
1563
1572
|
- Appium 配置自动保存失败后保留最新待保存内容并提供“重试保存”;修复切换或关闭 Appium 页签后,离开页面时未保存草稿保护失效的问题。
|
|
1564
1573
|
- Appium 顶部工具栏改为随页面布局排列,窄屏自动换行,避免遮挡面包屑;统一全站样式与中文组件文案,合并重复主题声明。
|
|
1565
1574
|
- 完善隔离数据环境下的浏览器回归测试,以及请求校验、配置保护、自动保存重试和统计口径测试。
|
|
1566
1575
|
|
|
1567
|
-
##
|
|
1576
|
+
## [0.2.1]
|
|
1568
1577
|
- 侧边栏底部新增“帮助与版本”入口。
|
|
1569
1578
|
- AI 识别预设提示词支持编辑测试场景名称和提示词内容,默认预设与自定义预设均可修改并自动保存。
|
|
1570
1579
|
- AI 识别启用分支后可勾选“启用兜底”,再选择进入左侧 true 或右侧 false 分支;正常识别结果不受影响。
|
|
1571
1580
|
|
|
1572
|
-
##
|
|
1581
|
+
## [0.1.43]
|
|
1573
1582
|
- 新增独立的“提示词优化模型”,统一用于优化 AI 识别提示词、报告提示词和生成回放测试报告总结;AI 识别与回放报告均可输入简要要求后由模型补充提示词,模型测试成功改为弹窗提示。
|
|
1574
1583
|
- 回放设置新增报告模板选择,不选择时使用默认测试报告;开启报告总结后会在回放前检测提示词优化模型,模型不可用时弹窗提示并继续生成默认格式的基础报告。总结请求失败、超时或返回空内容时同样保留基础报告,不改变测试结果。
|
|
1575
1584
|
- 回放输出弹窗支持同时拖拽调整宽度和高度,并保留最小尺寸与窗口边界限制。
|
|
1576
1585
|
- 连接脚本列表显示同一 App 的其他已保存脚本,不再因入口 Activity 不同或未绑定而隐藏;选择时说明等待入口页面或直接从当前画面执行的行为。
|
|
1577
1586
|
- 点击坐标操作新增“获取点击坐标”,直接在左侧设备预览点击画面即可填入实际 X、Y 坐标,无需弹窗,支持取消,取点不会执行设备操作。
|
|
1578
1587
|
|
|
1579
|
-
##
|
|
1588
|
+
## [0.1.42]
|
|
1580
1589
|
- 修复回放终止或会话创建失败后设备端 UiAutomator2 残留,导致组件树刷新失败的问题。
|
|
1581
1590
|
- AI 持续观察新增“检测命中后提前结束”模式,边采样去重边识别,命中后停止观察并继续流程或进入“是”分支;到达最长观察时间后完成剩余关键帧判断,未命中走原顺序或“否”分支,支持命中条件校验、取消和逐次模型请求超时。
|
|
1582
1591
|
- Appium 参数的AI 识别配置,新增持续观察选项,支持 pixelmatch(默认)、OpenCV(SSIM)和不去重选项。
|
|
@@ -1585,15 +1594,15 @@ Linux: ~/.local/share/android-midscene-automation
|
|
|
1585
1594
|
- 新增 AI 识别默认顺序执行模式,模型回答写入日志后继续下一节点;勾选“启用分支”及修改分支问题时通过模型验证判断语义,不符合时提示且不保存分支修改。
|
|
1586
1595
|
- Appium 配置新增默认关闭的“截图与 HTML 报告”开关;开启后才采集节点前后截图并生成 HTML。
|
|
1587
1596
|
|
|
1588
|
-
##
|
|
1597
|
+
## [0.1.41]
|
|
1589
1598
|
- 修复部分华为设备录屏启动时报编码器错误的问题:使用设备默认编码参数,视频流启动失败时降低分辨率和码率重试,并输出各次尝试的诊断日志。
|
|
1590
1599
|
|
|
1591
|
-
##
|
|
1600
|
+
## [0.1.40]
|
|
1592
1601
|
- 开启录屏时,在 Appium 服务端日志结束后汇总所有录像片段的脚本名称和保存位置;未生成视频时明确提示。
|
|
1593
1602
|
- 录屏启动失败、录像不完整或保存失败时,日志明确提示对流程执行的影响并提供排查建议,保留原始错误信息。
|
|
1594
1603
|
- 回放录屏支持按连接脚本分段保存 MP4,返回父脚本继续执行时另存片段;历史结果可选择片段播放,HTML 报告按节点时间自动切换视频,删除历史结果时一并清理全部片段。
|
|
1595
1604
|
|
|
1596
|
-
##
|
|
1605
|
+
## [0.1.39]
|
|
1597
1606
|
- Midscene 相关模块统一升级至 1.12.7,
|
|
1598
1607
|
- scrcpy 视频帧完整性修复:可靠传输视频包、修正关键帧标记,并在缓冲溢出后等待完整关键帧恢复,降低设备预览花屏风险。
|
|
1599
1608
|
- 回放按钮右侧下拉设置新增默认关闭的“录制回放视频”,远程设备暂不支持。
|
|
@@ -1601,37 +1610,37 @@ Linux: ~/.local/share/android-midscene-automation
|
|
|
1601
1610
|
- 移除 AI 识别操作、测试入口及 Appium 参数中的 AI 模型配置,保留流程背景色设置;旧脚本中的 AI 节点提示替换,回放前阻止执行,不自动删除或改变分支。
|
|
1602
1611
|
|
|
1603
1612
|
|
|
1604
|
-
##
|
|
1613
|
+
## [0.1.38]
|
|
1605
1614
|
- 移除节点类型切换;新节点及未配置的判断等待超时统一为 3000ms,已有自定义时间和延时、长按等操作时长保持不变。
|
|
1606
1615
|
- 取消 Activity 不匹配时的脚本编辑锁定,不在脚本绑定页面也可编辑节点;页面差异仅作提示,保留录制操作及回放期间的编辑保护。
|
|
1607
1616
|
- 所有分支节点新增“超时后处理”,可预设终止流程、进入左侧或右侧分支,默认终止;覆盖元素等待、文字匹配、勾选控件等待、AI 识别及图像观察超时,日志和 HTML 报告标明超时分支。正常 false、循环次数上限与超时区分处理,设备断开及 Appium 无响应仍终止。
|
|
1608
1617
|
|
|
1609
|
-
##
|
|
1618
|
+
## [0.1.37]
|
|
1610
1619
|
- 修复元素查找超时未覆盖 Appium 请求的问题,驱动无响应时及时中止并明确报错,不再误判为找不到元素;唯一原生定位优先使用 ID 或 Accessibility ID。
|
|
1611
1620
|
- 设备预览新增设备信息,展示设备名称、品牌、型号、处理器、Android 版本、物理分辨率及当前分辨率,支持远程设备;问号位于标题右侧,样式与全局变量帮助图标一致。
|
|
1612
1621
|
- 新增独立“杀死 APP”操作节点,默认使用当前选中应用包名,支持编辑目标包名;停止当前设备用户下的应用进程,不清除应用数据。
|
|
1613
1622
|
- Midscene 相关模块由 1.12.5 统一升级至 1.12.6。
|
|
1614
1623
|
|
|
1615
|
-
##
|
|
1624
|
+
## [0.1.36]
|
|
1616
1625
|
- 新合并支持取消:原合并按钮切换为取消合并,还原分支和被删除的重复节点,保留配置编辑;公共流程新增的普通操作可选择保留左侧、右侧或两侧,结构冲突时阻止还原。本地保存还原记录,导出及节点复制不携带历史记录。
|
|
1617
1626
|
- 启动相册前先停止当前设备用户下的目标相册进程,再重新打开;保留相册自动适配,不清除照片及应用数据,停止失败时明确报错。
|
|
1618
1627
|
- 修复修改元素或父级定位后仍使用旧备用定位、画面变化像素容差无法设为 0 的问题。
|
|
1619
1628
|
|
|
1620
|
-
##
|
|
1629
|
+
## [0.1.35]
|
|
1621
1630
|
- 新增“图像判断”分支节点,支持本地 OpenCV 模板匹配、图片勾选双模板、黑屏、区域颜色和多帧变化检测;支持组件定位、框选区域、模板采集与上传、连续采样及 true/false 分支,证据不足时明确报告无法判定。HTML 报告展示指标和可放大的检测图片,并沿用敏感运行截图保护。
|
|
1622
1631
|
- 合流后的公共节点上方新增插入入口,支持新增和粘贴操作,所有汇入分支先执行新操作再进入原公共节点。
|
|
1623
1632
|
- 修复嵌套判断显式合流到外层公共节点时连接被过滤、公共节点提前排列的问题,支持跨层分支合流。
|
|
1624
1633
|
|
|
1625
|
-
##
|
|
1634
|
+
## [0.1.34]
|
|
1626
1635
|
- 修复同一分支内显式跳转被画布误画为顺序连接的问题,失效跳转目标不再错误连接到相邻节点。
|
|
1627
1636
|
- 修复判断分支默认返回公共后续节点时画布漏连线、节点重叠的问题,嵌套分支显示与回放路径保持一致。
|
|
1628
1637
|
|
|
1629
|
-
##
|
|
1638
|
+
## [0.1.33]
|
|
1630
1639
|
- 操作菜单移除“断言存在”和“断言文本”,统一保留“判断存在”及其文本匹配配置;旧脚本中的断言节点仍兼容原有执行行为。
|
|
1631
1640
|
- “点击坐标”节点支持编辑 X、Y 坐标,保存后回放使用新坐标;默认节点名称同步更新,自定义名称保持不变。
|
|
1632
1641
|
- 新增“预设变量”区域,支持全局变量和脚本私有变量,输入、判断、定位和日志支持 `{{变量名}}` 引用。
|
|
1633
1642
|
|
|
1634
|
-
##
|
|
1643
|
+
## [0.1.32]
|
|
1635
1644
|
- 添加画面变化结束节点时,多组可配对检测支持按名称及开始节点编号选择,允许交叉结束;只有一组时直接添加,保留分支及重复结束校验。
|
|
1636
1645
|
- 画面变化结束节点校验覆盖祖先及子分支:同一执行路径已存在对应结束节点时,后续分支不能重复添加;互斥分支仍可分别结束。
|
|
1637
1646
|
- 脚本列表新增“历史结果对比”:保存运行结果、应用版本、设备、截图和日志,支持筛选查看通过率、耗时趋势与失败节点分布,对比两次运行并删除选中历史;手动终止不计入通过率,旧报告不自动补录。
|
|
@@ -1640,24 +1649,24 @@ Linux: ~/.local/share/android-midscene-automation
|
|
|
1640
1649
|
- Midscene 相关模块统一从 1.12.2 升级至 1.12.5。
|
|
1641
1650
|
|
|
1642
1651
|
|
|
1643
|
-
##
|
|
1652
|
+
## [0.1.31]
|
|
1644
1653
|
- 组件详情展示 Resource ID、Accessibility ID、XPath 和 UiAutomator 四种定位内容,支持分别复制,方便配置循环退出条件;缺少对应属性时显示未提供。
|
|
1645
1654
|
- “流程控制”新增有界循环及退出循环:支持固定次数、元素出现或消失时退出,必须设置最大执行次数;循环体支持嵌套判断、合流和连接脚本。退出节点可选择当前或外层循环,退出外层时同时结束内部循环并直接执行目标循环结束路径,日志及 HTML 报告标注轮次和退出目标。
|
|
1646
1655
|
- 新增流程节点搜索,支持按名称、操作类型、定位内容和日志关键字筛选,展示所属分支并在多个结果间切换;普通画布与流程总览支持定位高亮,不改变节点布局及批量选中状态。
|
|
1647
1656
|
- Midscene 相关模块统一从 1.12.0 升级至 1.12.2。
|
|
1648
1657
|
- 录制工作区支持拖拽调整设备预览、组件树栏宽,自动保存布局并支持恢复默认。
|
|
1649
1658
|
|
|
1650
|
-
##
|
|
1659
|
+
## [0.1.30]
|
|
1651
1660
|
- 新增节点批量删除功能,支持多选节点,选中节点及所属子节点以柔和红色背景和浅色文字标记,确认后统一删除;支持普通与放大视图同步操作。
|
|
1652
1661
|
|
|
1653
|
-
##
|
|
1662
|
+
## [0.1.29]
|
|
1654
1663
|
- 判断节点新增“合并分支”,支持选择一侧公共流程起点,将两侧后续汇入同一段居中流程;另一侧可保留独有操作或确认删除重复后缀,支持嵌套判断及各类分支,公共节点只执行一次且不随单侧节点删除。
|
|
1655
1664
|
- 将 Checkbox、RadioButton 判断入口合并为“判断勾选”,新增 Switch 支持;添加和回放时自动校验组件类型及可勾选属性,读取实时 checked 状态进入 true / false 分支,不改变控件状态,兼容已有独立判断节点。
|
|
1656
1665
|
- “流程控制”新增终止流程节点,执行到该节点时主动结束本次回放,不再执行后续节点或连接脚本;子脚本触发时也结束整个流程,保留执行日志和报告,不作为执行失败。
|
|
1657
1666
|
- “设备操作”新增启动相册顺序节点,优先解析系统相册入口,必要时查找已安装的常见相册应用;仅打开相册,不选择照片,日志记录实际启动应用,找不到或启动失败时明确报错。
|
|
1658
1667
|
- Appium 配置新增流程背景色设置,默认沿用浅绿色,支持预选颜色、颜色选择器、#RGB / #RRGGBB 输入校验和恢复默认;保存后持久化,普通画布、放大视图和连接脚本预览统一应用。
|
|
1659
1668
|
|
|
1660
|
-
##
|
|
1669
|
+
## [0.1.28]
|
|
1661
1670
|
- Appium 配置中的流程背景色独立成区,与节点模型配置分开展示,保留预选颜色、自定义颜色及保存入口。
|
|
1662
1671
|
- “组件操作”新增文字点击分支节点,无需预选元素,支持精准匹配和模糊匹配原生组件文字;匹配并点击后进入“匹配到文字”,等待超时未找到则进入“未匹配到文字”。支持编辑文字和超时,多元素匹配及点击异常明确报错,日志和报告保留分支结果。
|
|
1663
1672
|
- “流程控制”新增输出日志节点,支持设置日志内容和自定义关键字,默认按 `stageLog:内容` 输出;支持添加后编辑,回放实时输出、日志文件及报告均保留日志内容,多行内容逐行添加关键字。
|
|
@@ -1665,7 +1674,7 @@ Linux: ~/.local/share/android-midscene-automation
|
|
|
1665
1674
|
- 长按操作新增元素模式,新建节点默认按元素定位执行长按;添加弹窗和节点配置支持切换元素 / 坐标模式及修改长按时间,旧脚本保留坐标长按行为。
|
|
1666
1675
|
- 新增原生 Checkbox 和 RadioButton 状态判断节点,添加时校验选中元素类型,回放时读取 `checked` 属性,按 `true / false` 进入对应分支,不改变勾选状态;组件详情显示原生勾选属性,回放日志和报告记录判断结果。
|
|
1667
1676
|
|
|
1668
|
-
##
|
|
1677
|
+
## [0.1.27]
|
|
1669
1678
|
- npx android-midscene-automation 启动时默认使用固定的系统用户数据目录保存脚本、配置、报告和运行态文件,并在启动时尝试迁移旧版启动目录下的数据,降低升级后脚本或配置“不见了”的风险。
|
|
1670
1679
|
- 新增脚本列表复制和重命名能力,可直接生成“原文件名 Copy”副本并修改脚本名称,便于复用已有录制流程。
|
|
1671
1680
|
- 新增检测画面变化能力,支持框选设备预览区域或使用当前选中元素作为检测区域,通过“检测画面变化N-开始节点 / 结束节点”对同一分支内的前后截图进行差异对比。
|
|
@@ -1674,29 +1683,29 @@ Linux: ~/.local/share/android-midscene-automation
|
|
|
1674
1683
|
- 优化流程图节点插入、删除、复制、缩放和判断分支布局,修复节点新增后连线延迟、缩放后节点不可见、删除检测节点后分支错乱、重复添加同一结束节点等问题。
|
|
1675
1684
|
- 回放报告截图和截图节点改为使用 ADB 截图,避免 Appium /screenshot 超时后堵塞 UiAutomator2 命令队列;Appium 请求超时时也会显示更准确的超时提示。
|
|
1676
1685
|
|
|
1677
|
-
##
|
|
1686
|
+
## [0.1.26]
|
|
1678
1687
|
- 修复流程节点复制与粘贴问题,避免 `structuredClone` 失败、粘贴后原节点消失、分支插入位置错误和复制后相对位置偏移。
|
|
1679
1688
|
- 修复判断分支已有节点时入口添加按钮缺失的问题,分支入口现在会保留可插入节点,并正确连接到首个分支节点。
|
|
1680
1689
|
- 滑动操作支持在添加弹窗和节点配置中修改起点、终点坐标及滑动时长。
|
|
1681
1690
|
- 长按操作支持设置长按时间,并在节点卡片中显示长按坐标和时长。
|
|
1682
1691
|
|
|
1683
|
-
##
|
|
1692
|
+
## [0.1.25]
|
|
1684
1693
|
- Android 设备预览恢复使用 scrcpy 实时流,优化实时流参数,减少 H.264 丢帧导致的花屏;刷新画面时会重启底层 Playground 预览流并等待会话就绪。
|
|
1685
1694
|
- 测试脚本生成新增提示词模板,可在通用提示词、广告测试、表单填写、聊天对话、播放器测试、搜索列表、订单支付、权限弹窗、个人设置和 H5/WebView 等场景间切换,并支持编辑或上传当前原始 Prompt。
|
|
1686
1695
|
- 优化 AI 生成流程,支持后台处理和终止生成;生成中锁定原始 Prompt,再次点击“AI 生成”可恢复进度弹窗,终止后不再弹出额外提示。
|
|
1687
1696
|
- 优化脚本生成提示词策略,区分广告、播放器、弹窗等被测目标与无关遮挡内容,登录流程增加登录后遮挡弹窗处理和无遮挡首页成功判定。
|
|
1688
1697
|
|
|
1689
|
-
##
|
|
1698
|
+
## [0.1.24]
|
|
1690
1699
|
- 参数配置的运行配置新增保存校验,Android SDK 路径必须包含 `platform-tools/adb`,回放报告目录必须填写已存在且可写入的绝对路径。
|
|
1691
1700
|
- Midscene 自定义提供方的 `Model Name` 和 `Model Family` 改为输入框,`Base URL` 匹配已知提供方时自动填充模型名称和模型系列,并在字段旁新增官方配置说明入口。
|
|
1692
1701
|
|
|
1693
|
-
##
|
|
1702
|
+
## [0.1.23]
|
|
1694
1703
|
- 常见问题拆分为独立 `FAQ.md` 文档,并在 README 的“功能文档”中增加跳转入口。
|
|
1695
1704
|
|
|
1696
|
-
##
|
|
1705
|
+
## [0.1.22]
|
|
1697
1706
|
- 升级 Midscene 相关依赖到 `v1.12.0`
|
|
1698
1707
|
|
|
1699
|
-
##
|
|
1708
|
+
## [0.1.21]
|
|
1700
1709
|
- 录制步骤流程图升级为独立画布与节点卡片视图,优化节点内容排版、操作图标、选中态、批量复制和还原位置体验。
|
|
1701
1710
|
- 统一普通流程线、操作按钮连线和判断分支线条样式,按节点实际高度计算连接位置,修复线条颜色不一致、断裂、多余线条、节点重叠和分支错位问题。
|
|
1702
1711
|
- 优化判断分支布局,统一“是 / 否”分支的 T 形连接样式,避免分支节点堆叠、左右分支连接错乱及多出第三分支。
|
|
@@ -1705,30 +1714,30 @@ Linux: ~/.local/share/android-midscene-automation
|
|
|
1705
1714
|
- 移除“连接到下一节点”“取消连接”“继续主流程”等冗余连接操作,保留复制节点作为主要复用方式。
|
|
1706
1715
|
- 修复放大面板后点击操作按钮或节点配置会重置缩放的问题,保持当前画布大小和位置。
|
|
1707
1716
|
|
|
1708
|
-
##
|
|
1717
|
+
## [0.1.20]
|
|
1709
1718
|
- Appium 流程支持单节点、连续节点及完整判断子流程的复制与粘贴。
|
|
1710
1719
|
- 优化判断分支布局和流程总览,支持在总览中编辑完整流程。
|
|
1711
1720
|
- Appium session 与“启动 APP”节点解耦,并避免将桌面、设置等系统 Activity 误识别为脚本入口。
|
|
1712
1721
|
- 修复复杂判断脚本加载失败及加载后无法进入“当前录制”的问题。
|
|
1713
1722
|
|
|
1714
|
-
##
|
|
1723
|
+
## [0.1.19]
|
|
1715
1724
|
- 回放输出支持保留完整 Appium 服务日志,并可在执行过程中手动终止。
|
|
1716
1725
|
- 新增单文件 HTML 截图回放报告,提供时间轴、步骤导航和连续播放效果。
|
|
1717
1726
|
|
|
1718
|
-
##
|
|
1727
|
+
## [0.1.18]
|
|
1719
1728
|
- 使用说明和更新记录自动嵌入 README,可直接在 npm 页面渲染查看。
|
|
1720
1729
|
|
|
1721
|
-
##
|
|
1730
|
+
## [0.1.17]
|
|
1722
1731
|
- 新增在线文档查看入口,支持渲染使用说明和更新记录。
|
|
1723
1732
|
|
|
1724
|
-
##
|
|
1733
|
+
## [0.1.16]
|
|
1725
1734
|
- 优化参数配置页面布局,将预设 App 参数归入运行配置区域。
|
|
1726
1735
|
|
|
1727
|
-
##
|
|
1736
|
+
## [0.1.15]
|
|
1728
1737
|
- README 新增 Midscene 与 Appium 两种测试方式及环境要求说明。
|
|
1729
1738
|
- 明确 Midscene 需要配置模型,Appium 无需模型即可运行。
|
|
1730
1739
|
|
|
1731
|
-
##
|
|
1740
|
+
## [0.1.14]
|
|
1732
1741
|
- 参数配置支持指定 Android SDK 和回放报告目录,并在回放前检查 Android SDK。
|
|
1733
1742
|
- 回放完成后生成包含节点配置、执行结果和日志的 Markdown 报告。
|
|
1734
1743
|
- 脚本列表支持 JSON 脚本导入和下载。
|
|
@@ -1737,41 +1746,41 @@ Linux: ~/.local/share/android-midscene-automation
|
|
|
1737
1746
|
- 判断分支支持文本匹配、连接不同 Activity 的脚本及连接后的主流程回放。
|
|
1738
1747
|
- 新增节点备注、未保存提醒和页面状态持久化。
|
|
1739
1748
|
|
|
1740
|
-
##
|
|
1749
|
+
## [0.1.13]
|
|
1741
1750
|
- 修复历史脚本新增节点后无法覆盖保存的问题。
|
|
1742
1751
|
- 修复连接脚本未按顺序继续执行的问题。
|
|
1743
1752
|
|
|
1744
|
-
##
|
|
1753
|
+
## [0.1.12]
|
|
1745
1754
|
- “启动 APP”统一为流程开始节点操作,每个脚本最多添加一次。
|
|
1746
1755
|
- 连接脚本回放时自动跳过子脚本的重复启动操作。
|
|
1747
1756
|
|
|
1748
|
-
##
|
|
1757
|
+
## [0.1.11]
|
|
1749
1758
|
- 修复 npm 页面中的更新记录访问链接。
|
|
1750
1759
|
|
|
1751
|
-
##
|
|
1760
|
+
## [0.1.10]
|
|
1752
1761
|
- npm 包新增项目更新记录,并清理未随包发布的内部文档链接。
|
|
1753
1762
|
|
|
1754
|
-
##
|
|
1763
|
+
## [0.1.9]
|
|
1755
1764
|
- 录制步骤升级为可拖动、缩放和编辑的流程图,支持“是 / 否”判断分支。
|
|
1756
1765
|
- 支持在流程任意位置插入操作,并编辑节点、定位器、超时和输入内容。
|
|
1757
1766
|
- 支持 Activity 跳转检测和单 Activity 脚本录制保护。
|
|
1758
1767
|
- 支持连接已保存脚本,组合登录、首页等跨页面测试流程。
|
|
1759
1768
|
- 新增脚本管理列表,可加载、删除和回放已录制脚本。
|
|
1760
1769
|
|
|
1761
|
-
##
|
|
1770
|
+
## [0.1.8]
|
|
1762
1771
|
- 新增 selector 唯一性检测和父级上下文定位,解决多个组件共用同一 ID 的问题。
|
|
1763
1772
|
- 回放支持多级定位和坐标兜底,并记录页面检查点与完整失败诊断信息。
|
|
1764
1773
|
|
|
1765
|
-
##
|
|
1774
|
+
## [0.1.7]
|
|
1766
1775
|
- 新增存在则点击、输入、清空、返回等可选操作。
|
|
1767
1776
|
- 新增等待出现、判断存在和等待消失等等待与判断能力。
|
|
1768
1777
|
|
|
1769
|
-
##
|
|
1778
|
+
## [0.1.6]
|
|
1770
1779
|
- 新增可复用设备预览,支持点击画面选择组件树节点和刷新实时画面。
|
|
1771
1780
|
- 组件树支持滚动浏览并展示当前 Activity。
|
|
1772
1781
|
- 录制操作统一通过“添加操作”菜单选择。
|
|
1773
1782
|
|
|
1774
|
-
##
|
|
1783
|
+
## [0.1.5]
|
|
1775
1784
|
- 首次提供 Appium 无模型录制与回放能力。
|
|
1776
1785
|
- 支持从组件树录制点击、输入、断言和延时,并保存为可回放脚本。
|
|
1777
1786
|
- App 包名与参数配置中的预设 App 统一管理。
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolveReportSummary } from '../../src/appium-recorder/report-summary';
|
|
2
2
|
import { execFile } from 'node:child_process';
|
|
3
3
|
import { VariableScope, variableContext, resolveVariableStep } from './variables';
|
|
4
|
+
import { RandomValueGenerator } from './random-value';
|
|
4
5
|
import { getPresetVariables } from './variable-store';
|
|
5
6
|
import { validateExtraction, validateVariables, type TestVariable } from '../../src/appium-recorder/variables';
|
|
6
7
|
import { captureHistoryFrames, readAppVersion } from './history-capture';
|
|
@@ -71,6 +72,7 @@ type PendingVisualChangeCheck = {
|
|
|
71
72
|
};
|
|
72
73
|
|
|
73
74
|
const replayContext = new AsyncLocalStorage<{
|
|
75
|
+
randomValues: RandomValueGenerator;
|
|
74
76
|
signal?: AbortSignal;
|
|
75
77
|
appiumLog: (line: string) => void;
|
|
76
78
|
serverUrl: string;
|
|
@@ -925,6 +927,12 @@ async function runStep(
|
|
|
925
927
|
): Promise<RunStepResult | void> {
|
|
926
928
|
throwIfReplayStopped();
|
|
927
929
|
step = resolveVariableStep(step);
|
|
930
|
+
if (step.type === 'randomValue') {
|
|
931
|
+
const scope = variableContext.getStore();
|
|
932
|
+
const context = replayContext.getStore();
|
|
933
|
+
if (!scope || !context) throw new Error('随机值变量作用域未初始化');
|
|
934
|
+
return context.randomValues.write(scope, JSON.stringify([meta.scriptName, step.id]), step.randomValue);
|
|
935
|
+
}
|
|
928
936
|
if (step.type === 'aiRecognition') {
|
|
929
937
|
const recognition = await recognizeDeviceScreen({
|
|
930
938
|
deviceId, prompt: step.value, aiBranchEnabled: step.aiBranchEnabled, aiObservation: step.aiObservation,
|
|
@@ -1705,6 +1713,11 @@ export async function replayAppiumScript(
|
|
|
1705
1713
|
for (const step of current.steps) {
|
|
1706
1714
|
(step.parameters || []).forEach(item => scope.track(item));
|
|
1707
1715
|
if (step.extractVariable) scope.track({ ...step.extractVariable, value: '' });
|
|
1716
|
+
if (step.randomValue) {
|
|
1717
|
+
const name = step.randomValue.name;
|
|
1718
|
+
scope.track({ name, value: step.randomValue.text || '', sensitive: step.randomValue.sensitive
|
|
1719
|
+
|| current.variables?.find(item => item.name === name)?.sensitive || scope.locals.get(name)?.sensitive || scope.globals.get(name)?.sensitive });
|
|
1720
|
+
}
|
|
1708
1721
|
if (step.type === 'runScript' && step.value) {
|
|
1709
1722
|
const child = scripts.get(step.value);
|
|
1710
1723
|
if (child) registerSecrets(child);
|
|
@@ -1732,6 +1745,7 @@ export async function replayAppiumScript(
|
|
|
1732
1745
|
return length;
|
|
1733
1746
|
};
|
|
1734
1747
|
const context = {
|
|
1748
|
+
randomValues: new RandomValueGenerator(),
|
|
1735
1749
|
screenshotReport: (runOptions.screenshotReport ?? loadConfig().appium.screenshotReport) === true,
|
|
1736
1750
|
visualCaptureNodes: new Set([script, ...scripts.values()].flatMap(item => item.steps.flatMap(step =>
|
|
1737
1751
|
step.visualChange ? [step.id, step.visualChange.startStepId || '', step.visualChange.endStepId || ''] : []))),
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import childProcess from 'node:child_process';
|
|
4
|
+
import { syncBuiltinESMExports } from 'node:module';
|
|
5
|
+
import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import type { AppiumRecordedScriptRecord } from './repository';
|
|
9
|
+
|
|
10
|
+
test('replay repeats random nodes, passes literal values through child returns, resets pools and redacts secrets', async () => {
|
|
11
|
+
const root = await mkdtemp(join(tmpdir(), 'random-replay-'));
|
|
12
|
+
const original = { execFile: childProcess.execFile, fetch: globalThis.fetch };
|
|
13
|
+
const env = { ...process.env };
|
|
14
|
+
try {
|
|
15
|
+
const sdk = join(root, 'sdk');
|
|
16
|
+
await mkdir(join(sdk, 'platform-tools'), { recursive: true });
|
|
17
|
+
await writeFile(join(sdk, 'platform-tools', 'adb'), '');
|
|
18
|
+
Object.assign(process.env, { ANDROID_MIDSCENE_DATA_ROOT: root, ANDROID_HOME: sdk,
|
|
19
|
+
ANDROID_SDK_ROOT: sdk, APPIUM_SERVER_URL: 'http://external.invalid' });
|
|
20
|
+
childProcess.execFile = ((_command, _args, _options, callback) => {
|
|
21
|
+
queueMicrotask(() => callback(null, '', ''));
|
|
22
|
+
return {};
|
|
23
|
+
}) as typeof childProcess.execFile;
|
|
24
|
+
syncBuiltinESMExports();
|
|
25
|
+
globalThis.fetch = async (input, init) => Response.json({ value: new URL(String(input)).pathname === '/session'
|
|
26
|
+
&& init?.method === 'POST' ? { sessionId: 'random-test-session' } : null });
|
|
27
|
+
const { replayAppiumScript } = await import('./appium-runner');
|
|
28
|
+
const base = { appPackage: 'example.app', appActivity: '', deviceId: 'fake-device', createdAt: '', updatedAt: '' };
|
|
29
|
+
const child: AppiumRecordedScriptRecord = { ...base, id: 'child', name: '随机子流程', steps: [
|
|
30
|
+
{ id: 'pick', type: 'randomValue', label: '获取随机文本', randomValue: {
|
|
31
|
+
name: 'PROMPT', mode: 'text', text: '{{literal}}\n第二句', withoutReplacement: true,
|
|
32
|
+
} },
|
|
33
|
+
{ id: 'log', type: 'log', label: '记录抽取结果', value: 'sample={{PROMPT}}' },
|
|
34
|
+
] };
|
|
35
|
+
const script: AppiumRecordedScriptRecord = { ...base, id: 'root', name: '循环随机', steps: [
|
|
36
|
+
{ id: 'loop', type: 'loop', label: '重复两次', loop: { maxIterations: 2, exitWhen: 'never' },
|
|
37
|
+
flow: { nodeKind: 'condition', yesTargetId: 'call', noTargetId: 'after' } },
|
|
38
|
+
{ id: 'call', type: 'runScript', label: '连接子流程', value: 'child', returns: [{ name: 'PROMPT', target: 'LAST' }],
|
|
39
|
+
flow: { parentConditionId: 'loop', parentBranch: 'yes' } },
|
|
40
|
+
{ id: 'echo', type: 'log', label: '重复引用返回值', value: 'echo={{LAST}}|{{LAST}}',
|
|
41
|
+
flow: { parentConditionId: 'loop', parentBranch: 'yes' } },
|
|
42
|
+
{ id: 'after', type: 'noop', label: '完成' },
|
|
43
|
+
] };
|
|
44
|
+
const run = (input = script) => replayAppiumScript(input, 'fake-device', undefined, undefined,
|
|
45
|
+
{ screenshotReport: false, reportSummaryEnabled: false, linkedScripts: [child] });
|
|
46
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
47
|
+
const result = await run();
|
|
48
|
+
assert.equal(result.success, true, result.output);
|
|
49
|
+
const values = [...result.output.matchAll(/stageLog:sample=([^\n]+)/g)].map(match => match[1]);
|
|
50
|
+
assert.deepEqual(new Set(values), new Set(['{{literal}}', '第二句']));
|
|
51
|
+
for (const value of values) assert.ok(result.output.includes(`stageLog:echo=${value}|${value}`));
|
|
52
|
+
}
|
|
53
|
+
const exhausted = await run({ ...script, steps: script.steps.map(step => step.type === 'loop'
|
|
54
|
+
? { ...step, loop: { maxIterations: 3, exitWhen: 'never' } } : step) });
|
|
55
|
+
assert.equal(exhausted.success, false);
|
|
56
|
+
assert.ok(exhausted.output.includes('候选已耗尽'));
|
|
57
|
+
const sensitive = await run({ ...base, id: 'secret', name: '敏感随机', steps: [
|
|
58
|
+
{ id: 'secret-pick', type: 'randomValue', label: '获取敏感值', randomValue: {
|
|
59
|
+
name: 'api_token', mode: 'text', text: 'private-one\nprivate-two',
|
|
60
|
+
} },
|
|
61
|
+
{ id: 'secret-log', type: 'log', label: '记录敏感值', value: '{{api_token}}' },
|
|
62
|
+
] });
|
|
63
|
+
assert.equal(sensitive.success, true, sensitive.output);
|
|
64
|
+
assert.ok(!/private-one|private-two/.test(sensitive.output));
|
|
65
|
+
const report = await readFile(sensitive.reportPath, 'utf8');
|
|
66
|
+
assert.ok(!/private-one|private-two/.test(report));
|
|
67
|
+
} finally {
|
|
68
|
+
childProcess.execFile = original.execFile;
|
|
69
|
+
globalThis.fetch = original.fetch;
|
|
70
|
+
syncBuiltinESMExports();
|
|
71
|
+
for (const key of ['ANDROID_MIDSCENE_DATA_ROOT', 'ANDROID_HOME', 'ANDROID_SDK_ROOT', 'APPIUM_SERVER_URL']) {
|
|
72
|
+
if (env[key] === undefined) delete process.env[key]; else process.env[key] = env[key];
|
|
73
|
+
}
|
|
74
|
+
await rm(root, { recursive: true, force: true });
|
|
75
|
+
}
|
|
76
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { RandomValueGenerator } from './random-value';
|
|
7
|
+
import { VariableScope, variableContext, resolveVariableStep } from './variables';
|
|
8
|
+
import { randomTextCandidates, validateRandomValue, MAX_RANDOM_INTEGER_RANGE, type RandomValueConfig } from '../../src/appium-recorder/random-value';
|
|
9
|
+
import { createAppiumScriptExport } from './script-export';
|
|
10
|
+
import { createFlowClipboard, pasteFlowClipboard } from '../../src/appium-recorder/flow-copy';
|
|
11
|
+
import { defaultFlowKind, labelFlowStep } from '../../src/appium-recorder/flow-labels';
|
|
12
|
+
import type { AppiumRecordedScriptRecord } from './repository';
|
|
13
|
+
import { variablePresetOptions } from '../../src/appium-recorder/variable-presets';
|
|
14
|
+
|
|
15
|
+
test('preset keys merge global and private scopes without exposing values', () => {
|
|
16
|
+
assert.deepEqual(variablePresetOptions([
|
|
17
|
+
{ name: 'PROMPT', value: 'global', sensitive: true },
|
|
18
|
+
{ name: 'GLOBAL', value: 'global' },
|
|
19
|
+
{ name: '', value: '' },
|
|
20
|
+
], [
|
|
21
|
+
{ name: 'PROMPT', value: 'private' },
|
|
22
|
+
{ name: 'apiKey', value: 'secret' },
|
|
23
|
+
{ name: 'bad key', value: '' },
|
|
24
|
+
]), [
|
|
25
|
+
{ name: 'PROMPT', scope: 'private', sensitive: true },
|
|
26
|
+
{ name: 'GLOBAL', scope: 'global', sensitive: false },
|
|
27
|
+
{ name: 'apiKey', scope: 'private', sensitive: true },
|
|
28
|
+
]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('random text parses TXT, preserves literal templates and stays stable after writing', () => {
|
|
32
|
+
assert.deepEqual(randomTextCandidates('\uFEFF# 注释\r\n 你好 \r\n\n{{literal}}\n你好'), ['你好', '{{literal}}', '你好']);
|
|
33
|
+
const config: RandomValueConfig = { name: 'PROMPT', mode: 'text', text: '{{literal}}' };
|
|
34
|
+
const scope = new VariableScope([], []);
|
|
35
|
+
new RandomValueGenerator().write(scope, 'node', config);
|
|
36
|
+
assert.equal(scope.resolve('{{PROMPT}}').value, '{{literal}}');
|
|
37
|
+
assert.equal(scope.resolve('{{PROMPT}}/{{PROMPT}}').value, '{{literal}}/{{literal}}');
|
|
38
|
+
assert.equal(variableContext.run(scope, () => resolveVariableStep({ id: 'input', type: 'input', label: '输入', value: '{{PROMPT}}' })).value, '{{literal}}');
|
|
39
|
+
const child = scope.child([], [{ name: 'message', value: '{{PROMPT}}' }]);
|
|
40
|
+
assert.equal(child.resolve('{{message}}').value, '{{literal}}');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('non-repeating pools are per node and per replay; exhaustion never overwrites the old variable', () => {
|
|
44
|
+
const generator = new RandomValueGenerator();
|
|
45
|
+
const config: RandomValueConfig = { name: 'PROMPT', mode: 'text', text: '甲\n乙\n甲', withoutReplacement: true };
|
|
46
|
+
const scope = new VariableScope([], []);
|
|
47
|
+
generator.write(scope, 'script/node', config);
|
|
48
|
+
const first = scope.resolve('{{PROMPT}}').value;
|
|
49
|
+
generator.write(scope, 'script/node', config);
|
|
50
|
+
const second = scope.resolve('{{PROMPT}}').value;
|
|
51
|
+
assert.deepEqual(new Set([first, second]), new Set(['甲', '乙']));
|
|
52
|
+
assert.throws(() => generator.write(scope, 'script/node', config), /耗尽/);
|
|
53
|
+
assert.equal(scope.resolve('{{PROMPT}}').value, second);
|
|
54
|
+
assert.ok(['甲', '乙'].includes(generator.next('another-node', config)));
|
|
55
|
+
assert.ok(['甲', '乙'].includes(new RandomValueGenerator().next('script/node', config)));
|
|
56
|
+
assert.equal(generator.next('script/node', { ...config, text: '新候选' }), '新候选');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('integer bounds, UUID format, input validation and sensitive output', () => {
|
|
60
|
+
const generator = new RandomValueGenerator();
|
|
61
|
+
for (const value of [0, -10, Number.MAX_SAFE_INTEGER]) {
|
|
62
|
+
assert.equal(generator.next('number', { name: 'N', mode: 'integer', min: value, max: value }), String(value));
|
|
63
|
+
}
|
|
64
|
+
assert.match(generator.next('id', { name: 'ID', mode: 'uuid' }), /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
|
|
65
|
+
for (const config of [
|
|
66
|
+
undefined, { name: 'bad name', mode: 'uuid' }, { name: 'X', mode: 'bad' },
|
|
67
|
+
{ name: 'X', mode: 'integer', min: 0.1, max: 2 }, { name: 'X', mode: 'integer', min: 3, max: 2 },
|
|
68
|
+
{ name: 'X', mode: 'integer', min: 0, max: MAX_RANDOM_INTEGER_RANGE },
|
|
69
|
+
{ name: 'X', mode: 'text', text: '# only comments\n ' },
|
|
70
|
+
{ name: 'X', mode: 'text', text: 'a'.repeat(20001) },
|
|
71
|
+
]) assert.throws(() => generator.next('invalid', config as RandomValueConfig));
|
|
72
|
+
const scope = new VariableScope([], []);
|
|
73
|
+
const message = generator.write(scope, 'sensitive', { name: 'password', mode: 'text', text: 'hidden-test-value' });
|
|
74
|
+
assert.equal(scope.privacy.enabled, true);
|
|
75
|
+
assert.ok(!message.includes('hidden-test-value'));
|
|
76
|
+
assert.equal(scope.redact('hidden-test-value'), '[已脱敏]');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('random nodes survive copy, export and batch import, while sensitive TXT pools are removed', async () => {
|
|
80
|
+
const root = await mkdtemp(join(tmpdir(), 'random-node-import-'));
|
|
81
|
+
const previous = process.env.ANDROID_MIDSCENE_DATA_ROOT;
|
|
82
|
+
process.env.ANDROID_MIDSCENE_DATA_ROOT = root;
|
|
83
|
+
try {
|
|
84
|
+
const { saveAppiumRecordedScript, importAppiumRecordedScripts } = await import('./repository');
|
|
85
|
+
const script = saveAppiumRecordedScript({ name: '随机节点', appPackage: 'example.app', steps: [{
|
|
86
|
+
id: 'random', type: 'randomValue', label: '获取随机值',
|
|
87
|
+
randomValue: { name: 'PROMPT', mode: 'text', text: '甲\n乙', sourceName: '话术.txt', withoutReplacement: true },
|
|
88
|
+
}] })!;
|
|
89
|
+
const exported = await createAppiumScriptExport(script, () => null);
|
|
90
|
+
const payload = JSON.parse(exported.body.toString());
|
|
91
|
+
const imported = importAppiumRecordedScripts([{ ...payload.script, id: undefined, sourceId: payload.script.id }])[0]!;
|
|
92
|
+
assert.deepEqual(imported.steps, script.steps);
|
|
93
|
+
const copied = pasteFlowClipboard(script.steps, createFlowClipboard(script.steps, [0]), { afterIndex: 0 });
|
|
94
|
+
assert.notEqual(copied[0]!.id, copied[1]!.id);
|
|
95
|
+
assert.deepEqual(copied[0]!.randomValue, copied[1]!.randomValue);
|
|
96
|
+
assert.equal(defaultFlowKind(copied[1]!), 'action');
|
|
97
|
+
assert.ok(labelFlowStep(copied[1]!).meta.includes('获取随机值'));
|
|
98
|
+
const secretScript: AppiumRecordedScriptRecord = { ...script, steps: [{ ...script.steps[0]!, randomValue: {
|
|
99
|
+
name: 'password', mode: 'text', text: 'private-candidate', sourceName: 'private.txt',
|
|
100
|
+
} }] };
|
|
101
|
+
const secret = await createAppiumScriptExport(secretScript, () => null);
|
|
102
|
+
assert.ok(!secret.body.toString().includes('private-candidate'));
|
|
103
|
+
assert.ok(!secret.body.toString().includes('private.txt'));
|
|
104
|
+
const sanitized = JSON.parse(secret.body.toString());
|
|
105
|
+
assert.equal(sanitized.script.steps[0].randomValue.text, '');
|
|
106
|
+
assert.doesNotThrow(() => importAppiumRecordedScripts([{ ...sanitized.script, id: undefined, sourceId: 'sanitized' }]));
|
|
107
|
+
assert.throws(() => validateRandomValue(sanitized.script.steps[0].randomValue), /填写候选/);
|
|
108
|
+
assert.throws(() => saveAppiumRecordedScript({ name: '无效随机', appPackage: 'example.app', steps: [{ id: 'invalid', type: 'randomValue', label: '无效' }] }));
|
|
109
|
+
} finally {
|
|
110
|
+
if (previous === undefined) delete process.env.ANDROID_MIDSCENE_DATA_ROOT;
|
|
111
|
+
else process.env.ANDROID_MIDSCENE_DATA_ROOT = previous;
|
|
112
|
+
await rm(root, { recursive: true, force: true });
|
|
113
|
+
}
|
|
114
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { randomInt, randomUUID } from 'node:crypto';
|
|
2
|
+
import { randomTextCandidates, validateRandomValue, type RandomValueConfig } from '../../src/appium-recorder/random-value';
|
|
3
|
+
import type { VariableScope } from './variables';
|
|
4
|
+
|
|
5
|
+
/** 每次回放独立创建;同一脚本节点被循环或连接脚本多次调用时共用抽取记录。 */
|
|
6
|
+
export class RandomValueGenerator {
|
|
7
|
+
private readonly pools = new Map<string, { text: string; remaining: string[] }>();
|
|
8
|
+
|
|
9
|
+
next(key: string, input: RandomValueConfig | undefined): string {
|
|
10
|
+
const config = validateRandomValue(input);
|
|
11
|
+
if (config.mode === 'uuid') return randomUUID();
|
|
12
|
+
if (config.mode === 'integer') return String(config.min! + randomInt(0, config.max! - config.min! + 1));
|
|
13
|
+
const candidates = randomTextCandidates(config.text);
|
|
14
|
+
if (!config.withoutReplacement) return candidates[randomInt(candidates.length)]!;
|
|
15
|
+
let pool = this.pools.get(key);
|
|
16
|
+
if (!pool || pool.text !== config.text) {
|
|
17
|
+
pool = { text: config.text!, remaining: [...new Set(candidates)] };
|
|
18
|
+
this.pools.set(key, pool);
|
|
19
|
+
}
|
|
20
|
+
if (!pool.remaining.length) throw new Error(`随机值节点 ${config.name} 的候选已耗尽;请增加候选或允许重复抽取`);
|
|
21
|
+
const index = randomInt(pool.remaining.length);
|
|
22
|
+
const value = pool.remaining[index]!;
|
|
23
|
+
pool.remaining[index] = pool.remaining[pool.remaining.length - 1]!;
|
|
24
|
+
pool.remaining.pop();
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
write(scope: VariableScope, key: string, config: RandomValueConfig | undefined) {
|
|
29
|
+
const value = this.next(key, config);
|
|
30
|
+
// 候选中出现 {{…}} 时按普通文字保存,后续多次引用也不会重新抽取或递归插值。
|
|
31
|
+
scope.set({ name: config!.name, value, sensitive: config!.sensitive }, true);
|
|
32
|
+
return `已获取随机值并写入脚本变量:${config!.name} = ${scope.redact(value)}`;
|
|
33
|
+
}
|
|
34
|
+
}
|