软件测试:Airtest的iOS实用接口介绍

发表于:2023-10-23 09:50

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:程序员小濠    来源:知乎

  1. 前言
  前段时间Airtest更新了1.3.0.1版本,里面涉及非常多的iOS功能新增和改动,今天想详细跟大家聊一下里面的iOS设备接口。
  PS:本文示例均使用本地连接的iOS设备,Airtest版本为1.3.0.1 。
  2. 安装接口: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") 
  当然上述装包功能,我们用 device().install_app 也可以实现:
  # -*- encoding=utf8 -*-
  __author__ = "AirtestProject"
  
  from airtest.core.api import *
  auto_setup(__file__)
  
  dev = device()
  dev.uninstall_app("com.netease.mailmaster")
  3. 卸载接口: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")
  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_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)))
  本文内容不用于商业目的,如涉及知识产权问题,请权利人联系51Testing小编(021-64471599-8017),我们将立即处理
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号