Windows上实现iOS APP自动化测试:tidevice + WDA + airtest_tidevice+wda+airtest ios自动化测试

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化的资料的朋友,可以戳这里获取

$ tidevice list

airtest安装可参考:App自动化测试工具Airtest

airtest iOS 自动化

1. 启动WDA

获取设备的udid:

$ tidevice list

查看wda的bundle id:

$ tidevice applist

使用tidevice启动iOS设备上的WDA应用

$ tidevice -u [设备 udid] wdaproxy -B [wda 的 bundle Id] --port 8100

如果你觉得每次进行自动化测试之前都要手动启动WDA比较麻烦,可以考虑使用vbs+bat的方式后台启动WDA,实现方式可参考VBSscript实现后台运行Windows bat脚本

2. airtest 连接设备

如果要使用airtest IDE来编写自动化测试脚本,先连接 iOS 设备。

打开Airtest IDE,在右下角【连接iOS设备】中输入地址:

http+usbmux://00008101-000255021E08001E
# 或者
http://localhost:8100/

00008101-000255021E08001E 是手机的udid,8100是使用tidevice启动WDA时设置的端口号。

可以使用init_device()或者connect_device()方法连接iOS设备:

# 方法1
init_device(platform="IOS",uuid="http://localhost:8100/")
# 方法2
connect_device("ios:///http://127.0.0.1:8100")
# 方法3
init_device(platform="IOS",uuid="http+usbmux://00008101-000255021E08001E")

3. airtest 自动化

连接上iOS设备后就可以编写测试用例了, airtest使用的是图像识别的方法进行元素操作,元素操作方法可参考文章 App自动化测试工具Airtest

下面是一个示例脚本:打开【设置】

#!/usr/bin/python3
# @Time: 2021/9/26 13:55
# @File: test\_ios\_airtest.py

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"tpl1632398524727.png", record_pos=(-0.34, 0.236), resolution=(1125, 2436))) # 点击

# generate html report
simple_report(__file__)


poco iOS自动化

也可以使用poco进行UI元素操作,WDA启动和连接设备和前面介绍的【airtest iOS 自动化】一样。连接设备使用airtest提供的方法。

UI 元素可通过在AirtestIDE的Poco 辅助窗查看,注意要选择iOS。

poco元素操作方法可参考文章 App自动化测试工具Airtest

使用AirtestProject进行APP自动化测试时,通常将airtest和poco结合起来使用,下面是一个示例脚本:打开【设置】,检查软件版本为14.8

#!/usr/bin/python3
# @Time: 2021/9/26 13:56
# @File: test\_ios\_poco.py

from airtest.core.api import \*
from airtest.report.report import simple_report
from poco.drivers.ios import iosPoco

# 连接设备、初始化日志路径
auto_setup(__file__, logdir=True)
init_device(platform="IOS",uuid="http://localhost:8100/")

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

# 初始化ios poco
poco = iosPoco()

# 点击
poco("通用").click()
poco("关于本机").click()
# 断言
assert poco('软件版本').attr('value') == "14.8"

# generate html report
simple_report(__file__)

查看生成的报告:

和facebook-wda库一起使用

facebook-wda、airtest和poco这3个测试库可以在一个测试项目中使用,下面结合pytest测试框架,使用这3个库实现APP自动化测试。

from airtest.core.api import \*
from .start_wda import StartWDA
import wda
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
from poco.drivers.ios import iosPoco


class TestFacebookWDA():
    def setup(self):
        self.udid = "00008101-000255021E08001E"
        self.wda_bundle_id = "com.facebook.WebDriverAgentRunner.test1.xctrunner"
        self.port = 8100  # 8100为启动WDA设置的端口号
        self.app_name = "com.apple.Preferences"

        # 启动WDA
        self.wda = StartWDA()
        self.wda.stop_wda(self.port)
        self.wda.start_wda(self.udid, self.wda_bundle_id, self.port)

        # airtest初始化连接设备
        init_device(platform="IOS", uuid=f"http://localhost:{self.port}/")
        # poco初始化


![img](https://img-blog.csdnimg.cn/img_convert/bb9cf68f3e558e0b7079080dfa604aa4.png)
![img](https://img-blog.csdnimg.cn/img_convert/f950e779406db60bed94d50c23831d13.png)

**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化的资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618631832)**

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化的资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618631832)**

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值