当前位置:   article > 正文

airtest基础使用(安装+连接+脚本导入)_airtest怎么链接paid脚本

airtest怎么链接paid脚本

airtest基础(安装+连接+脚本导入)

原创:George555       公众号: 测试江湖路  

如果这些内容对你有帮助,也可以打开微信扫一扫,加关注:

注:本篇只针对代码层面的使用,关于AirtestIDE的使用请去官网查看。

一、环境要求:

  • 操作系统

  • Windows

  • MacOS X

  • Linux

  • Python2.7 & Python3+

  • 二、安装
     

1.安装方法1:pip install -U airtest

2.安装方法2:从git下载:

git clone https://github.com/AirtestProject/Airtest.git

pip install -e airtest

备注:因为Airtest还在快速开发中,这里使用 -e 来安装源码。以后你就可以直接使用 git pull 更新代码目录来升级Airtest了。

三、连接设备

---Android设备连接----

connect_device("android:///")  #连接本地android设备connect_device("android://adbhost:adbport/1234566?cap_method=javacap&    touch_method=adb") #连接远端android设备示例:

    #A.连接本地夜神模拟器:

    connect_device('Android://127.0.0.1:5037/127.0.0.1:62001')

    注意:夜神模拟器端口是62001,127.0.0.1:5037是对应的本机的adbhost和adbport

    #B.连接本机usb连接的真机:    (连接华为真机)

    connect_device("android:///Y2J5T17815005122")

----windows应用连接----

    connect_device("Windows:///") #连接windows桌面

    connect_device("Windows:///?title_re=百度.*") #连接windows应用

    示例:

    根据title正则匹配窗口:connect_device("Windows:///?title_re=百度一下.*")

    根据窗口句柄匹配窗口:connect_device('Windows:///3410242')

----IOS设备连接----

    connect_device("ios:///") #连接本机ios设备,即在mac上

    connect_device("ios:///http://192.168.2.127:8100") #连接远端ios设备(比如在windows上调用脚本,操作mac上连接的ios设备)

    注意:http://192.168.2.127:8100是在mac的xcode上运行WebdriverAgent(iOS-Tagent)成功后的服务端地址和端口

四、常用模拟输入

  • touch

  • swipe

  • text

  • keyevent

  • snapshot

  • wait

五、常用断言

  • assert_exists

  • assert_not_exists

  • assert_equal

  • assert_not_equal

备注:当断言失败,会抛出 AssertsionError。所有断言都会在html报告中显示。

六、获取脚本信息

# 如果代码中定义了包含: author, title, desc,则会在用例信息中输出author, title, desc。如:{"author": ..., "title": ..., "desc": ...}

使用命令:python -m airtest info "path to your .air dir"

七、导入其他air脚本

示例:

from airtest.core.api import using using("common.air") from common import common_function common_function()示例:

脚本目录结构:

airTestProject

        com.air

            com.py

        test.air

            test.py

com.py代码:​​​​

# -*- encoding=utf8 -*-__author__ = "George"from airtest.core.api import *import osdef getScreenWidthHigh(SerialNo):    '''使用adb命令,获取移动设备屏幕的宽和高    @param:SerialNo:设备序列号    @return:high、width    调用示例:    width,high=getScreenWidthHigh("127.0.0.1:62001")    print (width)    print (high)    '''    os.system("adb connect "+SerialNo)    size=os.popen("adb shell wm size").          read().split(':',1)[1].strip()    #size是Physical size: 720x1280处理后的720x1280    #print (size)    high=size.split('x',1)[1] #用x分离获取high值    width=size.split('x',1)[0]#用x分离获取width值    os.system("adb disconnect "+SerialNo)    return width,high

test.py代码:   (---调用com.py里的方法)

# -*- encoding=utf8 -*-__author__ = "George"from airtest.core.api import *from airtest.core.api import usingusing("com.air")from com import getScreenWidthHigha,b=getScreenWidthHigh("127.0.0.1:62001")print (a)print (b)

 

#####欢迎大家加群交流####

QQ:464314378

微信群请先加群主微信,群主会拉各位小伙伴进群。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/276271
推荐阅读
相关标签
  

闽ICP备14008679号