Windows上实现 IOS 自动化测试

编程知识 更新时间:2023-04-17 02:17:44

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

环境准备

Windows Python环境

Python 3.6+

WebDriverAgent安装

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

$ git clone https://github/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)))   # 点击【通知】

更多推荐

Windows上实现 IOS 自动化测试

本文发布于:2023-04-13 16:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/ab8202653a9209f4011175ee007d8c9a.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:测试   Windows   IOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 73227文章数
  • 14阅读数
  • 0评论数