Windows上实现 IOS 自动化测试

本文介绍如何使用tidevice+WDA+airtest/facebook-wda实现在Windows上进行IOS APP自动化测试

环境准备

Windows Python环境

Python 3.6+

WebDriverAgent安装

下载最新的项目到Mac:https://github.com/appium/WebDriverAgent

$ git clone https://github.com/appium/WebDriverAgent.git

用Xcode打开
Xcode -> Preference,添加账户

在这里插入图片描述

修改WebDriverAgentRunner这个项目的Bundle ID(不要与原来的重复就行)

在这里插入图片描述

Product —> Destination —> 选择真机设备
在这里插入图片描述

Product —> Scheme —> WebDriverAgentRunner(选择Scheme为WebDriverAgentRunner)
在这里插入图片描述

Product —> Build For —> Testing,将项目运行到真机设备上
在这里插入图片描述

这时手机就装上了一个名为WebDriverAgentRunner的应用
在这里插入图片描述

注意如果用的是企业证书安装或打包的ipa包进行安装可能需要在通用设置设备管理中添加信任后才能正常运行WDA。(如果没有Mac,可以请IOS的同事帮忙安装)

tidevice库安装
pip install -U tidevice

安装成功后查看版本:

> tidevice version
tidevice version 0.10.1

此时,将手机连接到Windows,就可以查看连接设备信息

> tidevice list
UDID                       SerialNumber    NAME         MarketName      ProductVersion  ConnType
0000xxx-00xx65xx22xx00xx  DNXXW28XXDYV    iPhone18臻享版  iPhone 14                 15.7  usb



> tidevice list --json
[
    {
        "udid": "0000xxx-00xx65xx22xx00xx",
        "serial": "DNXXW28XXDYV",
        "name": "iPhone18臻享版",
        "market_name": "iPhone 14",
        "product_version": "15.7",
        "conn_type": "usb"
    }
]

此外,tidevice还有许多常用指令

# 查看设备信息
tidevice info
# 截图(注意这是将截图保存到xx.jpg文件中,所以该图片是保存在电脑端的当前输指令的目录下,而不是在手机中)
tidevice screenshot xx.jpg
# 启动应用程序
tidevice lanch Bundle ID (Bundle ID表示包名)
如:
tidevice launch tv.danmaku.bilianime
# 停止程序
tidevice kill Bundle ID
# 查看第三方包名(Bundle ID)
tidevice applist
# 重启设备
tidevice reboot

# 关机
tidevice shutdown
# 安装应用

# 安装本地包
tidevice install C:\example.ipa

# 安装远程包
tidevice install https://.....ipa

# 多台手机时,指定uid安装
tidevice -u uid  install C:\test.ipa
# 卸载应用
tidevice uninstall 包名
# 多台手机时,指定uid卸载应用
tidevice -u uuid uninstall 包名
# 查看电池信息
tidevice info --domain com.apple.mobile.battery

tidevice battery
# 更多帮助
tidevice -h
启动WDA驱动器
tidevice -u [udid] wdaproxy -B [wda 的 bundle Id] --port 8100
例:
tidevice -u 1238101-00012345688001E wdaproxy -B com.facebook.wda.xxxnApp --port 8100

启动成功会有如下提示:
在这里插入图片描述

验证启动WDA是否成功

在浏览器中输入http://localhost:8100/,如果有返回信息,则证明WDA启动成功。

http://localhost:8300/status可以查看当前设备的状态,获取与wda通信session id
在这里插入图片描述
同时,启动成功后手机屏幕上会有Automation Running Hold both volume buttons to stop的水印。

完成上述环境配置后,也意味着IOS可以脱离Mac,使用Windows进行自动化操作了。

Python + facebook-wda 自动化

安装facebook-wda

pip install -U facebook-wda
import wda
ct = wda.Client("http://localhost:8100")

# 打印设备信息
print(ct.info)

# 三种打开应用的方式
# ct.session("com.sina.weibo")
# ct.session().app_activate("tv.danmaku.bilianime")
# ct.session().app_launch("com.alipay.iphoneclient")

# 打印当前所在APP的Bundle ID
print(ct.session().app_current())

# 截图
# ct.screenshot(r"C:\Users\sg0100\Desktop\test.jpg")
airtest 自动化

安装airtest,打开后在主界面的右下方 “连接IOS设备” 会自动获取到连接地址,点击连接即可
在这里插入图片描述

在这里插入图片描述

from airtest.core.api import *
from airtest.report.report import simple_report

# auto_setup(__file__, logdir=True, devices=["ios:///http://127.0.0.1:8100",])
auto_setup(__file__, logdir=True)
init_device(platform="IOS",uuid="http://localhost:8100/")

start_app("com.apple.Preferences") # 打开【设置】


touch(Template(r"tpl1675671163913.png", record_pos=(-0.197, 0.638), resolution=(1170, 2532)))   # 点击【通知】

  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值