使用Airtest专用的编辑器AirtestIDE编写一个DEMO

1. 简介

AirtestIDE 是一个跨平台的UI自动化测试编辑器,适用于游戏和App。

自动化脚本录制、一键回放、报告查看,轻而易举实现自动化测试流程

支持基于图像识别的Airtest框架,适用于所有Android/iOS/Windows应用

支持基于UI控件搜索的Poco框架,适用于Unity3d,Cocos2d与Android/iOS App等多种平台

能够运行在Windows和MacOS上

完全基于python实现,脚本的语言完全跟随python,调用airtest的api

录制的脚本基本没有冗余的代码(可能是我的脚本太简单,原谅我的无知哈)

2. 脚本做的事情

以下四步循环执行十次

第一步:在桌面点击电话

第二步:拨打136xxxxxxxx

第三步:因为手机没有sim卡,弹出提示,点下知道了回到通话记录界面

第四步:返回home

3. 脚本代码

# -*- encoding=utf8 -*-

__author__ = "kangpc"

from airtest.core.api import *

from airtest.cli.parser import cli_setup

if not cli_setup():

auto_setup(__file__, logdir=True, devices=[

"android://127.0.0.1:5037/8KE5T20103001133?cap_method=MINICAP_STREAM&&ori_method=MINICAPORI&&touch_method=MINITOUCH",

])

# script content

print("start...")

counter = 1

while(counter<10):

touch(Template(r"tpl1606402338314.png", record_pos=(-0.352, 0.922), resolution=(1079, 2340)))

touch(Template(r"tpl1606402344894.png", record_pos=(-0.203, -0.589), resolution=(1079, 2340)))

touch(Template(r"tpl1606402415335.png", record_pos=(-0.005, 0.965), resolution=(1079, 2340)))

keyevent("BACK")

assert_exists(Template(r"tpl1606403009349.png", record_pos=(0.019, 0.039), resolution=(1079, 2340)), "检查当前是否在HOME页")

counter+=1

# generate html report

# from airtest.report.report import simple_report

# simple_report(__file__, logpath=True)

4. 另一个脚本(点击+输入手机号)

# -*- encoding=utf8 -*-

__author__ = "kangpc"

from airtest.core.api import *

from airtest.cli.parser import cli_setup

if not cli_setup():

auto_setup(__file__, logdir=True, devices=[

"android://127.0.0.1:5037/8KE5T20103001133?cap_method=MINICAP_STREAM&&ori_method=MINICAPORI&&touch_method=MINITOUCH",

])

# script content

print("start...")

touch(Template(r"tpl1606405873959.png", record_pos=(0.12, 0.306), resolution=(1079, 2340)))

touch(Template(r"tpl1606405887402.png", record_pos=(0.212, 1.028), resolution=(1079, 2340)))

sleep(3)

touch(Template(r"tpl1606405894150.png", record_pos=(0.029, 0.488), resolution=(1079, 2340)))

sleep(3)

touch(Template(r"tpl1606405999074.png", record_pos=(-0.087, -0.436), resolution=(1079, 2340)))

sleep(3)

text('13600000000')

最后,放一个图感受一下

074bd1b9e70e120a396288e32399327a.png

e3fc8e47e48bb1999415d7217a261019.png

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐