AirTest(自动跑测试用例)

AirTest介绍:

Airtest是一款基于Python的、跨平台的UI自动化测试框架,基于图像识别原理,适用于游戏和App。

访问Github上的 Airtest源码地址 ,可以获得更多信息,也欢迎各位帮忙完善项目,提交PR,也可以在issues页面中 提交bug或建议 。

如何快速上手

首先,想要编写Airtest脚本,需要具备基础的Python语法知识。虽然借助我们的AirtestIDE提供的录制功能,也能简单地根据操作步骤录制出可以回放操作的脚本,但是通常来说,熟练掌握Python语法能够帮助我们写出应用更广泛、更不容易出错的脚本。

若对 Python 语法不熟悉,网络上有不少非常优秀的Python教程可以学习,例如 廖雪峰的Python新手教程

关于Airtest项目的安装、基本使用方法和简单的例子,请查看Airtest文档页的 快速上手 章节。

官方网址(必看)

http://airtest.netease.com/

airtest介绍与脚本入门

https://airtest.doc.io.netease.com/tutorial/2_Airtest_introduction/

模拟点击

Airtest作为自动化测试框架,模拟的是人的操作,常见接口主要有:

  • touch 点击某个位置,可以设定被点击的位置、次数、按住时长等参数
  • swipe 从一个位置滑动到另外一个位置
  • text 调用输入法输入指定内容
  • keyevent 输入某个按键响应,例如回车键、删除键
  • wait 等待某个指定的图片元素出现
  • snapshot 对当前画面截一张图
  • 其他

使用本地python环境运行脚本

http://airtest.netease.com/docs/en/1_online_help/running_scripts.html

1.部署Python环境,安装Python(2.7 或 <= 3.6),Mac 安装 brew install python3

windows注意配置环境变量,C:Python27Scripts、C:Python27

2.pip install airtest

3.pip install pocoui

4.跑脚本

airtest run E:AutoTestNormal.air --device Android:///设备信息

airtest run E:AutoTestNormal.air --device Android:///设备信息 --log log/

airtest run E:AutoTestNormal.air --device Android:///设备信息 --log log/ --outfile log.html /// 运行结果

adb devices 查看设备信息

 如果你连接了多个设备,或者有远程设备,那么使用参数来指定要连接的设备

# connect an android phone with adb
init_device("Android")

# or use connect_device api with default params
connect_device("android:///")

# connect a remote device using custom params
connect_device("android://adbhost:adbport/1234566?cap_method=javacap&touch_method=adb")
原文地址:https://www.cnblogs.com/hewei2012/p/12869786.html