AirtestProject / Airtest

UI Automation Framework for Games and Apps
http://airtest.netease.com/
Apache License 2.0
8.29k stars 1.3k forks source link

Android Device类即使传了adb_path的值,也仍会从进程中查找adb的进程一次 #1168

Closed Ryaningli closed 9 months ago

Ryaningli commented 1 year ago

代码bug

描述问题bug 在init_device时,有传参本地的adb路径到adb_path,目的是为了使用本地adb从而加快初始化速度,但是查阅代码发现,即使给init_device -> Device传参了adb_path,ADB类仍然会初始化两次且第一次初始化的时候adb_path为空。看到Android Device类的代码如下:

def __init__(self, serialno=None, host=None,
             cap_method=CAP_METHOD.MINICAP,
             touch_method=TOUCH_METHOD.MINITOUCH,
             ime_method=IME_METHOD.YOSEMITEIME,
             ori_method=ORI_METHOD.MINICAP,
             display_id=None,
             input_event=None,
             adb_path=None,      # 此处传参了
             name=None):
    super(Android, self).__init__()
    self.serialno = serialno or self.get_default_device()      # 这里没有使用adb_path,从而使得ADB类初始化较为耗时
    self._uuid = name or self.serialno
    self._cap_method = cap_method.upper()
    self._touch_method = touch_method.upper()
    self.ime_method = ime_method.upper()
    self.ori_method = ori_method.upper()
    self.display_id = display_id
    self.input_event = input_event
    # init adb
    self.adb = ADB(self.serialno, adb_path=adb_path, server_addr=host, display_id=self.display_id, input_event=self.input_event)

......

def get_default_device(self, adb_path=None):
    """
    Get local default device when no serialno

    Returns:
        local device serialno

    """
    if not ADB(adb_path=adb_path).devices(state="device"):
        raise IndexError("ADB devices not found")
    return ADB(adb_path=adb_path).devices(state="device")[0][0]

实例化的时候会先调用一次get_default_device,其中adb_path没有用init的参数,不知这么做是为了什么考究?能否更改为使用传参值?目前我的解决方案是复写了Device类改为了使用传参值

yimelia commented 11 months ago

非常感谢你的指出,这个是BUG,不是有特殊考虑,单纯是漏改了…… 将在下个版本修复

yimelia commented 11 months ago

https://github.com/AirtestProject/Airtest/pull/1186/commits/43f46de29b0dc9fde188327b0df5d2c90bf9b6d3