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") 

image

当然上述装包功能,我们用 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")

image

当然换成 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)

image

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)))

image

6. 小结

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值