软件测试 —— Airtest的iOS实用接口介绍 (建议收藏)

1. 前言

前段时间Airtest更新了1.3.0.1版本,里面涉及非常多的iOS功能新增和改动,今天想详细跟大家聊一下里面的iOS设备接口。

PS:本文示例均使用本地连接的iOS设备,Airtest版本为1.3.0.1 。

2. 安装接口:installinstall_app

Airtest支持通过本地.ipa文件安装APP,也支持通过下载链接安装APP,以本地ipa文件为例:

# -*- encoding=utf8 -*-
__author__ = "AirtestProject"
​
from airtest.core.api import *
auto_setup(__file__)
​
install(r"D:\my_popo\email.ipa") 

 当然上述装包功能,我们用 device().install_app 也可以实现:

# -*- encoding=utf8 -*-
__author__ = "AirtestProject"
​
from airtest.core.api import *
auto_setup(__file__)
​
dev = device()
dev.install_app(r"D:\my_popo\email.ipa") 

3. 卸载接口:uninstalluninstall_app

卸载接口与安装接口类似,可以直接 uninstall ,也可以通过 device().uninstall_app 来卸载指定APP,这里以 uninstall_app 为例:

# -*- encoding=utf8 -*-
__author__ = "AirtestProject"
​
from airtest.core.api import *
auto_setup(__file__)
​
dev = device()
dev.uninstall_app("com.netease.mailmaster")

 

当然换成 install 接口也是一样的效果: 

# -*- encoding=utf8 -*-
__author__ = "AirtestProject"
​
from airtest.core.api import *
auto_setup(__file__)
​
uninstall("com.netease.mailmaster")

4. 列出所有APP的接口:list_app

我们可以用 list_app 列出iOS设备的APP列表,并且支持在 list_app("") 里传入要列出的app类型,all、system、user ,分别对应全部APP、系统APP、用户安装的APP,这里以列出用户安装的APP信息为例:

# -*- encoding=utf8 -*-
__author__ = "AirtestProject"
​
from airtest.core.api import *
auto_setup(__file__)
​
dev = device()
​
#列出并打印用户安装的APP
print("---------以下是用户安装的APP的信息-----------")
user_app = dev.list_app("user")
print(user_app)

 

PS:在1.3.0.1版本的Airtest里面使用该接口,会报一个 TypeError: list_app() got an unexpected keyword argument 'type' 的错误,我们将在后续的版本中修复它。

5. 剪切板功能:get_clipboardset_clipboard

新版Airtest还支持设置iOS设备的剪切板,我们可以从一个简单的示例来查看这个功能:

  • 设置剪切板内容
  • 获取并打印剪切板内容
  • 粘贴剪切板内容
# -*- encoding=utf8 -*-
__author__ = "AirtestProject"
​
from airtest.core.api import *
auto_setup(__file__)
​
#设置剪贴板内容
set_clipboard("content")
​
#获取并打印剪切板内容
text = get_clipboard()
print("当前剪切板内容:" + text)
​
#单击唤出粘贴按钮
touch([50,310])
​
#粘贴剪切板内容
touch(Template(r"tpl1692173001410.png", record_pos=(-0.38, -0.788), resolution=(750, 1624)))
​

 

6. 小结

今天的iOS接口就介绍到这里,下期我们可以一起看看Airtest里面封装的tidevice接口,能带来哪些iOS功能。如果对我们的内容感兴趣的话,别忘了持续关注我们哟~

下面是配套学习资料,对于做【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!

软件测试面试小程序

被百万人刷爆的软件测试题库!!!谁用谁知道!!!全网最全面试刷题小程序,手机就可以刷题,地铁上公交上,卷起来!

涵盖以下这些面试题板块:

1、软件测试基础理论 ,2、web,app,接口功能测试 ,3、网络 ,4、数据库 ,5、linux

6、web,app,接口自动化 ,7、性能测试 ,8、编程基础,9、hr面试题 ,10、开放性测试题,11、安全测试,12、计算机基础

资料获取方式 :

猜你喜欢

转载自blog.csdn.net/jiangjunsss/article/details/132409937