导语
AI UI 自动化测试是基于计算机视觉、自然语言处理与机器学习技术,赋能 iOS 应用 UI 层自动化验证的新一代测试方案。它摒弃了传统 UI 自动化对硬编码脚本的依赖,通过智能化手段实现 “用例生成 - 执行 - 结果分析” 的端到端自动化,有效解决了 iOS 多机型 / 多版本适配难、脚本维护成本高、测试覆盖度不足等问题,成为推动研发自测与 QA 测试提效的核心工具。
大纲
-
概述
-
开发流程概览
-
崩溃处理与修复步骤
-
UI 自动化测试
-
API Key 使用方式
-
URL 配置说明(含参考链接)
-
标准使用说明(简要)
-
iOS 配置(WDA)
-
产出清单
-
结论
1. 概述
Open‑AutoGLM 是面向移动端 GUI 的自动化智能体系统,支持 Android(ADB)、HarmonyOS(HDC)与 iOS(WebDriverAgent)。
本次开发重点:解决 iOS Simulator SwiftUI/AttributeGraph 崩溃,并通过 UI 自动化测试 验证稳定性。
提示词:UI 自动化测试
强调:在该流程下,AI 可替代 QA 的测试工作与研发的自测工作,全链路完成 iOS 开发与验证。
2. 开发流程概览(以 UI 自动化测试为核心)
-
收到 iOS Simulator 崩溃日志(EXC_BAD_ACCESS / SwiftUI / AttributeGraph)
-
识别可能触发布局递归的视图点
-
收敛布局复杂度并修复可访问性
-
多轮 UI 自动化测试(xcodebuild + XCTest)验证稳定性
-
输出可发布使用文档与技术文档(含 iOS 配置)
3. 崩溃处理与修复步骤
3.1 崩溃现象
-
崩溃:
EXC_BAD_ACCESS -
线程:主线程
-
栈:SwiftUI / AttributeGraph
-
触发点:UI 渲染 / 布局过程
3.2 定位思路
重点排查:
-
GeometryReader+Path -
maxHeight: .infinity -
复杂 Overlay / Layer 链接
-
ScrollView 内部无限尺寸
3.3 修复动作
-
修正
overlay调用为.overlay(避免 modifier 链断裂) -
SessionReplay 时间线:
- frame(maxHeight: .infinity) → 固定高度
- LatencyChart:
- 移除 GeometryReader + Path
- 替换为固定高度柱状图
-
SessionReplay 页面改为
accessibilityElement(children: .contain)确保子元素可访问
4. UI 自动化测试(核心验证环节)
4.1 测试命令
xcodebuild -project AutoglmApp.xcodeproj \
-scheme AutoglmApp \
-destination "platform=iOS Simulator,name=iPhone 16 Pro" \
-derivedDataPath /tmp/autoglm-dd \
clean test
4.2 测试覆盖
-
首页加载(标题、按钮)
-
深度页面导航(Diagnostics / Agent Profile / Latency / Security / Session Replay)
-
每个页面的关键文本存在性校验
4.3 自动化测试流程(实操步骤)
-
使用
xcodebuild clean test在 iOS Simulator(iPhone 16 Pro)上执行 UI 测试。 -
测试包含:
- 首页加载断言(标题与按钮可见)
- 深度页面导航(Diagnostics / Agent Profile / Latency / Security / Session Replay)
- 各页面关键文案存在性断言
-
每次修改后重复执行
clean test确保无回归。 -
测试通过后记录结果:
2 tests, 0 failures。
4.4 测试结果
-
多轮执行均通过
-
最终结果:2 tests, 0 failures
5. API Key 使用方式
5.1 命令行方式
python main.py --apikey sk-xxxxx
5.2 结合模型服务使用
python main.py --base-url https://open.bigmodel.cn/api/paas/v4 \
--model "autoglm-phone-9b" \
--apikey sk-xxxxx \
"打开美团搜索附近的火锅店"
5.3 iOS 方式(WDA)
python ios.py --base-url "https://open.bigmodel.cn/api/paas/v4" \
--model "autoglm-phone" \
--api-key "YOUR_API_KEY" \
--wda-url http://localhost:8100 \
"TASK"
6. URL 配置说明(含参考链接)
6.1 必要 URL 一览(完整示例)
-
模型服务 URL(
--base-url):https://open.bigmodel.cn/api/paas/v4 -
iOS WebDriverAgent URL(
--wda-url):http://localhost:8100(USB + iproxy)或http://192.168.1.100:8100(Wi‑Fi)
6.2 模型服务 URL 配置
python main.py --base-url https://open.bigmodel.cn/api/paas/v4 --model "autoglm-phone-9b" "TASK"
可选环境变量:
export PHONE_AGENT_BASE_URL=https://open.bigmodel.cn/api/paas/v4
export PHONE_AGENT_MODEL=autoglm-phone-9b
6.3 iOS WDA URL 配置
USB 模式端口映射:
iproxy 8100 8100
然后使用:
--wda-url http://localhost:8100
Wi‑Fi 模式使用 Xcode / xcodebuild 输出:
ServerURLHere->http://192.168.1.100:8100<-ServerURLHere
然后使用:
--wda-url http://192.168.1.100:8100
6.4 参考链接
WebDriverAgent 官方仓库:
https://github.com/appium/WebDriverAgent
Open‑AutoGLM 主仓库:
https://github.com/zai-org/Open-AutoGLM
iOS MVP Git 仓库:
https://gitee.com/hhfa008/autoglm-ios-mvp
iOS 支持 PR:
https://github.com/zai-org/Open-AutoGLM/pull/141
Gekowa iOS 方案:
https://github.com/gekowa/Open-AutoGLM/tree/ios-support
6.5 相关的文汇总
6.6 结合官方文档(AutoGLM-Phone)补充说明
以下内容基于官方文档页面整理,用于补全模型能力与配置步骤:
模型定位与输入输出
-
AutoGLM-Phone 是基于视觉语言模型的 AI 手机智能助理框架,通过 ADB 自动操控 Android 设备。
-
输入:任务指令;输出:任务行动完成。
-
支持语言:中文;支持设备:Android 手机。
典型场景
-
外卖选购、商品购买、出行服务、资讯新闻、租房找房等。
-
示例任务包含外卖下单、商品比价、路线规划、票务预订等。
可执行操作
支持:Launch / Tap / Type / Swipe / Back / Home / Long Press / Double Tap / Wait / Take_over。
环境准备(官方步骤摘要)
-
Python 3.10+
-
ADB 安装与环境变量配置
-
Android 设备开启开发者选项与 USB 调试
-
安装并启用 ADB Keyboard
部署准备(官方步骤摘要)
-
克隆仓库:
git clone https://github.com/zai-org/Open-AutoGLM.git -
安装依赖:
pip install -r requirements.txt,pip install -e . -
连接设备:
adb devices -
配置模型 API:
python main.py --base-url https://open.bigmodel.cn/api/paas/v4 --model "autoglm-phone" --apikey "你的apikey" "打开美团搜索附近的火锅店"
6.7 准备环境(最小可用)
6.7.1 通用环境
-
Python 3.10+
-
网络可访问模型服务:
https://open.bigmodel.cn/api/paas/v4 -
获取可用 API Key
6.7.2 Android(ADB)
-
安装 ADB,并配置到系统 PATH
-
手机开启开发者选项与 USB 调试
-
连接设备并确认:
adb devices
-
安装并启用 ADB Keyboard(用于文本输入)
6.7.3 HarmonyOS(HDC)
-
安装 HDC,并配置到系统 PATH
-
设备开启开发者选项与 USB 调试
-
连接设备并确认:
hdc list targets
6.7.4 iOS(WebDriverAgent)
-
macOS + Xcode + 开发者账号
-
克隆并配置 WebDriverAgent(签名与信任)
-
通过 Xcode 或 xcodebuild 部署 WebDriverAgentRunner
-
USB 模式下启用端口映射:
iproxy 8100 8100
7. 标准使用说明(简要)
7.1 CLI 使用
python main.py --base-url https://open.bigmodel.cn/api/paas/v4 --model "autoglm-phone-9b"
python main.py --base-url https://open.bigmodel.cn/api/paas/v4 "打开美团搜索附近的火锅店"
7.2 Python API
from phone_agent import PhoneAgent
from phone_agent.model import ModelConfig
agent = PhoneAgent(model_config=ModelConfig(
base_url="https://open.bigmodel.cn/api/paas/v4",
model_name="autoglm-phone-9b",
))
agent.run("打开淘宝搜索无线耳机")
7.3 我与 AutoGLM 的交互方式(按实际操作)
7.3.1 命令行交互
-
通过
python main.py ... "任务"直接下达任务文本 -
示例(以 UI 自动化测试 为任务):
python main.py --base-url https://open.bigmodel.cn/api/paas/v4 --model "autoglm-phone-9b" "进行UI自动化测试:打开应用并验证首页与深度页面"
7.3.2 Python API 交互
-
通过
PhoneAgent创建实例,调用agent.run("任务") -
示例(以 UI 自动化测试 为任务):
from phone_agent import PhoneAgent
from phone_agent.model import ModelConfig
agent = PhoneAgent(model_config=ModelConfig(
base_url="https://open.bigmodel.cn/api/paas/v4",
model_name="autoglm-phone-9b",
))
agent.run("进行UI自动化测试:打开应用并验证首页与深度页面")
7.3.3 iOS WDA 交互(iOS 设备)
-
通过
python ios.py+--wda-url与 WebDriverAgent 建立连接 -
示例(以 UI 自动化测试 为任务):
python ios.py --base-url "https://open.bigmodel.cn/api/paas/v4" \
--model "autoglm-phone" \
--api-key "YOUR_API_KEY" \
--wda-url http://localhost:8100 \
"进行UI自动化测试:打开应用并验证首页与深度页面"
8. iOS 配置(WDA)
-
配置 WebDriverAgent(签名、信任、UI 自动化)
-
USB 端口映射:
iproxy 8100 8100
- 启动 iOS:
python ios.py --base-url "https://open.bigmodel.cn/api/paas/v4" \
--model "autoglm-phone" \
--api-key "YOUR_API_KEY" \
--wda-url http://localhost:8100 \
"TASK"
9. 结论
本次流程完成:
-
崩溃风险显著降低
-
UI 自动化测试确认稳定
-
文档交付可发布
结论:本次以 UI 自动化测试 为核心的修复与验证流程已闭环完成,AutoGLM 可按文档配置与运行,且在 iOS Simulator 场景下通过多轮自动化测试确认稳定。
Git 仓库:https://gitee.com/hhfa008/autoglm-ios-mvp