zoukankan      html  css  js  c++  java
  • 自动化--APP UI自动化--Airtest学习

    看到其他同事在使用airtest,于是学习一下

    AirtestIDE提供了一个比较全的官方文档,讲解、操作都蛮细的

    http://airtest.netease.com/docs/docs_AirtestIDE-zh_CN/index.html

    使用airtest执行ui自动化,首先要:

    1.安卓 AirtestIDE

    官方安装  http://airtest.netease.com/

    网盘安装:  

    链接:https://pan.baidu.com/s/1IaTR_ZPxy81mCPwGsyRKhA
    提取码:f7pk

    2.IDE连上手机

    手机需开启开发者模式(设置-系统-开发人员选项-USB调试)

    如果连不上,文章最上面的官方文档有对应的问题解决

    3.简单的脚本

    1)使用图片定位

     1 # -*- encoding=utf8 -*-
     2 __author__ = "whyCai"
     3 
     4 from airtest.core.api import *
     5 
     6 auto_setup(__file__)
     7 
     8 
     9 touch(Template(r"tpl1586696803061.png", record_pos=(0.122, 0.872), resolution=(1080, 2280)))  #点击计算器
    10 
    11 touch(Template(r"tpl1586696831912.png", record_pos=(-0.369, 0.643), resolution=(1080, 2280)))  #点击 1
    12 
    13 touch(Template(r"tpl1586696857748.png", record_pos=(0.371, 0.373), resolution=(1080, 2280)))  #点击 +
    14 
    15 
    16 touch(Template(r"tpl1586696879899.png", record_pos=(0.125, 0.641), resolution=(1080, 2280)))  #点击 3
    17 
    18 touch(Template(r"tpl1586696905934.png", record_pos=(0.375, 0.781), resolution=(1080, 2280)))  #点击 =

    如图:

    运行:

    2)使用位置定位

     1 # -*- encoding=utf8 -*-
     2 __author__ = "whyCai"
     3 
     4 from airtest.core.api import *
     5 from airtest.cli.parser import cli_setup
     6 
     7 if not cli_setup():
     8     auto_setup(__file__, logdir=True, devices=[
     9             "Android://127.0.0.1:5037/VBJDU18712006906",
    10     ])
    11 
    12     
    13     
    14 
    15 # script content
    16 print("start...")
    17 
    18 from poco.drivers.android.uiautomation import AndroidUiautomationPoco
    19 poco = AndroidUiautomationPoco(use_airtest_input=True,screenshot_each_action=False)
    20 
    21 
    22 #点击计算器
    23 poco(text='计算器').click()
    24 
    25 #点击 1
    26 poco(text='1').click()
    27 
    28 #点击 +
    29 poco(name='com.android.calculator2:id/op_add').click()
    30 
    31 #点击 3
    32 poco(text='3').click()
    33 
    34 #点击 =
    35 poco(name='com.android.calculator2:id/eq').click()
    36 
    37 
    38 # generate html report
    39 # from airtest.report.report import simple_report
    40 # simple_report(__file__, logpath=True)

    执行:

    新增--------

    1.使用屏幕中的文字,模糊匹配,并获取对应的文字

    textName=poco(textMatches="^我的任务.*$")
    realName = textName.get_text()

  • 相关阅读:
    webrtc系列之-像老鼠一样打洞
    Ubuntu记录用户IP访问操作信息工具
    OPENVIDU实现同一用户同时发布多个流媒体
    如何使用Nginx-rtmp搭建简易的HLS直播系统
    python实现数据库主从状态监控
    简单分析实现运维利器---批量操作bashshell
    《我与Windows Server 2008R2那点事儿》之域控账户故障事件
    常用动态路由协议之IS-IS
    在云服务器上搭建Python开发环境
    基于Python3接口自动化测试开发相关常用方法
  • 原文地址:https://www.cnblogs.com/whycai/p/12687871.html
Copyright © 2011-2022 走看看