Airtest ——poco

1.  Pymysql(No module named cryptography)

pip install cryptographypython

pip install paramikomysql

cryptography pymysql 放入 airtest路徑android

註釋:mac 環境,Airtest 默認安裝位置,/應用程序/AirtestIDE/Contents/MacOS/spring

                         python3 默認安裝位置,/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packagessql

 

2.  安裝,卸載

方法一(原生adb):shell

以mac 爲例,首先找到airtest adb 的路徑,例如:/Applications/AirtestIDE.app/Contents/MacOS/airtest/core/android/static/adb/mac/。如下操做均爲adb路徑+命令(adb路徑簡寫爲adb
api

1. 查看所鏈接的設備app

os.system('adb version')測試

 

2. 查看全部包名ui

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

 

3. 安裝

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

 

4. 卸載

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

 

5. 啓動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

 

方法二:

from airtest.core.android.android import Android
command = Android()

print("當前設備:%s"% command.get_default_device())
print("uuid:%s"% command.uuid)
print("手機裏全部的app:%s"% command.list_app())
print("啓動app:%s"% command.start_app('com.tencent.mtt'))
print("中止app:%s"% command.stop_app('com.tencent.mtt'))
print("清除app數據:%s"% command.clear_app('com.tencent.mtt'))
print("安裝app:%s"% command.install_app('/Users/zd/Downloads/zenglish-3.13.0-fenbi-test.apk'))
print("卸載app:%s"% command.uninstall_app('com.tencent.mtt'))
print("喚醒:%s"% command.wake())
print("home:%s"% command.home())
print("手機是否滅屏返回值:%s"% command.is_screenon())
print("手機裏的app是否存在:%s"% command.check_app('com.tencent.mtt'))

 

方法三:

from airtest.core.api import *

stop_app('com.fenbi.android.zenglish')
start_app('com.fenbi.android.zenglish')
clear_app('com.fenbi.android.zenglish')
install('/Users/zd/Downloads/zenglish-3.13.0-fenbi-test.apk')
uninstall('com.fenbi.android.zenglish')
wake()
home()

 

 

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

 

 

6. 放大,縮小

from airtest.core.api import *

poco('android:id/content').pinch('in',percent=0.2)

poco('android:id/content').pinch('out',percent=0.2)

 

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)

9. 生成測試報告

Ctr+L

10. 關於文件導入

from airtest.core.api import *

import os

print(os.path.abspath(os.path.dirname(os.getcwd())))ST.PROJECT_ROOT =os.path.abspath(os.path.dirname(os.getcwd()))using("untitled.air")from ttest import *

相關文章
相關標籤/搜索