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()

  • 相关阅读:
    无声的吐槽csdn
    成长
    最近忙的头发都油油的
    pycharm5工具免费分享及安装教程
    分布式版本控制git常见问题之gitignore冲突
    感觉自己还是太年轻,还有很多东西不会
    关于laravel5.2仓库的建立,以及简单调用
    乎,前所未有的挑战!
    嘿嘿,无聊的时候,来点好玩的,翻滚吧,杀马特!!!
    随便说说
  • 原文地址:https://www.cnblogs.com/whycai/p/12687871.html
Copyright © 2011-2022 走看看