tidevice常用命令大全
网址指引:
WebDriverAgent github(https://github.com/appium/WebDriverAgent)
tidevice github(https://github.com/alibaba/tidevice)
tidevice3 github(https://github.com/codeskyblue/tidevice3)
pymobiledevice3 github(https://github.com/doronz88/pymobiledevice3)
安装
使用python的pip安装tidevice
pip install tidevice电脑需要安装并启动 Itunes
启动WebDriverAgent
运行 XCTest 并在PC上监听8200端口转发到手机8100服务,这个命令会同时调用xctest和relay,另外当wda退出时,会自动重新启动xctest
请先确保手机上已经安装有WebDriverAgent应用
tidevice wdaproxy -B 你的WDA包名 --port 8200运行该命令后终端不能退出,需要一直开着监听
目前已知的几个问题:
不支持运行企业证书签名的WDA
数据线可能导致wda连接中断。Github 作者用的数据线(推荐): https://item.jd.com/44473991638.html
ios17+无法使用
安装WebDriverAgent
前提:必须使用MacOS系统
# 克隆 WebDriverAgent 源码
git clone https://github.com/appium/WebDriverAgent.git
# 打开项目
cd WebDriverAgent
open WebDriverAgent.xcodeproj步骤如下:
安装Xcode,并连接 IOS 真机设备。确保 Xcode 的版本兼容IOS 设备版本,并准备一个 Apple 开发者账号(个人免费账号也可)。
从github中克隆项目,使用 Xcode 打
WebDriverAgent.xcodeproj文件。点击左边项目目录的项目名,一般为 WebDriverAgent,此动作目的是为了打开项目配置中的 TARGETS 栏去配置证书
在 Xcode 的 TARGETS 中选择
WebDriverAgentRunner,进入Signing & Capabilities一栏并登录 Apple 开发者账号并启用自动签名。如果使用个人免费证书,需修改BundleID为唯一值,例如添加时间戳。在正上方选择目标设备为连接的 iOS 真机,点击左上方的菜单栏(在MacOS的菜单栏里面)中的 Product -> Test 开始编译和安装。完成后,在设备上信任开发者证书(设置 -> 通用 -> VPN与设备管理)。
查看真机是否安装了WebDriverAgent,并且处于Automation Running的状态。在浏览器中访问 http://[设备IP]:8100/status,如果返回类似 WebDriverAgent is running 的信息,则说明安装成功。
设备相关
列出已连接的设备
tidevice list
tidevice list --json查看设备信息
tidevice info
# 查看设备电源信息
tidevice info --domain com.apple.mobile.battery --json配对设备
tidevice pair取消配对设备
tidevice unpair重启
tidevice并不支持关机
tidevice reboot截图
tidevice screenshot screenshot.jpg输出日志
tidevice syslogAPP(ipa)相关
安装应用
# 为一台设备安装ipa,只适用于这台电脑插一台设备的情况
tidevice install example.ipa
# 指定设备安装
tidevice --u $UDID install https://example.org/example.ipa卸载应用
tidevice uninstall com.example.demo启动应用
tidevice launch com.example.demo停止应用
tidevice kill com.example.demo查看已安装应用
tidevice applist查看运行中的应用
tidevice ps
tidevice ps --json output as json文件相关
列出文件夹的内容
tidevice ls /path/to/dir列出 App 中的文件夹的内容
tidevice fsync -B com.t3go.passenger ls /Documents/从设备中提取文件到电脑
# 拉取单个文件
tidevice pull /path/on/device/file.txt ./local_directory/
# 拉取整个目录
tidevice pull /path/on/device/folder ./local_folder/
# 拉取并重命名
tidevice pull /path/on/device/photo.jpg ./renamed_photo.jpg向设备推送文件/目录
# 推送单个文件
tidevice push ./local_file.txt /path/on/device/
# 推送整个目录
tidevice push ./local_folder/ /path/on/device/folder
# 推送并重命名
tidevice push ./local_file.txt /path/on/device/new_name.txt查看文件/目录状态信息
# 查看文件状态
tidevice stat /path/on/device/file.txt
# 查看目录状态
tidevice stat /path/on/device/folder删除文件
# 删除单个文件
tidevice rm /path/on/device/file.txt
# 删除多个文件
tidevice rm /path/file1.txt /path/file2.txt
# 使用通配符(注意:通配符需要在shell中正确转义)
tidevice rm "/path/*.tmp"递归删除目录
# 删除整个目录(包括所有子目录和文件)
tidevice rmtree /path/on/device/folder
# 删除多个目录
tidevice rmtree /path/folder1 /path/folder2创建目录
# 创建单个目录
tidevice mkdir /path/on/device/new_folder
# 创建多级目录(类似 mkdir -p)
tidevice mkdir /path/on/device/deep/nested/folder
# 创建多个目录
tidevice mkdir /path/folder1 /path/folder2查看文件内容
# 查看文件内容
tidevice cat /path/on/device/config.txt
# 查看日志文件
tidevice cat /var/mobile/Containers/Data/Application/UDID/Documents/app.log
# 结合grep等工具使用(在本地shell中处理)
tidevice cat /path/file.log | grep "error"查看文件/目录状态信息
# 查看文件状态
tidevice stat /path/on/device/file.txt
# 查看目录状态
tidevice stat /path/on/device/folderios 17+支持
目前tidevice只支持ios 17以下版本,若想要使用ios 17+以上版本的查询等,请用tidevice3,它封装了pymobiledevice3,让命令更好用,安装方法如下:
pip install tidevice3