mcpField
I
ios-app-tester

ios-app-tester

github.com/ckorhonen测试与质量2254 次安装5 周前更新
代码仓库

关于 ios-app-tester

iOS App Tester 是一项使用 AXe 命令行工具测试和自动化 iOS Simulator 应用的 skill,涵盖界面操作、无障碍检查、视频录制、脚本化测试和 CI/CD 流程。

主要功能

  1. 01自动执行模拟器触控与文本输入
  2. 02检查无障碍界面元素
  3. 03录制或串流模拟器视频
  4. 04支持脚本化测试步骤
  5. 05介绍 CI/CD 测试设置

适用场景

  1. 01自动执行模拟器登录流程
  2. 02审查无障碍标签
  3. 03录制视频以排查测试问题
  4. 04将界面检查加入 CI/CD

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/ckorhonen/claude-skills --skill ios-app-tester

安装后在 Claude Code 中输入/ios-app-tester确认已加载。

详细介绍

iOS 应用测试器(AXe CLI)

概述

使用 AXe 测试和自动化 iOS 模拟器应用。AXe 是一款利用 Apple 辅助功能 API 以编程方式控制模拟器的命令行工具。AXe 以单个二进制文件运行,无需设置服务。

适用场景

  • 自动化 iOS 模拟器 UI 交互以进行测试
  • 审查辅助功能标签和 VoiceOver 描述
  • 录制测试执行视频
  • 编写可重复的测试场景脚本
  • 集成到 CI/CD 流水线中进行 iOS 测试

前提条件

  • 安装了 Xcode 的 macOS
  • iOS 模拟器(随 Xcode 提供)
  • Homebrew(用于安装)

安装

brew tap cameroncooke/axe
brew install axe

验证安装:

axe --help

快速开始

  1. 查找模拟器 UDID:
axe list-simulators
  1. 点击某个坐标:
axe tap -x 200 -y 400 --udid <SIMULATOR_UDID>
  1. 检查辅助功能元素:
axe describe-ui --udid <SIMULATOR_UDID>

命令参考

模拟器发现
# List all available simulators with UDIDs
axe list-simulators
触摸交互
# Tap at coordinates
axe tap -x 100 -y 200 --udid <UDID>

# Swipe gesture
axe swipe --start-x 100 --start-y 500 --end-x 100 --end-y 200 --udid <UDID>

# Low-level touch events
axe touch-down -x 100 -y 200 --udid <UDID>
axe touch-up -x 100 -y 200 --udid <UDID>
预设手势
# Scrolling
axe gesture scroll-up --udid <UDID>
axe gesture scroll-down --udid <UDID>
axe gesture scroll-left --udid <UDID>
axe gesture scroll-right --udid <UDID>

# Edge swipes (for navigation)
axe gesture swipe-from-left-edge --udid <UDID>
axe gesture swipe-from-right-edge --udid <UDID>
axe gesture swipe-from-top-edge --udid <UDID>
axe gesture swipe-from-bottom-edge --udid <UDID>
文本输入
# Type text directly
axe type 'Hello World!' --udid <UDID>

# Type from stdin (useful for passwords/sensitive data)
echo "secret" | axe type --stdin --udid <UDID>

# Type from file
axe type --file input.txt --udid <UDID>
硬件按钮
# Home button
axe button home --udid <UDID>

# Lock/power button
axe button lock --udid <UDID>

# Long press (e.g., for Siri)
axe button lock --duration 2.0 --udid <UDID>

# Side button
axe button side --udid <UDID>

# Apple Pay
axe button apple-pay --udid <UDID>
辅助功能检查
# Describe all UI elements (full screen)
axe describe-ui --udid <UDID>

# Describe element at specific point
axe describe-ui --point 100,200 --udid <UDID>
视频录制
# Record to MP4 file
axe record-video --udid <UDID> --fps 15 --output test-recording.mp4

# Stream video (for ffmpeg piping)
axe stream-video --udid <UDID> --fps 30 --format ffmpeg | ffmpeg -i - output.mp4

# Stream as MJPEG
axe stream-video --udid <UDID> --fps 10 --format mjpeg > stream.mjpeg
时间控制

所有命令都支持延迟,以便按顺序执行:

# Wait before action
axe tap -x 100 -y 200 --pre-delay 1.0 --udid <UDID>

# Wait after action
axe tap -x 100 -y 200 --post-delay 0.5 --udid <UDID>

# Combined delays
axe type 'text' --pre-delay 0.5 --post-delay 1.0 --udid <UDID>

辅助功能测试工作流

1. 审查整个屏幕
# Get all accessibility elements
axe describe-ui --udid <UDID> > accessibility-audit.txt

检查输出,留意:

  • 缺少 accessibilityLabel 值
  • “button”或“image”等通用标签
  • 复杂操作缺少 accessibilityHint
  • 不正确的 accessibilityTraits
2. 基于坐标检查
# Check specific element
axe describe-ui --point 200,400 --udid <UDID>
3. VoiceOver 模拟脚本
#!/bin/bash
UDID="YOUR_SIMULATOR_UDID"

# Navigate through app elements
axe gesture swipe-from-left-edge --udid $UDID --post-delay 1.0
axe describe-ui --udid $UDID

axe tap -x 200 -y 400 --udid $UDID --post-delay 0.5
axe describe-ui --udid $UDID

自动化示例

#!/bin/bash
UDID="YOUR_SIMULATOR_UDID"

# Login flow automation
echo "Starting login test..."

# Tap email field
axe tap -x 200 -y 300 --udid $UDID --post-delay 0.3

# Type email
axe type '[email protected]' --udid $UDID --post-delay 0.3

# Tap password field
axe tap -x 200 -y 380 --udid $UDID --post-delay 0.3

# Type password (from stdin for security)
echo "password123" | axe type --stdin --udid $UDID --post-delay 0.3

# Tap login button
axe tap -x 200 -y 480 --udid $UDID --post-delay 2.0

# Verify result - check for expected element
axe describe-ui --udid $UDID | grep -q "Welcome" && echo "Login successful"

CI/CD 集成

# GitHub Actions example
- name: Run iOS UI Tests
  run: |
    # Boot simulator
    xcrun simctl boot "iPhone 15"
    UDID=$(xcrun simctl list devices | grep "iPhone 15" | grep -oE '[A-F0-9-]{36}')

    # Install app
    xcrun simctl install $UDID ./build/MyApp.app
    xcrun simctl launch $UDID com.example.myapp

    # Run AXe tests
    axe describe-ui --udid $UDID > accessibility-report.txt

    # Record test
    axe record-video --udid $UDID --fps 10 --output test.mp4 &
    VIDEO_PID=$!

    # Run automation script
    ./test-scripts/login-flow.sh $UDID

    kill $VIDEO_PID

故障排除

“未找到模拟器”
# Ensure simulator is booted
xcrun simctl boot "iPhone 15"

# Get correct UDID
axe list-simulators
“权限被拒绝”
# Grant accessibility permissions in System Preferences
# Security & Privacy > Privacy > Accessibility
命令无响应
# Ensure app is in foreground
xcrun simctl launch <UDID> <BUNDLE_ID>

# Add delays between commands
axe tap -x 100 -y 200 --post-delay 1.0 --udid <UDID>

最佳实践

  • 始终在命令之间使用 --post-delay,以提高可靠性
  • 在脚本中将 UDID 存储到环境变量
  • 在操作前后使用 describe-ui 验证状态
  • 在测试运行期间录制视频,以便调试
  • 通过 stdin 输入敏感文本,不要将其作为命令行参数
  • 将辅助功能审查纳入 CI/CD 流水线

评论

支持 Markdown