axe-ios-simulator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

AXe iOS Simulator Automation

AXe iOS Simulator 自动化

AXe is a single-binary CLI for iOS Simulator automation via Apple's Accessibility APIs and HID.
AXe是一个单二进制文件的CLI工具,通过Apple的无障碍API和HID实现iOS Simulator自动化。

Installation

安装

bash
brew install cameroncooke/axe/axe
bash
brew install cameroncooke/axe/axe

Quick Start

快速开始

bash
undefined
bash
undefined

Get simulator UDID

获取模拟器UDID

axe list-simulators UDID="<simulator-udid>"
axe list-simulators UDID="<simulator-udid>"

Basic interactions

基础交互

axe tap -x 100 -y 200 --udid $UDID axe tap --label "Safari" --udid $UDID axe type 'Hello World!' --udid $UDID axe gesture scroll-down --udid $UDID axe button home --udid $UDID axe screenshot --udid $UDID
undefined
axe tap -x 100 -y 200 --udid $UDID axe tap --label "Safari" --udid $UDID axe type 'Hello World!' --udid $UDID axe gesture scroll-down --udid $UDID axe button home --udid $UDID axe screenshot --udid $UDID
undefined

Touch & Gestures

触摸与手势

bash
undefined
bash
undefined

Tap at coordinates

按坐标点击

axe tap -x 100 -y 200 --udid $UDID
axe tap -x 100 -y 200 --udid $UDID

Tap by accessibility identifier or label

按无障碍标识符或标签点击

axe tap --id "myButton" --udid $UDID axe tap --label "Submit" --udid $UDID
axe tap --id "myButton" --udid $UDID axe tap --label "Submit" --udid $UDID

With timing controls

带时间控制的点击

axe tap -x 100 -y 200 --pre-delay 1.0 --post-delay 0.5 --udid $UDID
axe tap -x 100 -y 200 --pre-delay 1.0 --post-delay 0.5 --udid $UDID

Swipe

滑动操作

axe swipe --start-x 100 --start-y 300 --end-x 300 --end-y 100 --udid $UDID axe swipe --start-x 50 --start-y 500 --end-x 350 --end-y 500 --duration 2.0 --delta 25 --udid $UDID
axe swipe --start-x 100 --start-y 300 --end-x 300 --end-y 100 --udid $UDID axe swipe --start-x 50 --start-y 500 --end-x 350 --end-y 500 --duration 2.0 --delta 25 --udid $UDID

Low-level touch control

底层触摸控制

axe touch -x 150 -y 250 --down --udid $UDID axe touch -x 150 -y 250 --up --udid $UDID axe touch -x 150 -y 250 --down --up --delay 1.0 --udid $UDID
undefined
axe touch -x 150 -y 250 --down --udid $UDID axe touch -x 150 -y 250 --up --udid $UDID axe touch -x 150 -y 250 --down --up --delay 1.0 --udid $UDID
undefined

Gesture Presets

手势预设

PresetUse Case
scroll-up
Content navigation
scroll-down
Content navigation
scroll-left
Horizontal scrolling
scroll-right
Horizontal scrolling
swipe-from-left-edge
Back navigation
swipe-from-right-edge
Forward navigation
swipe-from-top-edge
Dismiss/close
swipe-from-bottom-edge
Open/reveal
bash
axe gesture scroll-down --udid $UDID
axe gesture swipe-from-left-edge --udid $UDID
axe gesture scroll-up --screen-width 430 --screen-height 932 --udid $UDID
axe gesture scroll-down --pre-delay 1.0 --post-delay 0.5 --udid $UDID
预设值适用场景
scroll-up
内容导航
scroll-down
内容导航
scroll-left
横向滚动
scroll-right
横向滚动
swipe-from-left-edge
返回导航
swipe-from-right-edge
前进导航
swipe-from-top-edge
关闭/取消
swipe-from-bottom-edge
打开/显示
bash
axe gesture scroll-down --udid $UDID
axe gesture swipe-from-left-edge --udid $UDID
axe gesture scroll-up --screen-width 430 --screen-height 932 --udid $UDID
axe gesture scroll-down --pre-delay 1.0 --post-delay 0.5 --udid $UDID

Text Input

文本输入

bash
undefined
bash
undefined

Direct text (use single quotes for special characters)

直接输入文本(特殊字符使用单引号)

axe type 'Hello World!' --udid $UDID
axe type 'Hello World!' --udid $UDID

From stdin (best for automation)

从标准输入读取(最适合自动化场景)

echo "Complex text" | axe type --stdin --udid $UDID
echo "Complex text" | axe type --stdin --udid $UDID

From file

从文件读取输入

axe type --file input.txt --udid $UDID
axe type --file input.txt --udid $UDID

Individual key press by HID keycode

通过HID键码单独按键

axe key 40 --udid $UDID # Enter key axe key 42 --duration 1.0 --udid $UDID # Hold Backspace
axe key 40 --udid $UDID # 回车键 axe key 42 --duration 1.0 --udid $UDID # 长按退格键

Key sequence

按键序列

axe key-sequence --keycodes 11,8,15,15,18 --udid $UDID # "hello"
undefined
axe key-sequence --keycodes 11,8,15,15,18 --udid $UDID # 输入"hello"
undefined

Hardware Buttons

硬件按钮操作

bash
axe button home --udid $UDID
axe button lock --duration 2.0 --udid $UDID
axe button side-button --udid $UDID
axe button siri --udid $UDID
axe button apple-pay --udid $UDID
bash
axe button home --udid $UDID
axe button lock --duration 2.0 --udid $UDID
axe button side-button --udid $UDID
axe button siri --udid $UDID
axe button apple-pay --udid $UDID

Screenshot & Video

截图与录屏

bash
undefined
bash
undefined

Screenshot (auto-generates filename)

截图(自动生成文件名)

axe screenshot --udid $UDID
axe screenshot --udid $UDID

Screenshot to specific path

截图到指定路径

axe screenshot --output ~/Desktop/screenshot.png --udid $UDID
axe screenshot --output ~/Desktop/screenshot.png --udid $UDID

Video recording to MP4

录制MP4视频

axe record-video --udid $UDID --fps 15 --output recording.mp4 axe record-video --udid $UDID --fps 10 --quality 60 --scale 0.5 --output low-bandwidth.mp4
axe record-video --udid $UDID --fps 15 --output recording.mp4 axe record-video --udid $UDID --fps 10 --quality 60 --scale 0.5 --output low-bandwidth.mp4

Stream MJPEG

流式传输MJPEG

axe stream-video --udid $UDID --fps 10 --format mjpeg > stream.mjpeg
axe stream-video --udid $UDID --fps 10 --format mjpeg > stream.mjpeg

Pipe to ffmpeg

管道传输到ffmpeg

axe stream-video --udid $UDID --fps 30 --format ffmpeg |
ffmpeg -f image2pipe -framerate 30 -i - -c:v libx264 -preset ultrafast output.mp4

Press `Ctrl+C` to stop recording. AXe finalizes MP4 and prints path to stdout.
axe stream-video --udid $UDID --fps 30 --format ffmpeg |
ffmpeg -f image2pipe -framerate 30 -i - -c:v libx264 -preset ultrafast output.mp4

按下`Ctrl+C`停止录制。AXe会完成MP4文件的生成,并在标准输出中打印文件路径。

Accessibility Inspection

无障碍检查

bash
undefined
bash
undefined

Full screen accessibility tree

全屏无障碍树

axe describe-ui --udid $UDID
axe describe-ui --udid $UDID

Accessibility info at specific point

指定位置的无障碍信息

axe describe-ui --point 100,200 --udid $UDID
undefined
axe describe-ui --point 100,200 --udid $UDID
undefined

Automation Patterns

自动化模式

Wait-then-tap pattern

等待后点击模式

bash
axe tap --label "Continue" --pre-delay 2.0 --udid $UDID
bash
axe tap --label "Continue" --pre-delay 2.0 --udid $UDID

Scroll to find element

滚动查找元素

bash
for i in {1..5}; do
  axe describe-ui --udid $UDID | grep -q "targetElement" && break
  axe gesture scroll-down --udid $UDID
done
axe tap --label "targetElement" --udid $UDID
bash
for i in {1..5}; do
  axe describe-ui --udid $UDID | grep -q "targetElement" && break
  axe gesture scroll-down --udid $UDID
done
axe tap --label "targetElement" --udid $UDID

Form filling

表单填充

bash
axe tap --label "Email" --udid $UDID
axe type 'user@example.com' --udid $UDID
axe tap --label "Password" --udid $UDID
axe type 'secret123' --udid $UDID
axe tap --label "Sign In" --udid $UDID
bash
axe tap --label "Email" --udid $UDID
axe type 'user@example.com' --udid $UDID
axe tap --label "Password" --udid $UDID
axe type 'secret123' --udid $UDID
axe tap --label "Sign In" --udid $UDID

Screenshot after action

操作后截图

bash
axe tap --label "Submit" --post-delay 1.0 --udid $UDID
axe screenshot --output result.png --udid $UDID
bash
axe tap --label "Submit" --post-delay 1.0 --udid $UDID
axe screenshot --output result.png --udid $UDID