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功能。如果對我們的內容感興趣的話,別忘了持續關注我們喲~


AirtestIDE下載:airtest.netease.com/
Airtest 教程官網:airtest.doc.io.netease.com/
搭建企業私有云服務:airlab.163.com/b2b

官方答疑 Q 羣:117973773

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章