Airtest的iOS实用接口介绍

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

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

安装接口:install、install_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")

Airtest的iOS实用接口介绍_第1张图片

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

卸载接口:uninstall、uninstall_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")

Airtest的iOS实用接口介绍_第2张图片
当然换成 install 接口也是一样的效果:

# -*- encoding=utf8 -*-
__author__ = "AirtestProject"

from airtest.core.api import *
auto_setup(__file__)

uninstall("com.netease.mailmaster")

列出所有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)

Airtest的iOS实用接口介绍_第3张图片

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

剪切板功能:get_clipboard、set_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)))

Airtest的iOS实用接口介绍_第4张图片

小结

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

最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你! 

你可能感兴趣的:(软件测试,ios,软件测试,自动化测试,功能测试,程序人生,职场和发展)