美文网首页
QPython中运行uiautomator2自动化脚本

QPython中运行uiautomator2自动化脚本

作者: Cosy_89 | 来源:发表于2022-01-05 18:45 被阅读0次

    - QPython安装

    下载地址:https://www.qpython.com/

    - 安装atx-agent

    python -m uiautomator2 init

    打开ATX,启动uiautomator2服务

    - 安装Qpython 3L

    默认安装目录:/storage/emulated/0/qpython

    将需要运行的python脚本导入到/storage/emulated/0/qpython/scripts

    - 安装uiautomator2

    (1) 打开Qpython,右上角进入pip终端窗口,输入以下命令

    pip3 install -U --pre uiautomator2

    基本会安装失败,报错如下:

    Command "python setup.py egg_info" failed with error code/in/storage/emulated/0/qpython/cache/pip-build-pizq_8xy/lxml/

    (2)导入site-packages中所有依赖库

    adb push site-packages\ /storage/emulated/0/qpython/lib/python3.6/

    注:其中的pil文件夹需要使用合成的PIL文件夹才可以,

    (3)导入脚本

    adb push xxx.py /storage/emulated/0/qpython/scripts3

    ---

    - site-packages

    将C:\Users\Administrator\AppData\Roaming\Python\Python38\site-packages导入下述路径下

    /storage/emulated/0/qpython/lib/python3.6/

    ---

    - python脚本示例

    `` import uiautomator2 as u2

    `` import time

    ``

    ``

    `` def facepay():

    ``    d = u2.connect("http://0.0.0.0:7912")

    ``    print(d.info)

    ``    # 启动应用

    ``    d.app_start("com.icbc.facepay.zpb")

    ``    count = 0

    ``    while count < 1000:

    ``

    ``        print("facepay executed")

    ``        facepay_el = d(text="刷脸支付")

    ``        time.sleep(0.5)

    ``        if facepay_el.exists:

    ``            facepay_el.click()

    ``        time.sleep(0.5)

    ``        cancel_el = d(resourceId="com.ft.youtu.faceapp:id/iv_close")

    ``        time.sleep(0.5)

    ``        if cancel_el.exists:

    ``            cancel_el.click()

    ``        else:

    ``            print("找不到刷脸支付")

    ``        count = count + 1

    ``

    ``

    `` if __name__ == '__main__':

    ``    facepay()

    注:连接地址使用http://0.0.0.0:7912

    ---

    执行脚本出现的问题

    (1) ImportError:cannot import name '_imaging' from 'PIL'_

    找不到PIL模块

    pip3 install pillow

    安装失败,执行下面

    1、在终端目录下新建个PIL文件夹,将原来pil删除

    /storage/emulated/0/qpython/lib/python3.6/site-packages

    2、进入电脑目录

    C:\Users\Administrator\.PyCharm2019.2\system\python_stubs\

    找到其子文件夹PIL内imaging.py,对应下面版本必需是8.4.0

    PILLOW_VERSION = '8.4.0'_

    将PIL下的所有文件导入终端目录下

    /storage/emulated/0/qpython/lib/python3.6/site-packages/PIL

    3、进入电脑目录

    C:\Users\Administrator\AppData\Roaming\Python\Python38\site-packages/pil

    将pil文件夹下的所有文件导入终端目录下

    /storage/emulated/0/qpython/lib/python3.6/site-packages/PIL

    将原有pil文件夹删除

    4、执行脚本文件

    相关文章

      网友评论

          本文标题:QPython中运行uiautomator2自动化脚本

          本文链接:https://www.haomeiwen.com/subject/iydhcrtx.html