zoukankan      html  css  js  c++  java
  • 基于uiautomator2 安装 app,处理adb install 未知来源 风险管控的一个方式

    有些手机可以通过adb直接安装 app,但有些手机会提示风险提示,有的还要求输入密码等(oppo、vivo)

    正常基于uiautomator2 安装一个app

    import uiautomator2 as u2
    import os
    
    d = u2.connect()
    apk_path = os.path.normpath("./xxxx.apk")
    d.app_install(apk_path)
    

    有风险提示的一个方案

    现在是通过启动另一个线程,通过 uiautomator2 ,获取UI远程,然后输入点,只能点击位置,直接代码了。

    import adbutils
    import uiautomator2 as u2
    import os
    import threading
    
    
    def get_devices():
        # 获取设备
        return adbutils.adb.device_list()
    
    
    def install_app(d):
        apk_path = os.path.normpath("./xxxx.apk")
        d.app_install(apk_path)
    
    
    def click_install(d):
        if d(text="忘记密码").exists(timeout=30):
            d.send_keys("aA111111")
            d(text="安装").click()
    
        if d(text="继续安装").exists(timeout=10):
            d(text="继续安装").click()
            d(text="安装").click()
    
        if d(text="应用权限").exists():
            info = d.device_info
            x = info["display"]["width"] / 2
            y = info["display"]["height"]
            d.click(536, 2216)
    
    
    if __name__ == "__main__":
        devices = get_devices()
        print(devices)
        if devices is None or devices.__len__ == 0:
            print("not found devices")
    
        threads = []
    
        for device in devices:
            d = u2.connect(device.serial)
    
            th1 = threading.Thread(target=install_app, args=(d,))
            th2 = threading.Thread(target=click_install, args=(d,))
    
            th1.start()
            th2.start()
    
            th1.join()
            th2.join()
    
    
    

    PS: 但发现,有些系统是没办法找到继续安装的按钮的,查看ui hierarchy,是没有那个按钮的信息,回头再尝试一下其它方法

    本文原创手打,转载请注明出处。
  • 相关阅读:
    Linux下让一个程序开机自动启动
    Heartbeat高可用解决方案
    NFS文件共享
    清除系统日志的三个脚本
    nfs+rsync+inotify实现文件的实时同步
    安装配置rsync服务端
    shell中如何进行算术运算
    linux下查看账号密码的过期时间和设置时间
    配置Nginx作为web server详解
    [LeetCode] 398. Random Pick Index ☆☆☆
  • 原文地址:https://www.cnblogs.com/gaoshang212/p/15323667.html
Copyright © 2011-2022 走看看