AirtestProject Airtest 的 iOS 实用接口介绍

fishfish-yu · 2023年08月18日 · 2409 次阅读

此文章来源于项目官方公众号:“AirtestProject”
版权声明:允许转载,但转载必须保留原链接;请勿用作商业或者非法用途

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 功能。如果对我们的内容感兴趣的话,别忘了持续关注我们哟~


AirtestIDE 下载:airtest.netease.com/\
Airtest 教程官网:airtest.doc.io.netease.com/\
搭建企业私有云服务:airlab.163.com/b2b

官方答疑 Q 群:117973773

呀~这么认真都看到这里啦,帮忙点击左下角的爱心,给我点个赞支持一下把,灰常感谢~

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册