关于 harmony-hdc
Harmony HDC 是使用原始 hdc 命令控制 HarmonyOS 设备的参考技能,面向设备测试与调试操作。它整理了设备连接、应用管理、输入、截图、界面树和文件传输命令,并强调多设备选择及执行前检查。
主要功能
- 01连接设备并查询设备状态
- 02启动和管理应用
- 03执行点击、长按及文本输入
- 04截图并导出界面树
- 05在设备间传输文件
适用场景
- 01检查 HarmonyOS 设备信息与屏幕尺寸
- 02启动应用并执行界面操作
- 03采集截图和 UI 布局用于检查
- 04在本地与设备之间传送文件
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ httprunner/ skills --skill harmony-hdc安装后在 Claude Code 中输入/harmony-hdc确认已加载。
详细介绍
Harmony HDC
使用原始 hdc 命令控制 HarmonyOS 设备的参考指南。
执行限制
- 连接了多个设备时,使用
hdc -t <device_id>。 - 执行坐标操作前,确认屏幕分辨率:
hdc -t DEVICE shell wm size。 - 执行前询问缺少的必需输入(设备 ID、bundle/ability、坐标、文件路径)。
- 失败时提供可采取操作的标准错误信息(授权、电缆/网络、tcp 模式)。
设备和服务端
# Start HDC server
hdc start
# Stop HDC server
hdc kill
# List targets
hdc list targets
# Target a specific device
hdc -t DEVICE <command>
连接
# Connect over TCP
hdc tconn <ip>:<port>
# Disconnect target
hdc -t DEVICE tdis
设备状态
# Device model/system info
hdc -t DEVICE shell param get const.product.model
hdc -t DEVICE shell param get const.ohos.fullname
# Screen size
hdc -t DEVICE shell wm size
# Foreground focus window
hdc -t DEVICE shell hidumper -s WindowManagerService -a '-a'
# Run raw shell command
hdc -t DEVICE shell <command>
应用生命周期
# List installed bundles
hdc -t DEVICE shell bm dump -a
# Start an ability
hdc -t DEVICE shell aa start -a <ability_name> -b <bundle_name>
# Start by URI
hdc -t DEVICE shell aa start -U <uri>
# Force-stop app by bundle
hdc -t DEVICE shell aa force-stop <bundle_name>
输入操作
# Tap
hdc -t DEVICE shell uitest uiInput click X Y
# Double tap
hdc -t DEVICE shell uitest uiInput click X Y && sleep 0.1 && hdc -t DEVICE shell uitest uiInput click X Y
# Long press
hdc -t DEVICE shell uitest uiInput longClick X Y
# Swipe
hdc -t DEVICE shell uitest uiInput swipe X1 Y1 X2 Y2 [duration_ms]
# Key event
hdc -t DEVICE shell uitest uiInput keyEvent Back
hdc -t DEVICE shell uitest uiInput keyEvent Home
hdc -t DEVICE shell uitest uiInput keyEvent Enter
文本输入
# Text input (Harmony text input supports UTF-8)
hdc -t DEVICE shell uitest uiInput inputText "hello world"
屏幕截图和 UI 转储
# Capture screenshot on device
hdc -t DEVICE shell snapshot_display -f /data/local/tmp/screen.jpeg
# Pull screenshot to local
hdc -t DEVICE file recv /data/local/tmp/screen.jpeg ./screen.jpeg
# Dump UI tree (JSON)
hdc -t DEVICE shell uitest dumpLayout -p /data/local/tmp/layout.json
hdc -t DEVICE file recv /data/local/tmp/layout.json ./layout.json
文件传输
# Push file to device
hdc -t DEVICE file send ./local.file /data/local/tmp/remote.file
# Pull file from device
hdc -t DEVICE file recv /data/local/tmp/remote.file ./remote.file
应用安装和卸载
# Install HAP
hdc -t DEVICE install /path/to/app.hap
# Install with replace
hdc -t DEVICE install -r /path/to/app.hap
# Uninstall by bundle
hdc -t DEVICE uninstall <bundle_name>
常见 KeyEvents
| KeyEvent | 描述 |
|---|---|
Back | 返回按钮 |
Home | 主页按钮 |
Enter | 输入/确认 |
Power | 电源按钮 |
VolumeUp | 音量增大 |
VolumeDown | 音量减小 |
评论
支持 Markdown