问答 airtest 在 oppo 真机上遇到麻烦,求助

佳佳 · 2018年12月12日 · 最后由 佳佳 回复于 2019年04月16日 · 3430 次阅读

问题:

刚开始学习 airtest,遇到点小问题
问题是,第二步点击安装之后,第三步就找不到控件 id 了
看了下日志,发现 PocoService 被杀了,然后在手机上给进程加了一个锁,跑的时候还是被杀掉了,不知道是不是这个原因?
哪位小伙伴遇到过类似问题?

环境:

oppoA57 android6.0.1

代码:

import threading
from airtest.core.api import *
from airtest.core.android.android import *
from poco.drivers.android.uiautomation import AndroidUiautomationPoco

android = Android()
poco = AndroidUiautomationPoco(force_restart=False)
APP_NAME = 'com.xxxx.yyyy'
INSTALL_PATH = "F:\\ggg\\xxxx_443.apk"  # 路径带中文不能识别

class PermissionThread(threading.Thread):   # 处理OPPO权限
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        install_permission()

def install_permission():
    while True:     # 第一步 输入oppo账号的密码
        try:
            poco("com.coloros.safecenter:id/et_login_passwd_edit").click()
            text("123456")
            poco("android:id/button1").click()
            break
        except:
            pass
        finally:
            sleep(5)
    while True:     #  第二步 在权限页面确认页面点击安装按钮,找不到id,所以用图片识别
        try:
            touch(Template(r"tpl1544600876786.png", record_pos=(0.215, 0.811), resolution=(720, 1280)))
            break
        except:
            pass
        finally:
            sleep(5)
    while True:     #  第三步 安装完成后,点击完成按钮
        try:
            poco("com.android.packageinstaller:id/bottom_button_one").click()
            break
        except:
            pass
        finally:
            sleep(5)

def install_bao():
    android.uninstall_app(APP_NAME)
    thread = PermissionThread()
    thread.start()
    android.install_app(INSTALL_PATH)

if __name__ == '__main__':
    connect_device("Android:///")
    wake()  # 唤醒
    home()  # 回到首页
    install_bao()   # 安装apk

日志:

[08:12:41][DEBUG]<airtest.utils.nbsp> [minicap_server]b'PID: 14560'
[08:12:41][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: Using projection 720x1280@720x1280/0'
[08:12:41][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (external/MY_minicap/src/minicap_23.cpp:240) Creating SurfaceComposerClient'
[08:12:41][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (external/MY_minicap/src/minicap_23.cpp:243) Performing SurfaceComposerClient init check'
[08:12:41][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (external/MY_minicap/src/minicap_23.cpp:250) Creating virtual display'
[08:12:41][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (external/MY_minicap/src/minicap_23.cpp:256) Creating buffer queue'
[08:12:41][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (external/MY_minicap/src/minicap_23.cpp:261) Creating CPU consumer'
[08:12:41][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (external/MY_minicap/src/minicap_23.cpp:265) Creating frame waiter'
[08:12:41][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (external/MY_minicap/src/minicap_23.cpp:269) Publishing virtual display'
[08:12:41][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (jni/minicap/JpgEncoder.cpp:64) Allocating 2766852 bytes for JPG encoder'
[08:12:41][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (/home/lxn3032/minicap_for_ide/jni/minicap/minicap.cpp:473) Server start'
[08:12:41][DEBUG]<airtest.utils.nbsp> [minicap_server]b'INFO: (/home/lxn3032/minicap_for_ide/jni/minicap/minicap.cpp:475) New client connection'
[08:12:41][DEBUG]<airtest.core.android.minicap> (1, 24, 14560, 720, 1280, 720, 1280, 0, 2)
[08:12:41][DEBUG]<airtest.core.android.adb> f:\huigui_app\airtest\airtest\core\android\static\adb\windows\adb.exe -s 4d986a30 shell LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -i ; echo ---$?---
[08:12:41][DEBUG]<airtest.core.api> try match with _find_template
[08:12:41][DEBUG]<airtest.aircv.template> threshold=0.7, result={'result': (515, 1224), 'rectangle': ((361, 1192), (361, 1256), (669, 1256), (669, 1192)), 'confidence': 0.9994706511497498}
[08:12:41][DEBUG]<airtest.core.api> match result: {'result': (515, 1224), 'rectangle': ((361, 1192), (361, 1256), (669, 1256), (669, 1192)), 'confidence': 0.9994706511497498}
[08:12:41][DEBUG]<airtest.core.android.adb> f:\huigui_app\airtest\airtest\core\android\static\adb\windows\adb.exe -s 4d986a30 shell getprop ro.product.cpu.abi
[08:12:41][DEBUG]<airtest.core.android.adb> f:\huigui_app\airtest\airtest\core\android\static\adb\windows\adb.exe -s 4d986a30 shell getprop ro.build.version.sdk
[08:12:41][DEBUG]<airtest.core.android.adb> f:\huigui_app\airtest\airtest\core\android\static\adb\windows\adb.exe -s 4d986a30 shell ls /data/local/tmp/minitouch ; echo ---$?---
[08:12:42][DEBUG]<airtest.core.android.adb> f:\huigui_app\airtest\airtest\core\android\static\adb\windows\adb.exe -s 4d986a30 shell ls -l /data/local/tmp/minitouch ; echo ---$?---
[08:12:42][DEBUG]<airtest.core.android.minitouch> install_minitouch skipped
[08:12:42][DEBUG]<airtest.core.android.adb> f:\huigui_app\airtest\airtest\core\android\static\adb\windows\adb.exe -s 4d986a30 shell LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -i ; echo ---$?---
[08:12:42][DEBUG]<airtest.core.android.adb> f:\huigui_app\airtest\airtest\core\android\static\adb\windows\adb.exe -s 4d986a30 forward --no-rebind tcp:13147 localabstract:minitouch_13147
[08:12:42][DEBUG]<airtest.core.android.adb> f:\huigui_app\airtest\airtest\core\android\static\adb\windows\adb.exe -s 4d986a30 shell /data/local/tmp/minitouch -n 'minitouch_13147' 2>&1
[08:12:42][DEBUG]<airtest.utils.nbsp> [minitouch_server]b'Note: device /dev/input/mice is not supported by libevdev'
[08:12:42][DEBUG]<airtest.utils.nbsp> [minitouch_server]b'Type B touch device touchpanel (720x1280 with 10 contacts) detected on /dev/input/event1 (score 21969)'
[08:12:42][DEBUG]<airtest.utils.nbsp> [minitouch_server]b'Connection established'
[08:12:42][DEBUG]<airtest.core.android.minitouch> minitouch header:b'v 1\n^ 10 720 1280 0\n$ 14586\n'
[08:12:42][DEBUG]<airtest.core.android.adb> f:\huigui_app\airtest\airtest\core\android\static\adb\windows\adb.exe -s 4d986a30 forward --remove tcp:14771
[08:12:42][DEBUG]<airtest.core.android.adb> f:\huigui_app\airtest\airtest\core\android\static\adb\windows\adb.exe -s 4d986a30 forward --remove tcp:16847
[08:12:42][DEBUG]<airtest.core.android.adb> f:\huigui_app\airtest\airtest\core\android\static\adb\windows\adb.exe -s 4d986a30 forward --remove tcp:13870
[08:12:42][DEBUG]<airtest.core.android.adb> f:\huigui_app\airtest\airtest\core\android\static\adb\windows\adb.exe -s 4d986a30 forward --remove tcp:13147
[08:12:42][DEBUG]<airtest.core.android.rotation> orientationWatcher has ended

共收到 2 条回复 时间 点赞


我这边一台 OPPO A83,安装过程中的这个安装也是识别不出来。

2楼 已删除

后来我放弃了 airtest,用了 uiautomator2,如果用 uiautomator2,可以参考下下面的·😀

def oppo_verify(u):
    """ 处理oppo权限问题 """
    if u(packageName="com.coloros.safecenter", textContains="需要您验证身份后安装").exists:
        u.set_fastinput_ime()
        u(className='android.widget.EditText').set_text('123456')
        u(className='android.widget.Button', text='安装').click()
    if u(packageName="com.android.packageinstaller", resourceId="com.android.packageinstaller:id/bottom_button_layout").exists:
        u.click(0.714, 0.96)
        return True


def install_bao(url):
    """ 安装apk """
    u.app_uninstall(APP_NAME)
    u.app_install(url, installing_callback=oppo_verify)
    # u(resourceId="com.android.packageinstaller:id/bottom_button_two").click()
    logger.info('apk installed over!!!')

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册