当前位置: 首页 > news >正文

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.batterytidevice 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)))   # 点击【通知】
http://www.lryc.cn/news/57.html

相关文章:

  • Linux云服务器下怎么重置MySQL8.0数据库密码
  • JVM调优
  • 【配电网规划】SOCPR和基于线性离散最优潮流(OPF)模型的配电网规划( DNP )(Matlab代码实现)
  • 锦正茂EM3电磁铁的技术参数
  • Go最新版下载 Go1.20版新特性
  • Pywirt:一款基于Python的Windows安全应急响应工具
  • KDZD832 智能蓄电池活化仪
  • 纯css实现loading加载中(多种展现形式)
  • 【面试题】2023 vue高频面试知识点汇总
  • 跨境电商选品重要吗?
  • SpringBoot
  • python--turtle
  • NodeJS的后端Express项目部署到Ubuntu服务器,为前端提供API服务
  • 作为研发如何使用Github Api?
  • Java volatile学习
  • 用神经网络分类上和下
  • VS Code 1.75 发布!
  • Vue2仿网易云风格音乐播放器(附源码)
  • Spring相关面试题
  • 操作符详解(上篇)
  • 采样电路的3个组成部分
  • ffmpeg硬解码与软解码的压测对比
  • 操作符——“C”
  • YSP的UI界面设计
  • 干货 | 什么是磁传感器?最常用的磁传感器类型及应用
  • 操作符(运算符)详解
  • 【LeetCode每日一题】【2023/2/9】1797. 设计一个验证系统
  • 计算机图形学:改进的中点BH算法
  • 【SQL开发实战技巧】系列(六):从执行计划看NOT IN、NOT EXISTS 和 LEFT JOIN效率,记住内外关联条件不要乱放
  • 十分钟利用环信WebIM-vue3-Demo,打包上线一个即时通讯项目【含音视频通话】