转 airtest poco

1.  Pymysql(No module named cryptography)

pip install cryptography

pip install paramiko

把 cryptography 与pymysql 放入 airtest路径

2.  安装,卸载

  1. 查看所连接的设备

os.system('adb version')

 

  1. 查看所有包名

os.system('adb shell pm list package')

  1. 安装

os.popen("adb install -r D:\BaiduYunDownload\kaoyan3.1.0.apk")

 

  1. 卸载

os.system('adb uninstall com.fenbi.android.zenglish')

1.启动app

def call_adb(str):
  rec = os.system("/Applications/AirtestIDE.app/Contents/MacOS/airtest/core/android/static/adb/mac/adb %s" % str)
  return rec
call_adb("shell dumpsys activity activities") # 找package+actity

(2) 找到cmp

(3) call_adb("shell am start -n com.fenbi.android.zenglish/com.fenbi.android.zebraenglish.activity.portal.WelcomeActivity") #package+actity

 

1. 点击并长按

# coding=utf-8

from poco.drivers.unity3d import UnityPoco

poco = UnityPoco()

poco('btn_start').click()poco('basic').click()poco('star_single').long_click()poco('star_single').long_click(duration=5)

poco(text='分享').click()

 

2. 存在

obj = poco(text='分享',type='android.widget.RadioButton')

if obj.exists(): #True

    print('返回Ture')

else:  

     print('返回False')

3. 选择

  1. 属性

 poco(text='分享',type='android.widget.RadioButton')

 

  1. 遍历子代

rec = poco("android.view.ViewGroup").offspring("android.widget.TextView")

print('%%%%%%%%%%%s'%len(rec))

for i in range(len(rec)):

    print(rec[i].get_text())

4. 获得属性

print(obj.get_text())

print(obj.attr('text'))

print(obj.attr('package'))

5. 拖动

 

poco('star').drag_to(poco('shell'))

6. 滑动

obj.swipe([0, 0.8],duration=3)

obj.swipe('up')

obj.swipe('down')

obj.swipe('left')

obj.swipe('right')

 

x,y=obj.get_position()

obj.swipe([x,y],[x*0.6,y*0.6])

 

 

7. focus

 

listView = poco('Scroll View')

listView.focus([0.5, 0.8]).drag_to(listView.focus([0.5, 0.2]))

image.focus('center').long_click()

image.focus([0.1, 0.1]).long_click()

 

8. wait

 

# coding=utf-8

from poco.drivers.unity3d import UnityPocofrom poco.exceptions import PocoTargetTimeout

poco = UnityPoco()

bomb_count = 0

while True:

    blue_fish = poco('fish_emitter').child('blue')

    yellow_fish = poco('fish_emitter').child('yellow')

    bomb = poco('fish_emitter').child('bomb')

    fish = poco.wait_for_any([blue_fish, yellow_fish, bomb])

    if fish is bomb:

        # skip the bomb and count to 3 to exit

        bomb_count += 1

        if bomb_count > 3:

            return

    else:

        # otherwise click the fish to collect.

        fish.click()

time.sleep(2.5)

案例二:

 

# coding=utf-8

import timefrom poco.drivers.unity3d import UnityPoco

poco = UnityPoco()

poco(text='wait UI 2').click()

blue_fish = poco('fish_area').child('blue')

yellow_fish = poco('fish_area').child('yellow')

shark = poco('fish_area').child('black')

poco.wait_for_all([blue_fish, yellow_fish, shark])

poco('btn_back').click()

time.sleep(2.5)

如果你想要利用Airtest的API,自己拓展更多的高级功能的话,可以先下载airtest的python第三方依赖库:

$brew install python3.6.4
#下载python3   
$pip install Airtest
#下载Airtest python第三方依赖库
$pip install poco
#下载Airtest提供的Android app ui测试库pocoui
$brew cask install android-sdk 
#安装Android-sdk,详细的配置教程网上有,这里不详细说了。
from airtest.core.api import *
# 通过ADB连接本地Android设备
connect_device("Android:///")
#安装待测软件apk,路径信息。
install("path/to/your/apk")
#开始运行app
start_app("com.pingan.certicationApp")
#点击某个图片,Airtest中基于图像识别语法,图片自己提供。
touch(Template("image_of_a_button.png"))
#滑动语音,开头图片跟结尾图片
swipe(Template("slide_start.png"), Template("slide_end.png"))
#添加断言的图片
assert_exists(Template("success.png"))
#点击Android上的返回键
#keyevent("BACK")
#点击Android上的Home键返回
#home()
#uninstall("package_name_of_your_apk")

 

 

posted on 2019-03-13 14:35  wjmrr  阅读(515)  评论(0编辑  收藏  举报