IOS在Windows自动化测试之tidevice

IOS在Windows自动化测试之tidevice,第1张

前提安装了一下工具:
1、Windows上配置了Python环境:Python 3.6+
2、Windows上安装了iTunes

IOS在Windows自动化测试之tidevice

tidevice地址

一、安装tidevice库
pip3 install -U "tidevice[openssl]"   # Recommend

# 如果上面的命令提示安装失败,就试试下面的命令。(不过这种方法安装,配对功能就没有了,因为没有办法进行签名)
pip3 install -U tidevice

用法:tidevice [-h] [-v] [-u UDID] [–socket SOCKET]

C:\Users\shenyf\Desktop>tidevice -u 691a8bdxxxxxxxxxx6eb6eb1b423039f9649d7b9 ps
PID NAME                     BUNDLE_ID                       DISPLAY_NAME
311 Preferences              com.apple.Preferences           设置
328 MailCacheDeleteExtension
260 StoreKitUIService        com.apple.ios.StoreKitUIService iTunes
202 ShortcutsWidget
379 AppStore                 com.apple.AppStore              App Store
139 Spotlight                com.apple.Spotlight             Spotlight
276 EscrowSecurityAlert
187 WeChat                   com.tencent.xin                 微信

C:\Users\shenyf\Desktop>
命令描述
version查看版本号
list查看设备列表
info查看设备信息
date查看日期
sysinfo查看系统信息
appinfo
applist查看安装的所有第三方App
battery
screenshot
install安装
uninstall卸载
reboot
shutdown
parse
watch
wait-for-device
launch
kill
ps
relay
xctest
wdaproxy
syslog系统日志
fsync
dumpfps
developer
pair
perf
test测试
二、查看版本号
C:\Users\shenyf\Desktop>tidevice version
tidevice version 0.5.0
三、列出链接设备
C:\Users\shenyf\Desktop>tidevice list
List of apple devices attached
691a8bdxxxxxxxxxx6eb6eb1b423039f9649d7b9 iPhone 6s USB

C:\Users\shenyf\Desktop>tidevice list --json
[
    {
        "udid": "691a8bdxxxxxxxxxx6eb6eb1b423039f9649d7b9",
        "name": "iPhone 6s",
        "conn_type": "USB"
    }
]

C:\Users\shenyf\Desktop>
四、应用管理
# 安装应用
$ tidevice install example.ipa

# 指定设备安装
$ tidevice --udid $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
五、Run XCTest

请先确保手机上已经安装有WebDriverAgent应用

# 运行XCTEST
$ tidevice xctest -B com.facebook.wda.WebDriverAgent.Runner
[I 210127 11:40:23 _device:909] BundleID: com.facebook.wda.WebDriverAgent.Runner
[I 210127 11:40:23 _device:911] DeviceIdentifier: 12345678901234567890abcdefg
[I 210127 11:40:23 _device:773] SignIdentity: 'Apple Development: -Your-Developer-Name-'
[I 210127 11:40:23 _device:840] Launch 'com.facebook.wda.WebDriverAgent.Runner' pid: 239
[I 210127 11:40:23 _device:1003] ProductVersion: 12.4
[I 210127 11:40:24 _device:952] Start execute test plan with IDE version: 29
[I 210127 11:40:24 _device:875] WebDriverAgent start successfully

# 修改监听端口为8200, 并显示调试日志
$ tidevice xctest -B com.facebook.wda.WebDriverAgent.Runner -e USB_PORT:8200 --debug
六、Relay
# 转发请求到手机,类似于iproxy
$ tidevice relay 8100 8100

# 转发并把传输的内容用hexdump的方法print出来
$ tidevice relay -x 8100 8100
运行WebDriverAgent 运行XCTest UITest 挂载开发者镜像 七、查看设备信息
$ tidevice info

# 查看设备电源信息
$ tidevice info --domain com.apple.mobile.battery --json
{
    "BatteryCurrentCapacity": 53,
    "BatteryIsCharging": true,
    "ExternalChargeCapable": true,
    "ExternalConnected": true,
    "FullyCharged": false,
    "GasGaugeCapability": true,
    "HasBattery": true
}

已知域
com.apple.disk_usage
com.apple.disk_usage.factory
com.apple.mobile.battery
com.apple.iqagent
com.apple.purplebuddy
com.apple.PurpleBuddy
com.apple.mobile.chaperone
com.apple.mobile.third_party_termination
com.apple.mobile.lockdownd
com.apple.mobile.lockdown_cache
com.apple.xcode.developerdomain
com.apple.international
com.apple.mobile.data_sync
com.apple.mobile.tethered_sync
com.apple.mobile.mobile_application_usage
com.apple.mobile.backup
com.apple.mobile.nikita
com.apple.mobile.restriction
com.apple.mobile.user_preferences
com.apple.mobile.sync_data_class
com.apple.mobile.software_behavior
com.apple.mobile.iTunes.SQLMusicLibraryPostProcessCommands
com.apple.mobile.iTunes.accessories
com.apple.mobile.internal
com.apple.mobile.wireless_lockdown
com.apple.fairplay
com.apple.iTunes
com.apple.mobile.iTunes.store
com.apple.mobile.iTunes

八、文件 *** 作
# 查看相册内容
$ tidevice fsync /DCIM/

# 查看T3出行Documents中的内容
$ tidevice fsync -B com.t3go.passenger ls /Documents/

# 其他 *** 作 rm cat pull push stat tree rmtree mkdir
$ tidevice fsync -h

# 支持查看 /Documents 的App
# com.apple.iMovie iMovie
# com.apple.mobilegarageband 库乐队
# com.apple.clips 可立拍
# com.t3go.passenger T3出行
# com.dji.golite DJI Fly
# com.duokan.reader 多看阅读
九、其他常用
# 重启
$ tidevice reboot

# 截图
$ tidevice screenshot screenshot.jpg

# 输出日志 same as idevicesyslog
$ tidevice syslog

# 启动苹果设置
C:\Users\shenyf\Desktop>tidevice launch com.apple.Preferences
PID: 311
十、性能采集

使用命令行可以直接看到结果,不过最好还是用接口获取

# 性能采集
$ tidevice perf -B com.example.demo
fps {'fps': 0, 'value': 0, 'timestamp': 1620725299495}
network {'timestamp': 1620725300511, 'downFlow': 55685.94921875, 'upFlow': 2300.96484375}
screenshot {'value': <PIL.PngImagePlugin.PngImageFile image mode=RGB size=231x500 at 0x1037CF760>, 'timestamp': 1620725301374}
fps {'fps': 58, 'value': 58, 'timestamp': 1620725873152}
cpu {'timestamp': 1620725873348, 'pid': 21243, 'value': 1.2141945711006428}
memory {'pid': 21243, 'timestamp': 1620725873348, 'value': 40.54920196533203}

如何在python中获得应用程序性能

import time
import tidevice

t = tidevice.Device()
perf = tidevice.Performance(t)


def callback(_type: tidevice.DataType, value: dict):
    print("R:", _type.value, value)


perf.start("com.apple.Preferences", callback=callback)
time.sleep(10)
perf.stop()
遇到的问题 1.没有安装iTunes
C:\Users\shenyf\Desktop>tidevice list
List of apple devices attached
Traceback (most recent call last):
  File "d:\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Python37\Scripts\tidevice.exe\__main__.py", line 7, in <module>
  File "d:\python37\lib\site-packages\tidevice\__main__.py", line 743, in main
    actions[args.subparser](args)
  File "d:\python37\lib\site-packages\tidevice\__main__.py", line 78, in cmd_list
    for dinfo in um.device_list():
  File "d:\python37\lib\site-packages\tidevice\_usbmux.py", line 75, in device_list
    data = self.send_recv(payload)
  File "d:\python37\lib\site-packages\tidevice\_usbmux.py", line 46, in send_recv
    with self.create_connection() as s:
  File "d:\python37\lib\site-packages\tidevice\_usbmux.py", line 43, in create_connection
    return PlistSocket(self.__address, self._next_tag())
  File "d:\python37\lib\site-packages\tidevice\_safe_socket.py", line 97, in __init__
    super().__init__(addr)
  File "d:\python37\lib\site-packages\tidevice\_safe_socket.py", line 48, in __init__
    self._sock.connect(addr)
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/993426.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存