在windows平台通过tidevice+airtest搭建ios自动化框架

 1.概述:

tidevice 是阿里的内部的一个小组用来做 iOS 自动化用的工具。最近终于开源了出来,类似android下的adb。

 

2.价值:

不依赖 xcode 启动 WebDriverAgent完成设备连接,因为不依赖 Xcodebuild,所以就算你只有 Windows 或者 Linux 也能跑起来 iOS 自动化。

 

3.作用:

  • 截图
  • App安装(支持远程安装),启动,停止,查看
  • 启动 WebDriverAgent
  • 性能采集(类似 PerfDog)不过这块暂时只有 API 可以用。
  • 功能还在不停的扩展中

 

4.安装tidevice:

# 安装依赖包(推荐)
pip3 install -U "tidevice[openssl]" 

#直接安装

pip3 install -U tidevice

# 查看tidevice版本,检查是否安装成功
tidevice version

 

5.命令:

########################查看####################
tidevice list #查看设备
tidevice list --json #以json格式查看设备
tidevice applist #查看第三方包名
tidevice info   #查看设备信息
tidevice sysinfo # 返回的是设备系统信息


####################程序操作######################
tidevice launch com.apple.Preferences #启动程序
tidevice kill com.apple.Preferences .....停止程序


####################安装与卸载######################
tidevice install example.ipa #安装本地包
tidevice install https://.....ipa  #远程安装包

#多台手机时可指定uid
tidevice -u 设备uid  install C:\Users\Administrator\Desktop\test.ipa #指定设备安装
tidevice -u 设备uid uninstall 包名 .........卸载应用


####################设备操作######################
tidevice screenshot screenshot.jpg #截图
tidevice syslog  # 获取设备日志
tidevice reboot  #重启设备
tidevice shutdown  #手机关机
#获取指定应用的性能
tidevice perf -B 包名 # 阻塞式打印


################模拟Xcode运行XCTest#####################
tidevice -u $UDID xctest -B $BUNDLE_ID #运行WebDriverAgent
tidevice -u udid 8100 8100   # 转发请求到手机,类似于iproxy
tidevice relay 8100 8100     # 转发请求到手机,类似于iproxy

tidevice -u [设备 udid]  wdaproxy  -B [wda 的 bundle Id]  --port 8100 #指定端口启动wda
#案例:
tidevice -u  设备id  xctest  -B  包名  #通过包名启动WebDriverAgent(指定一台)

 备注使用tidevice需要依赖itunes插件(可以直接安装爱思助手,会自动装itunes插件), 否则连接设备失败

tidevice详细:https://testerhome.com/topics/27758

 

 

6.部署步骤:

1.难点:如何安装WebDriverAgent到手机

需要下载WebDriverAgent项目编译到手机

https://github.com/AirtestProject/iOS-Tagent/blob/master/Introduction/README_zh.md

https://www.cnblogs.com/chen-xia/p/14266014.html

备注:

  •     部署iOS测试平台需要苹果开发者证书,现在使用个人Apple ID登陆即可,不需要另外注册付费开发者账号
  •     个人版的免费证书,每隔7天左右,要手动更新开发者证书;
  •     需要手动的在iPhone中选择信任证书,通用->设备管理->选择信任;
  •     最多支持3台设备;

建议:使用公司的企业账号或个人收费账号测试(企业账号可以绑定100台也不需要更新证书),不然很头疼

 

2.启动WebDriverAgent

tidevice  xctest  -B  $BUNDLE_ID ................通过包名启动WebDriverAgent(单台)

tidevice -u  设备id  xctest  -B  $BUNDLE_ID ............................通过包名启动WebDriverAgent(指定一台)

 

 

3.检查设备代理状态(xx表示手机ip)

http://xx.xx.xx.xx:8100/status

 

 

4.使用airtest

输入 http://xx.xx.xx.xx:8100/  点击connet即可连接

 

 

 

7.使用记录:

#!/usr/bin/env python
# encoding: utf-8
__author__ = "晨晨"

import os


#________________________________________tidevice基础封装______________________________________________
class Package_name(object):

    def __init__(self,device_id,name_list=None):
        self.device_id=device_id
        self.name_list=name_list


    def __call__(self, *args, **kwargs):
        '''列出设备的三方包名列表'''
        bb=os.popen('tidevice -u '+self.device_id+' applist').readlines()
        self.name_list=[ i[:i.find(' '):] for i in bb]
        return self.name_list


    def  is_no_package3_name(self,packeage_name):
        '''判断手机是否安装了xx包名'''
        return  True if  packeage_name  in self.name_list else False


    def  device_info(self):
        '''获取设备信息_dict格式'''
        bb=os.popen('tidevice -u '+self.device_id+' info').readlines()
        self.name_list=([''.join([i for i in price.replace("  ",'').split('\n')]) for price in bb])
        self.name_list.pop()
        json_a={}
        for i in self.name_list:
            aa=((i[:i.find(':'):]))
            bb=(i[i.find(':')+1:].lstrip())
            json_a[aa] = bb
        return json_a




if __name__=='__main__':
    test=Package_name('9592617d97b1d558ad4ced4a31cd0442762ffc05')
    print('以列表方式列出包名',test())

    print('判断设备是否安装xx包',test.is_no_package3_name('com.tencent.xin'))
    print('设备基础信息:',test.device_info())

 

 

 相关连接:

https://testerhome.com/articles/29124 ..............................................................................................tidevice搭建airtest环境

https://mp.weixin.qq.com/s/xgDnZdMdy5E5af-54ZMXow ...................................................................tidevice相关用法 ,,端口转发相关

https://www.freesion.com/article/4943908479/ ..................................................................................tidevice实现 iOS 压测自动化

https://blog.csdn.net/u010698107/article/details/120498549 ...........................................................Windows上实现iOS APP自动化测试:tidevice + WDA + airtest

https://mp.weixin.qq.com/s?__biz=MzUxMDc4NTkwMA==&mid=2247486891&idx=1&sn=7a2747d0f41fea3946b68cae51caaef4.............................AirtestIDE无线连接手机

https://mp.weixin.qq.com/s?__biz=MzA4NDUyNzA0Ng==&mid=2247488591&idx=1&sn=c81d7be31c4418be5f8aca5b8ac51e57.............................tidevice相关用法,tidvice获取ios性能数据

 

 

 

 

posted on 2021-02-02 15:11  chen_2987  阅读(7118)  评论(6编辑  收藏  举报

导航